695. Sum of Left Leaves

0

Easy

Given the root of a binary tree, print the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of another node.

Input Format

The tree is built from a string representation of the tree which is given as input.
First line takes string S as input. The input string is given in the following format: "root left-child right-child" of the current node.
Each node is separated by a space. 'N' represents a null node.

Output Format

Print the sum of all left leaves.

Example

Input

3 9 20 N N 15 7

Output

24

Constraints

The number of nodes in the tree is in the range [1, 1000].
-1000 <= Node.val <= 1000
Loading...

View Submissions

Console