#include <bits/stdc++.h>
using namespace std;
int n, a[200007];
struct Tree {
  long long sum[200007];
  void add(int x, long long d) {
    for (; x <= n; x += x & -x) sum[x] += d;
  }
  long long query(int x) {
    long long ans = 0;
    for (; x; x -= x & -x) ans += sum[x];
    return ans;
  }
} T1, T2;
int main() {
  double ans;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  ans = 0;
  for (int j = 1; j <= n; j++) ans += 1.0 * j * (j - 1) * (n - j + 1) / 4;
  long long cnt = 0;
  for (int i = n; i >= 1; i--) {
    int x = a[i];
    cnt += T1.query(x);
    ans -= 1.0 * i * T2.query(x);
    T1.add(x, 1), T2.add(x, n - i + 1);
  }
  ans /= 1.0 * n * (n + 1) / 2;
  ans += cnt;
  printf("%.10lf\n", ans);
  return 0;
}
