#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long b, long long p) {
  if (p == 0) return 1;
  long long my = bigmod(b, p / 2);
  my *= my;
  my %= 1000000007;
  if (p & 1) my *= b, my %= 1000000007;
  return my;
}
int setb(int n, int pos) { return n = n | (1 << pos); }
int resb(int n, int pos) { return n = n & ~(1 << pos); }
bool checkb(int n, int pos) { return (bool)(n & (1 << pos)); }
long long n, ara[200005], mx;
long long tree[200005];
long double get_val(long long x) {
  long long ret = (x * (x - 1)) / 2;
  return (long double)ret / 2.0;
}
long long read(long long ind) {
  long long sum = 0;
  while (ind > 0) {
    sum += tree[ind];
    ind -= (ind & -ind);
  }
  return sum;
}
void update(long long ind, long long val) {
  while (ind <= mx) {
    tree[ind] += val;
    ind += (ind & -ind);
  }
}
long long go(long long x) {
  long long mx = read(n);
  long long mn = read(x);
  return mx - mn;
}
int main() {
  long long i;
  scanf("%lld", &n);
  mx = n;
  for (i = 1; i <= n; i++) {
    scanf("%lld", &ara[i]);
  }
  long long act = 0;
  for (i = 1; i <= n; i++) {
    long long my = ara[i];
    act += go(my);
    update(my, 1);
  }
  memset(tree, 0, sizeof(tree));
  long long ret = 0;
  for (i = 1; i <= n; i++) {
    long long my = ara[i];
    ret += go(my) * (n - i + 1);
    update(my, i);
  }
  long double tot = 0.0;
  for (i = 1; i <= n; i++) {
    long long my = (n - i + 1);
    tot += (my * get_val(i));
  }
  long double love = tot - ret;
  love *= 2.0;
  love /= ((n * (n + 1)));
  printf("%.20f\n", (double)(love + act));
  return 0;
}
