#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 15;
long long sum[N], a[N];
double dp[N];
int u[N];
void update(int x, int add) {
  while (x < N) sum[x] += add, x += x & (-x);
}
long long q(int x) {
  long long ret = 0;
  while (x) ret += sum[x], x = x & (x - 1);
  return ret;
}
int main() {
  int n, i, k, x, y;
  long long A = 0, B = 0;
  cin >> n;
  for (i = 1; i <= n; ++i) scanf("%d", &u[i]), update(i, 1);
  for (i = 1; i <= n; ++i) update(u[i], -1), A += q(u[i]);
  for (i = n; i >= 1; --i) update(u[i], n - i + 1);
  for (i = 1; i <= n; ++i) update(u[i], -n + i - 1), B += q(u[i]) * i;
  dp[1] = 0;
  for (i = 2; i <= n; ++i) dp[i] = dp[i - 1] + (double)(i - 1) / 2;
  double ret = A, tot = n;
  tot *= n + 1;
  tot /= 2;
  for (i = 1; i <= n; ++i) ret += (dp[i] * (n - i + 1)) / tot;
  ret -= B / tot;
  printf("%0.9lf\n", ret);
}
