#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int N, A[maxn];
long long K = 0ll, t = 0ll, T = 0ll;
double E = 0.0;
struct Fenwick_Tree {
  long long val[maxn];
  int lowbit(int x) { return x & -x; }
  void Update(int p, long long v) {
    for (int i = p; i <= N; i += lowbit(i)) val[i] += v;
  }
  long long Sum(int p) {
    long long tot = 0ll;
    for (int i = p; i; i -= lowbit(i)) tot += val[i];
    return tot;
  }
} T1, T2;
void Init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", &A[i]), A[i] = N - A[i] + 1;
}
void Solve() {
  if (N == 1) {
    printf("0\n");
    return;
  }
  for (int i = 1; i <= N; ++i) {
    K += T1.Sum(A[i]), T1.Update(A[i], 1);
    t += T2.Sum(A[i]), T2.Update(A[i], i);
    T += t, E += 1.0 * i * (i - 1) / 4.0 * (N - i + 1);
  }
  double ans = K + (double)(E - T) * 2.0 / N / (N + 1);
  printf("%.15lf\n", ans);
}
int main() {
  Init(), Solve();
  return 0;
}
