#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], n;
long long Bit[N];
long double F[N], ans;
void update(int u, int p) {
  for (; u < N; u += u & -u) Bit[u] += 1LL * p;
}
long long get(int u) {
  long long res = 0;
  for (; u > 0; u -= u & -u) res += Bit[u];
  return res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) F[i] = F[i - 1] + (i - 1.) / 2.;
  for (int i = n; i >= 1; --i) {
    ans += 1. * get(a[i]);
    update(a[i], 1);
  }
  memset(Bit, 0, sizeof Bit);
  for (int i = n; i >= 1; --i) {
    long double res = get(a[i]);
    res = 2. * res * i / n / (n + 1);
    ans -= res;
    update(a[i], n - i + 1);
  }
  for (int i = 1; i <= n; ++i)
    ans = ans + 2. * (F[i] * (n - i + 1)) / n / (n + 1);
  cout << fixed << setprecision(9) << ans;
}
