#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
long long num1[N], num2[N], x, n;
double f[N];
void insert(long long x, long long y) {
  for (long long i = x; i < N; i += i & -i) num1[i]++, num2[i] += y;
}
long long find1(long long x) {
  long long ans = 0;
  for (; x; x -= x & -x) ans += num1[x];
  return ans;
}
long long find2(long long x) {
  long long ans = 0;
  for (; x; x -= x & -x) ans += num2[x];
  return ans;
}
signed main() {
  scanf("%lld", &n);
  long long ans1 = 0, ans2 = 0;
  double s = 0;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &x);
    x = n - x + 1;
    ans1 += find1(x);
    ans2 += find2(x) * (n - i + 1);
    insert(x, i);
  }
  for (long long i = 1; i <= n; i++) f[i] = i * (i - 1) / 2 + f[i - 1];
  for (long long i = 1; i <= n; i++) s += f[i];
  printf("%.10lf\n",
         ans1 - (double)ans2 / (n * (n + 1) / 2) + (double)s / (n * (n + 1)));
}
