#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long fen[maxn], n, a[maxn], w[maxn], inv1, inv2;
long double ev;
inline void up(int u, long long v) {
  for (int i = u; i <= n; i += i & (-i)) {
    fen[i] += v;
  }
}
long long gt(int u) {
  long long o = 0;
  for (int i = u; i > 0; i -= i & (-i)) {
    o += fen[i];
  }
  return o;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    inv1 += gt(n) - gt(a[i]);
    up(a[i], 1);
    ev += (n - i) * (i + 1) * i / 4.0;
  }
  memset(fen, 0, sizeof fen);
  for (int i = 0; i < n; ++i) {
    inv2 += (n - i) * (gt(n) - gt(a[i]));
    up(a[i], i + 1);
  }
  cout << setprecision(14) << fixed << (ev - inv2) / (n * (n + 1) / 2) + inv1;
  return 0;
}
