#STK0000085. Cây nhiễm độc (Poisonous Plants)

Cây nhiễm độc (Poisonous Plants)

Poisonous Plants

Source: HackerRank

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN plants from left to right, where plant ii has pesticide level pip_i. After each day, every plant whose pesticide level is greater than that of the currently alive plant immediately to its left dies simultaneously. The process repeats on the surviving sequence. Determine the number of days until no plant dies.

Input

The first line contains NN. The second line contains NN integers p1,p2,…,pNp_1,p_2,\ldots,p_N.

Output

Print the number of days until no more plants die.

Subtasks

  • Subtask 1 (30 points): N≤2000N\le2000; all other conditions are unchanged.
  • Subtask 2 (70 points): 1≤N≤1051\le N\le10^5, 0≤pi≤1090\le p_i\le10^9.

Examples

Input

7
6 5 8 4 7 10 9

Output

2

Explanation

Initially the pesticide levels are [6,5,8,4,7,10,9][6,5,8,4,7,10,9].

On day 11, each plant is compared with the alive plant immediately to its left using the state at the start of the day:

  • 8>58>5, so the plant with level 88 dies;
  • 7>47>4, so the plant with level 77 dies;
  • 10>710>7, so the plant with level 1010 dies.

After day 11, the surviving sequence is [6,5,4,9][6,5,4,9].

On day 22, the plant with level 99 is immediately to the right of level 44, and 9>49>4, so it dies. The survivors are [6,5,4][6,5,4].

Now 6≥5≥46\ge5\ge4, so no surviving plant has more pesticide than its left neighbor. The process stops after 22 days, hence the output is 2.