#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-12;
const double PI = acos(-1);
const long long INFF = (long long)1e18;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const int MAX = (int)1e5 + 7;
int st[MAX], p[MAX];
int main(void) {
  int n;
  scanf("%d", &n);
  ;
  for (int i = (1); i < (n + 1); ++i) {
    scanf("%d", st + i);
    p[st[i]] = i;
  }
  long long cnt = 0;
  for (int i = (1); i < (n + 1); ++i) {
    while (p[i] != i) {
      cnt++;
      int v = st[p[i] - 1];
      swap(st[p[i] - 1], st[p[i]]);
      p[v] = p[i];
      p[i]--;
    }
  }
  printf("%lld\n", 2 * cnt - cnt % 2);
  return 0;
}
