Skip to content
UPEEC

Height of a BST

Medium#trees#binary-search-tree· solved by 0 · time limit 2.0 s

Insert distinct values one by one into an empty binary search tree (smaller values go left, larger go right). Print the tree's height — the number of nodes on the longest root-to-leaf path.

Input

nn, then the nn distinct values in insertion order.

Output

The height.

Constraints

1≤n≤20001 \le n \le 2000

Sample 1

Input

5
50 30 70 20 40

Output

3

Sample 2

Input

3
1 2 3

Output

3

Sign in or join free to run and submit your solution.