#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<long long> ft(n + 10, 0);
  auto update = [&](int pos, int val) {
    while (pos < int(ft.size())) {
      ft[pos] += val;
      pos += pos & -pos;
    }
  };
  auto get = [&](int pos) {
    long long ret = 0;
    while (pos) {
      ret += ft[pos];
      pos -= pos & -pos;
    }
    return ret;
  };
  long long inv = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    inv += i - 1 - get(a[i]);
    update(a[i], 1);
  }
  fill(begin(ft), end(ft), 0);
  double iden = 1.0 / (1LL * n * (n + 1));
  double diff = 0;
  for (int i = n; i >= 1; i--) {
    diff += iden * (get(n) - get(a[i])) * i;
    diff -= iden * get(a[i]) * i;
    update(a[i], n - i + 1);
  }
  cout << fixed << setprecision(15) << inv + diff << '\n';
  return (0);
}
