#include <bits/stdc++.h>
using namespace std;
long long bit_total[100005], bit_parcial[100005];
double F[100005], sumF[100005];
int v[100005];
long long query(long long *bit, int idx) {
  long long sum = 0;
  while (idx) {
    sum += bit[idx];
    idx -= (idx & -idx);
  }
  return sum;
}
void update(long long *bit, int idx, long long delta) {
  while (idx < 100005) {
    bit[idx] += delta;
    idx += (idx & -idx);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", v + i);
  F[1] = sumF[1] = 0;
  for (int i = 2; i <= n; i++) {
    F[i] = F[i - 1] + (i - 1) / 2.0;
    sumF[i] = F[i] + sumF[i - 1];
  }
  double ans = 0;
  double deno = (1. * n * (n + 1) / 2);
  for (int i = 1; i <= n; i++) {
    int k = n - i + 1;
    ans += sumF[k] / deno;
  }
  long long total = 0;
  double parcial = 0;
  for (int i = n; i >= 1; i--) {
    total += query(bit_total, v[i]);
    update(bit_total, v[i], 1);
    parcial += i * query(bit_parcial, v[i]) / deno;
    update(bit_parcial, v[i], n - i + 1);
  }
  printf("%.20f\n", ans + (total - parcial));
  return 0;
}
