#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, min = 101, u, max = 0, m = 0, n = 0, z = 0;
  cin >> x;
  vector<int> vec(x);
  for (int i = 0; i < x; i++) {
    cin >> vec[i];
    if (vec[i] <= min) {
      min = vec[i];
      n = i;
    }
    if (vec[i] > max) {
      max = vec[i];
      m = i;
    }
  }
  if (m > n)
    x = x - 2;
  else
    x = x - 1;
  n = x - n;
  z = m + n;
  cout << z << endl;
  return 0;
}
