网址:​​点击打开链接​

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:

codeforces 144A Arrival of the General_ide

题意:(假如有很多个最大值和最小值)把第一个最大值移到第一个位置,把最后一个最小值移到最后一个位置的步骤和,只能两两交换。

#include<stdio.h>
int main()
{
int n,s[110],least=0,largest=0;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%d",&s[i]);
}
for(int i=1; i<n; i++)
{
if(s[least]>=s[i])
least=i;
if(s[largest]<s[i])
largest=i;
}
if(least<largest)
{
printf("%d\n",largest+n-1-least-1);
}
else if(least==largest)
{
printf("0\n");
}
else//least>largest
{
printf("%d\n",largest+n-1-least);
}
//printf("%d %d %d %d\n",s[least],s[largest],least,largest);
return 0;
}