#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const int N = 1e5 + 10;
int p[N];
long long c[N], d[N];
long long A[N], B[N];
int n;
void add(long long c[], int x, int y) {
  for (; x <= n; x += x & -x) {
    c[x] += y;
  }
}
long long query(long long c[], int x) {
  long long ret = 0;
  for (; x; x -= x & -x) {
    ret += c[x];
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &p[i]);
  }
  long long sum = 0;
  double all = (double)n * (n + 1);
  double ret = 0.0;
  for (int i = 0; i < n; ++i) {
    long long A0 = query(c, p[i]);
    long long A1 = query(d, p[i]);
    add(c, p[i], 1);
    add(d, p[i], i);
    ret += (n - i) / all * (A0 + A1);
    A0 = i - A0;
    A1 = sum - A1;
    ret += A0 - (n - i) / all * (A0 + A1);
    sum += i;
  }
  printf("%.10f\n", ret);
  return 0;
}
