#include <bits/stdc++.h>
using namespace std;
long long yy;
long double ans1 = 0, ans2;
int n;
long long tre1[100005], tre2[100005], inv1[100005], inv2[100005];
int c;
int lowb(int x) { return -x & x; }
long long ask1(int x) {
  long long nowans = 0;
  while (x) {
    nowans += tre1[x];
    x -= lowb(x);
  }
  return nowans;
}
long long ask2(int x) {
  long long nowans = 0;
  while (x) {
    nowans += tre2[x];
    x -= lowb(x);
  }
  return nowans;
}
void add1(int x) {
  while (x <= n) {
    tre1[x]++;
    x += lowb(x);
  }
}
void add2(int x, long long y) {
  while (x <= n) {
    tre2[x] += y;
    x += lowb(x);
  }
}
int main() {
  cin >> n;
  ans2 = 0.5 * (n + 1) * n;
  for (int i = 1; i <= n; i++) ans1 += 0.25 * (i - 1) * i * (n - i + 1);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c);
    ans1 += ans2 * (ask1(n) - ask1(c));
    ans1 -= 1.0 * (n - i + 1) * (ask2(n) - ask2(c));
    add1(c);
    add2(c, i);
  }
  printf("%.12f\n", double(ans1 / ans2));
  return 0;
}
