#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  T fl = 1;
  char ch = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') fl = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + (ch ^ 48);
  x *= fl;
}
double ans = 0;
long long n, a[100005], d[100005], c[100005];
int main() {
  read(n);
  if (n == 1) return printf("0\n"), 0;
  for (int i = (1); i <= (n); i++) read(a[i]);
  for (int i = n; i; i--) {
    for (int j = a[i]; j; j -= (j & -j))
      ans += c[j], ans -= 2.0 * i * d[j] / n / (n + 1);
    for (int j = a[i]; j <= n; j += (j & -j)) c[j]++, d[j] += n - i + 1;
    ans += (n - i + 1.0) * i * (i - 1) / n / (n + 1) / 2;
  }
  printf("%.12f\n", ans);
  return 0;
}
