#include <bits/stdc++.h>
using namespace std;
const int N = 3007;
long double dp[N * N];
int n, m, a[N];
bool mark[N * N];
long double calc(int i) {
  if (i == 0) return 0.0;
  if (i == 1) return 1.0;
  if (mark[i]) return dp[i];
  mark[i] = true;
  dp[i] = 1e18;
  if (i + 2 <= m) dp[i] = min(dp[i], calc(i + 2));
  dp[i] = min(dp[i], calc(i - 2));
  return dp[i] + 4.0;
}
int main() {
  scanf("%d", &n);
  if (n == 1) {
    puts("0.00000000000");
    return 0;
  }
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  if (n == 2) {
    if (a[0] < a[1])
      puts("0.0000000000");
    else
      puts("1.0000000000");
    return 0;
  }
  int inv = 0;
  m = n * (n - 1) / 2;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j)
      if (a[i] > a[j]) ++inv;
  cout << fixed << setprecision(9) << calc(inv) << endl;
  return 0;
}
