#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
int N;
class Fenwick {
 public:
  long long sum[MAX_N];
  void update(int x, int v) {
    for (; x <= N; x += x & -x) sum[x] += v;
  }
  long long ask(int x) {
    long long res = 0;
    for (; x; x -= x & -x) res += sum[x];
    return res;
  }
} t1, t2;
int a[MAX_N];
double f[MAX_N];
int main() {
  scanf("%d", &N);
  double res1 = 0, res2 = 0;
  for (int i = 1; i <= N; ++i) scanf("%d", &a[i]);
  for (int i = N; i; --i) {
    res1 += t1.ask(a[i]);
    res2 += 1LL * t2.ask(a[i]) * i;
    t1.update(a[i], 1), t2.update(a[i], N - i + 1);
  }
  res2 /= 1LL * N * (N + 1) / 2;
  for (int i = 1; i <= N; ++i) f[i] = (double)(i - 1) / 2 + f[i - 1];
  double res3 = 0;
  for (int i = 1; i <= N; ++i) res3 += f[i] * (N - i + 1);
  res3 /= 1LL * N * (N + 1) / 2;
  printf("%.10lf\n", res1 + res3 - res2);
  return 0;
}
