#include <bits/stdc++.h>
using namespace std;
const int N = 100004;
long long bit[N];
int a[N];
void update(int x, int val) {
  while (x < N) {
    bit[x] += val;
    x += x & -x;
  }
  return;
}
long long query(int x) {
  long long ans = 0;
  while (x > 0) {
    ans = ans + bit[x];
    x -= x & -x;
  }
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  int i;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  double totl = (double)(1LL * n * (n + 1)) / 2.0;
  double ans = 0.0;
  double lensum = 0.0;
  double ssum = 0.0;
  for (i = n; i >= 1; i--) {
    ssum = ssum + (double)query(a[i]);
    lensum = lensum + (1LL * (n - i) * (n - i + 1)) / 4.0;
    ans = ans + (lensum - ssum) / totl;
    update(a[i], n - i + 1);
  }
  memset(bit, 0, sizeof(bit));
  long long cnt = 0;
  for (i = n; i > 0; i--) {
    cnt = cnt + query(a[i]);
    update(a[i], 1);
  }
  ans = ans + cnt;
  printf("%0.20lf\n", ans);
  return 0;
}
