A gantry frame hangs from a binary tree. Imagine the tree drawn as a complete binary grid: the root occupies slot 0, and a node in slot p has its left child in slot 2p and its right child in slot 2p + 1 (whether or not those children exist). The width of a level is the number of slots from its left-most present node to its right-most present node, inclusive, counting the empty slots in between. Report the maximum width over all levels.
Input format
Line 1: an integer n, the number of tokens on the next line.
Line 2: n space-separated tokens describing a binary tree in level-order (breadth-first). The first token is the root's value. Reading left to right, keep a queue of already-created nodes; for each node taken from the front of the queue, the next two tokens are its left child then its right child, where the token null marks a missing child. Only non-null children are added to the queue. Trailing null tokens for absent children at the deepest level may be omitted. Every node value is an integer.
Output format
A single integer: the maximum level width.
Constraints
- 1 <= n <= 129
- The tree has at least 1 and at most 40 nodes.
- Each node value is an integer with -1000 <= value <= 1000.