#include <bits/stdc++.h>
using namespace std;
int n;
int a[300005], s[300005];
void add(int x, int k) {
  while (x <= n) s[x] += k, x += ((x) & (-(x)));
}
int query(int x) {
  int res = 0;
  while (x) res += s[x], x -= ((x) & (-(x)));
  return res;
}
int main() {
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    ans += i - 1 - query(a[i]);
    add(a[i], 1);
  }
  if (ans & 1)
    ans = ans * 2 - 1;
  else
    ans *= 2;
  cout << ans << endl;
  return 0;
}
