#include <bits/stdc++.h>
using namespace std;
struct Bit {
  double a[100002];
  int n;
  void add(int x, double val) {
    for (; x <= n; x += x & -x) a[x] += val;
  }
  double que(int x) {
    double res = 0;
    for (; x > 0; x -= x & -x) res += a[x];
    return res;
  }
} bit, bit2;
double a[100002], ans;
int main() {
  int n;
  scanf("%d", &n);
  bit.n = bit2.n = n;
  for (int i = 1; i <= n; i++) scanf("%lf", &a[i]);
  for (int i = 1; i <= n; i++) {
    ans += bit2.que(n - a[i] + 1) * n * (n + 1) / 2;
    bit2.add(n - a[i] + 1, 1);
    ans += (double)i * (i - 1) / 4 * (n - i + 1);
  }
  for (int i = 1; i <= n; i++) {
    ans -= (n - i + 1) * bit.que(n - a[i] + 1);
    bit.add(n - a[i] + 1, i);
  }
  ans /= (double)n * (n + 1) / 2;
  printf("%.12f\n", ans);
}
