#include <bits/stdc++.h>
using namespace std;
int it[4 * 3002], l[4 * 3002], h[4 * 3002];
int a[3002], r[3002];
void Build(int x, int low, int high) {
  l[x] = low;
  h[x] = high;
  it[x] = 0;
  if (low == high) return;
  int mid = (low + high) / 2;
  Build(2 * x, low, mid);
  Build(2 * x + 1, mid + 1, high);
}
void add(int x, int pos) {
  if (pos > h[x] || pos < l[x]) return;
  it[x]++;
  add(2 * x, pos);
  add(2 * x + 1, pos);
}
int query(int x, int low, int high) {
  if (low > h[x] || high < l[x]) return 0;
  if (low <= l[x] && h[x] <= high) return it[x];
  return query(2 * x, low, high) + query(2 * x + 1, low, high);
}
int main() {
  int permute = 0;
  int n;
  cin >> n;
  Build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    r[a[i]] = i;
  }
  for (int i = n; i >= 1; i--) {
    add(1, r[i]);
    permute += query(1, 1, r[i] - 1);
  }
  cout << (permute / 2) * 4 + (permute % 2 == 0 ? 0 : 1);
}
