A binary tree of network switch ids is given in level-order form (a single line of space-separated tokens, null marking a missing child; every non-null node contributes exactly two following tokens for its children).
Count how many nodes have exactly one child (either a left child with no right child, or a right child with no left child). Nodes with zero children or two children do not count.
Input format
Line 1: space-separated level-order tokens describing the binary tree (integers and the token null).
Output format
A single integer: the number of single-child nodes. If the tree is empty, print 0.
Constraints
- 0 <= number of nodes <= 500
- Each node value is an integer with -1000 <= value <= 1000