#include <bits/stdc++.h>
using namespace std;
int n, a[100007];
long long bit[100007];
long long f[100007];
double res;
void update_bit(int x, int v) {
  while (x > 0) {
    bit[x] += v;
    x -= (x & (-x));
  }
}
long long get_bit(int x) {
  long long res = 0;
  while (x <= n) {
    res += bit[x];
    x += (x & (-x));
  }
  return res;
}
int main() {
  cout.precision(9);
  cout << fixed;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  f[1] = 0;
  for (int i = 2; i <= n; ++i) f[i] = f[i - 1] + (i - 1);
  long long r = 0;
  for (int i = 1; i <= n; ++i) r = r + f[i] * (n + 1 - i);
  for (int i = 1; i <= n; ++i) {
    r -= get_bit(a[i]) * 2 * (n + 1 - i);
    update_bit(a[i], i);
  }
  res = r;
  res = res / n / (n + 1);
  memset(bit, 0, sizeof(bit));
  for (int i = 1; i <= n; ++i) {
    res += get_bit(a[i]);
    update_bit(a[i], 1);
  }
  cout << res;
  return 0;
}
