Hide

Problem C
Stalínröðun

Languages en is
/problems/stalinrodun/file/statement/en/img-0001.png
Sample 2

One of the many times Unnar was scrolling and looking through new posts on the social media site ReadIt he saw a post on /l/codingjests about Stalinsort. In it a linear sorting algorithm was described, it worked by eliminating all elements that aren’t in increasing order.

Then Unnar started to think ,,What about instead of deleting all elements that aren’t in increasing order we delete the ones that are in increasing order?”. A very normal question to ask then is how many iterations it would take to end up with an empty list.

An element $a_i$ is considered to be in increasing order if for all $j < i$ we have $a_i \geq a_j$.

Input

The first line of the input contains one integer $1 \leq n \leq 5 \cdot 10^5$. The next line contains $n$ integers $1 \leq a_i \leq 10^6$.

Output

Print the number of iterations to end up with an empty list.

Example

[ 1 7 5 8 6 3 2 4 ]
After the first iteration:
[ 5 6 3 2 4 ]
After the second iteration:
[ 3 2 4 ]
After the third iteration:
[ 2 ]
After the fourth iteration:
[ ]
Thus the answer is four.

Scoring

Group

Points

Constraints

1

20

$n \leq 50$, all $a_i$ are distinct

2

30

$n \leq 2\, 500$, all $a_i$ are distinct

3

50

No further constraints

Sample Input 1 Sample Output 1
3
2 1 3
2
Sample Input 2 Sample Output 2
8
1 7 5 8 6 3 2 4
4

Please log in to submit a solution to this problem

Log in