#include <bits/stdc++.h>
using namespace std;
long long AIB[202020][4], N;
inline int zeros(int x) { return x & (-x); }
inline void add(long long x, long long q, int a) {
  for (int i = x; i <= N; i += zeros(i)) AIB[i][a] += q;
}
inline long long comp(int x, int a) {
  long long ret = 0;
  for (int i = x; i > 0; i -= zeros(i)) ret += AIB[i][a];
  return ret;
}
int v[202020];
long long tot;
long long alt;
long long all;
int main() {
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> v[i];
  }
  for (long long i = 1; i <= N; ++i) {
    tot += comp(N, 1) - comp(v[i], 1);
    add(v[i], 1, 1);
    alt += (comp(N, 2) - comp(v[i], 2)) * (N - i + 1);
    add(v[i], i, 2);
    all += i * (i - 1) * (N - i + 1);
  }
  double ret = 1.0 * tot -
               (1.0 * alt - 1.0 * all / 4.0) / (1.0 * N * (1.0 * N + 1) / 2.0);
  printf("%.12lf\n", ret);
}
