LogiQuest

386. Diameter of a Binary Tree

EasyDFS

Print the number of edges on the longest path between any two nodes.

Input format

Line 1: n (number of level-order entries) Line 2: the values in level order, -1 for a missing child

Output format

The diameter.

Example 1

Input

5
1 2 3 4 5

Output

3

Example 2

Input

2
1 2

Output

1

Constraints

1 ≤ nodes ≤ 5000

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…