#include <bits/stdc++.h>
using namespace std;
char __buf[1 << 18], *__c = __buf, *__ed = __buf;
inline int qr() {
  int ret = 0, f = 0, c = getchar();
  while (!isdigit(c)) f |= c == 45, c = getchar();
  while (isdigit(c)) ret = ret * 10 + c - 48, c = getchar();
  return f ? -ret : ret;
}
const int maxn = 1e5 + 5;
long long seg[maxn], cnt[maxn];
int n, data[maxn];
void add(int pos, long long tag, long long* seg) {
  for (int t = pos; t <= n; t += t & -t) seg[t] += tag;
}
long long que(int pos, long long* seg) {
  long long ret = 0;
  for (int t = pos; t > 0; t -= t & -t) ret += seg[t];
  return ret;
}
int main() {
  n = qr();
  for (int t = 1; t <= n; ++t) data[t] = n - qr() + 1;
  long double ans = 0, sum = 0;
  for (int t = 1; t <= n; ++t) {
    sum += que(data[t], cnt);
    ans -= que(data[t], seg) * (n - t + 1);
    ans += (long double)(n - t + 1) * t * (t - 1) / (long double)4.0;
    add(data[t], 1, cnt);
    add(data[t], t, seg);
  }
  cout.precision(20);
  cout << ans / (1ll * n * (n + 1) / 2) + sum << endl;
  return 0;
}
