A binary tree is given as a single space-separated level-order array. Values appear top-to-bottom, left-to-right, and the literal token null marks a missing child (a null never has children of its own). An empty tree is encoded as the single token null.
Compute the sum of the values of all real nodes in the tree. The sum of an empty tree is 0.
Values may be negative, so the answer can be negative; with up to 100000 nodes the total can exceed 32 bits, so accumulate in a 64-bit-safe integer.
Input format
A single line of level-order tokens separated by single spaces. Each token is an integer or the literal null. The line may be exactly null for an empty tree.
Output format
A single integer: the sum of all node values.
Constraints
- The number of real (non-null) nodes is between 0 and 100000.
- Each node value is in the range -1000000 to 1000000.
- The input is always a valid level-order serialization.