In the easy version, guards can use the operations only once.
In the next round of the Squid Game, players must be arranged by their numbers from $$$1$$$ to $$$n$$$. Guards must rearrange the players that initially are shuffled in a random order. Time is crucial, so they have to minimize the time needed to do that.
A guard can do the following operations :
The goal of the guards is to rearrange the players into the correct order $$$1,2,...,n$$$, using these operations only once, while minimizing the total time. The guards can perform these operations infinitely, but they must be strategic in choosing the number of segments each time because the more segments they use, the longer it takes.
The first line contains an integer $$$n$$$ $$$(2 \leq n \leq 10^5)$$$ — the number of players.
The second line contains $$$n$$$ integers $$$a_1,a_2,...,a_n$$$ $$$(1 \le a_i \le n)$$$ — the initial permutation of players.
Print a single integer, the minimum time needed to rearrange the players.
55 4 2 3 1
4
53 4 5 1 2
2
66 5 4 3 2 1
6
51 2 3 4 5
0
In the first test, you can divide the players into $$$4$$$ segments $$$[5]$$$,$$$[4]$$$,$$$[2,3]$$$ and $$$[1]$$$ and shuffle them into $$$[1,2,3,4,5]$$$. So the answer is $$$4$$$.
In the second test, you can divide the players into $$$2$$$ segments $$$[3,4,5]$$$ and $$$[1,2]$$$ and shuffle them into $$$[1,2,3,4,5]$$$. So the answer is $$$2$$$.
In the third test, you can divide the players into $$$6$$$ segments $$$[6]$$$,$$$[5]$$$,$$$[4]$$$,$$$[3]$$$,$$$[2]$$$ and $$$[1]$$$ and shuffle them into $$$[1,2,3,4,5,6]$$$. So the answer is $$$6$$$.