A binary tree of paint-can color codes 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).
A branch is any path of nodes in the tree that are connected by parent-child edges, where the path may bend at most once at a single common node (a route from one node up to a shared ancestor and back down into the other side, or a straight downward path). A branch is called uniform if every node on it has the exact same value.
Print the number of edges in the longest uniform branch. (A single node, by itself, is a uniform branch with 0 edges.)
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 edges in the longest uniform branch. If the tree is empty, print 0.
Constraints
- 0 <= number of nodes <= 400
- Each node value is an integer with -1000 <= value <= 1000