#include <bits/stdc++.h>
using namespace std;
int AIB[200005];
long long AIB2[200005];
int n, perm[200005];
double answer;
void update(int poz, int val) {
  for (; poz <= n; poz += ((poz ^ (poz - 1)) & poz)) AIB[poz] += val;
}
void update2(int poz, int val) {
  for (; poz <= n; poz += ((poz ^ (poz - 1)) & poz)) AIB2[poz] += val;
}
int query(int poz) {
  int s = 0;
  for (; poz; poz -= ((poz ^ (poz - 1)) & poz)) s += AIB[poz];
  return s;
}
long long query2(int poz) {
  long long s = 0;
  for (; poz; poz -= ((poz ^ (poz - 1)) & poz)) s += AIB2[poz];
  return s;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &perm[i]);
  reverse(perm + 1, perm + n + 1);
  double answer = 0;
  for (int i = 1; i <= n; i++) {
    answer += ((double)n - i + 1) * (double)i * ((double)i - 1) /
              (2 * (double)n * ((double)n + 1));
    update(perm[i], 1);
    update2(perm[i], i);
    int cnt = query(perm[i] - 1);
    long long sum = query2(perm[i] - 1);
    answer += cnt - ((double)n - i + 1) * 2 * (double)sum /
                        ((double)n * ((double)n + 1));
  }
  printf("%.9lf\n", answer);
  return 0;
}
