#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5 + 5;
int n, a[nmax];
long long cntInv[nmax];
double c[nmax];
class Aib {
 public:
  long long aib[nmax];
  Aib() {
    for (int i = 0; i < nmax; ++i) {
      aib[i] = 0;
    }
  }
  int lsb(int x) { return x & (-x); }
  void update(int pos, int val) {
    for (; pos <= n; pos += lsb(pos)) {
      aib[pos] += val;
    }
  }
  long long query(int pos) {
    long long sum = 0;
    for (; pos > 0; pos -= lsb(pos)) {
      sum += aib[pos];
    }
    return sum;
  }
  long long queryRange(int a, int b) { return query(b) - query(a - 1); }
};
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  Aib aib;
  Aib aibInv;
  long long totalInv = 0;
  for (int i = n; i >= 1; --i) {
    cntInv[i] = cntInv[i + 1] + aib.queryRange(1, a[i]);
    aib.update(a[i], n - i + 1);
    totalInv += aibInv.queryRange(1, a[i]);
    aibInv.update(a[i], 1);
  }
  for (int i = 1; i <= n; ++i) {
    c[i] = 1.0 * i * (i - 1) / 4.0;
    c[i] += c[i - 1];
  }
  double ans = 0.0;
  long long numitor = 1LL * n * (n + 1) / 2;
  for (int i = n; i >= 1; --i) {
    ans += ((1.0 * (n - i + 1) * totalInv - 1.0 * cntInv[i] + c[n - i + 1]) /
            (1.0 * numitor));
  }
  cout << fixed << setprecision(10) << ans << "\n";
  return 0;
}
