A rock formation is a binary tree; each node has an integer stratum value. A uniform path is a path in the tree (a sequence of nodes connected by parent-child edges, which may bend at one node) along which every node has the same stratum value. The length of a path is its number of edges, so a single node is a uniform path of length 0.
Report the length, in edges, of the longest uniform path.
Input format
Line 1: an integer k, the number of tokens on line 2.
Line 2: k space-separated tokens giving the tree in level order. The first token is the root; each subsequent token is an integer stratum value or null for a missing child. Children of null nodes are omitted.
Output format
A single integer: the length in edges of the longest uniform path.
Constraints
- The tree has between 1 and 2000 nodes (the root is always present).
- Each stratum value is between -1000000 and 1000000.