#include<bits/stdc++.h>
using namespace std;
int main(){
int maxi=0,maxn=INT_MIN;
int mini=0,minn= INT_MAX;
int n;
int a[105];
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
if(maxn<a[i]){
maxn= a[i];
maxi = i;
}
if(minn>=a[i]){
minn=a[i];
mini=i;
}
}
if(minn==maxn){
cout<<0<<"\n";
}
else{
int c=0;
if(mini<maxi){
c = n - 1 - mini + maxi -1;
}
else c = n - 1 - mini + maxi;
cout<<c<<"\n";
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCl7CgogICAgaW50IG1heGk9MCxtYXhuPUlOVF9NSU47CiAgICBpbnQgbWluaT0wLG1pbm49IElOVF9NQVg7CgogICAgaW50IG47CiAgICBpbnQgYVsxMDVdOwogICAgY2luPj5uOwogICAgZm9yKGludCBpPTA7aTxuO2krKyl7CiAgICAgICAgY2luPj5hW2ldOwogICAgICAgIGlmKG1heG48YVtpXSl7CiAgICAgICAgICAgIG1heG49IGFbaV07CiAgICAgICAgICAgIG1heGkgPSBpOwogICAgICAgIH0KICAgICAgICBpZihtaW5uPj1hW2ldKXsKICAgICAgICAgICAgbWlubj1hW2ldOwogICAgICAgICAgICBtaW5pPWk7CiAgICAgICAgfQoKICAgIH0KCiAgICBpZihtaW5uPT1tYXhuKXsKICAgICAgICAgICAgY291dDw8MDw8IlxuIjsKICAgIH0KICAgIGVsc2V7CiAgICAgICAgaW50IGM9MDsKCiAgICAgICAgaWYobWluaTxtYXhpKXsKICAgICAgICAgICAgYyA9IG4gLSAxIC0gbWluaSArIG1heGkgLTE7CiAgICAgICAgfQogICAgICAgIGVsc2UgIGMgPSBuIC0gMSAtIG1pbmkgKyBtYXhpOwoKICAgICAgICBjb3V0PDxjPDwiXG4iOwoKICAgIH0KCn0K