Jin since training into the team, do a lot on the reverse of the subject, he also likes to reverse the, to introduce the reverse of, reverse to is in an array in a sequence of two Numbers x and y, but this two Numbers x and y can be counted as a reverse the rule is more than x y, but the position of the x must be in front of the y (namely the I & lt; J & amp; & A [I] & gt; A [j]),
Then jin to the problem, if given a sequence of length n, the number n to ensure greater than or equal to zero and less than n, and will not repeat, then jin gives you a mobile operation, you can be the first to get the sequence number of the sequence of the sequence into a new sequence, for example when n=10, given a sequence, a
So, all possible sequence is obtained by mobile as follows,
Can you please reverse output in all possible sequences of the number of the smallest?
Input
Multiple sets of input,
The first line of input integer n, meaning as described in the question, (0 & lt; N & lt;
=5000)The second line with n integers (0 & lt;=x & lt;=n - 1),
The Output
Output minimum reverse to the number of input and output of each line, guarantee the legal data,
Example Input
10
1 3 6 9 0 8 5 7 4 2
Example Output
16
#include
Int main ()
{
Int I, n, a [5005], [5005] s={0}, min.
While (~ the scanf (" % d ", & amp; N))
{
Int t, j, l;
for (i=0; i
for (i=0; i
for (j=0; J & lt; n; J++)
{
For (l=j; L & lt; n; L++)
{
If (a [j] & gt; A [l])
S [I] + +;
}
}
T=a, [0].
for (j=0; J & lt; n; J++)
{
A [j]=a, a + 1 bonus to [j].
}
1 a [j]=t;
}
Min=s [0];
For (I=1; i
If (s [I]
}
Printf (" % d \ n ", min);
}
return 0;
}