#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];
long long bit[200005][2];
long long total;
double ans;
void standing_by() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
}
void add_bit(int x, int y, int v) {
  for (; x <= n; x += (x & (-x))) bit[x][y] += v;
}
long long sum_bit(int x, int y) {
  long long ans = 0;
  for (; x > 0; x -= (x & (-x))) ans += bit[x][y];
  return ans;
}
void complete() {
  int i;
  total = 1ll * (n + 1) * n / 2;
  for (i = n; i >= 1; i--) {
    ans += 1.0 * (n - i + 1) / total * i * (i - 1) / 4;
    ans += sum_bit(a[i], 0);
    ans -= 1.0 * sum_bit(a[i], 1) * i / total;
    add_bit(a[i], 0, 1);
    add_bit(a[i], 1, n - i + 1);
  }
  printf("%.15lf\n", ans);
}
int main() {
  standing_by();
  complete();
  return 0;
}
