#include <bits/stdc++.h>
using namespace std;
long long seg[100005 + 1];
long long n;
void update(long long i, long long val) {
  while (i <= n) {
    seg[i] += val;
    i += i & (-i);
  }
  return;
}
long long query(long long ind) {
  long long ans = 0;
  while (ind > 0) {
    ans += seg[ind];
    ind -= ind & (-ind);
  }
  return ans;
}
long long a[100005 + 1];
double getlen(long long n) {
  double den = 4;
  double a2 = n * (n + 1);
  a2 /= 2;
  double a1 = n * (n + 1);
  a1 /= 6;
  a1 *= (2 * n + 1);
  double num = a1 - a2;
  return num / den;
}
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) scanf("%lld", &a[i]);
  for (long long i = 0; i <= n; i++) seg[i] = 0;
  double num = 0;
  double den = n * (n + 1);
  den /= 2;
  double ff = 0;
  for (long long i = n - 1; i >= 0; i--) {
    ff += query(a[i] - 1);
    update(a[i], 1LL);
  }
  for (long long i = 0; i <= n; i++) seg[i] = 0;
  double ans = 0;
  double bc = 0;
  for (long long i = n - 1; i >= 0; i--) {
    num = 0;
    num += getlen(n - i);
    bc += query(a[i] - 1);
    num -= bc;
    num += (n - i) * ff;
    num /= den;
    ans += num;
    update(a[i], n - i);
  }
  printf("%.20lf\n", ans);
}
