#include <bits/stdc++.h>
using namespace std;
vector<long long> BITree;
int n;
long long getSumBIT(int index) {
  long long sum = 0;
  index = index + 1;
  while (index > 0) {
    sum += BITree[index];
    index -= index & (-index);
  }
  return sum;
}
void updateBIT(int index, int val) {
  index = index + 1;
  while (index <= n) {
    BITree[index] += val;
    index += index & (-index);
  }
}
int main() {
  scanf("%d", &n);
  vector<int> a(n);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i]--;
  }
  double s1 = 0;
  double s2 = 0;
  double s3 = 0;
  double s4 = 0;
  double totInv = 0;
  BITree = vector<long long>(n + 1, 0);
  for (i = n - 1; i >= 0; i--) {
    if (a[i] != 0) {
      totInv += getSumBIT(a[i] - 1);
    }
    updateBIT(a[i], 1);
  }
  BITree = vector<long long>(n + 1, 0);
  double len;
  for (i = n - 1; i >= 0; i--) {
    len = n - i;
    s1 += (len * (len - 1)) / 4.0;
    s2 += s1;
    if (a[i] != 0) {
      s3 += getSumBIT(a[i] - 1);
    }
    s4 += s3;
    updateBIT(a[i], n - i);
  }
  double nums = (((double)n) * (n + 1)) / 2.0;
  double ans = (s2 - s4) / nums;
  ans += totInv;
  printf("%0.9f", ans);
  return 0;
}
