网址:点击打开链接
A. Arrival of the General
time limit per test
memory limit per test
input
output
n
first and the last
(4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2)wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
Input
n (2 ≤ n ≤ 100) which represents the number of soldiers in the line. The second line contains integers a1, a2, ..., an (1 ≤ ai) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers a1, a2, ..., an
Output
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
Examples
input
4 33 44 11 22
output
2
input
7 10 10 58 31 63 40 76
output
10
Note
(44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
题意:(假如有很多个最大值和最小值)把第一个最大值移到第一个位置,把最后一个最小值移到最后一个位置的步骤和,只能两两交换。