# PermutationForces solution codeforces

## PermutationForces solution codeforces

You have a permutation pp of integers from 11 to nn.

You have a strength of ss and will perform the following operation some times:

• Choose an index ii such that 1i|p|1≤i≤|p| and |ipi|s|i−pi|≤s.
• For all jj such that 1j|p|1≤j≤|p| and pi<pjpi<pj, update pjpj to pj1pj−1.
• Delete the ii-th element from pp. Formally, update pp to [p1,,pi1,pi+1,,pn][p1,…,pi−1,pi+1,…,pn].

It can be shown that no matter what ii you have chosen, pp will be a permutation of integers from 11 to |p||p| after all operations.

ALSO READ:-   Checker for Array Shuffling solution codeforces

You want to be able to transform pp into the empty permutation. Find the minimum strength ss that will allow you to do so.

Output

Print the minimum strength ss required.

Examples
input

Copy
3
3 2 1

output

Copy
1

input

Copy
1
1

output

Copy
0

input

Copy
10
1 8 4 3 7 10 6 5 9 2

output

Copy
1

Note

In the first test case, the minimum ss required is 11.

Here is how we can transform pp into the empty permutation with s=1s=1:

• In the first move, you can only choose i=2i=2 as choosing any other value of ii will result in |ipi|s|i−pi|≤s being false. With i=2i=2pp will be changed to [2,1][2,1].
• In the second move, you choose i=1i=1, then pp will be changed to .
• In the third move, you choose i=1i=1, then pp will be changed to [ ][ ].
ALSO READ:-   Array Balancing solution codeforces

It can be shown that with s=s=0, it is impossible to transform pp into the empty permutation.