#include <bits/stdc++.h>
using namespace std;
const int N = 101000;
long long bit[N], sm[N];
int n, lin[N], a[N];
double ans = 0, rev;
inline bool cmp(int x, int y) { return a[x] > a[y]; }
inline void modify(long long *a, int x, int v) {
  for (; x <= n; x += x & -x) a[x] += v;
}
inline long long query(long long *a, int x) {
  long long tmp = 0;
  for (; x; x -= x & -x) tmp += a[x];
  return tmp;
}
int main() {
  ios ::sync_with_stdio(false);
  cin >> n;
  int x;
  long long tmp, rec;
  for (int i = 1, nn = int(n); i <= nn; ++i) cin >> a[i], lin[i] = i;
  sort(lin + 1, lin + 1 + n, cmp);
  for (int i = 2, nn = int(n); i <= nn; ++i)
    ans += (double)(n - i + 1) * (double)i * (double)(i - 1) / (double)4;
  for (int i = 1, nn = int(n); i <= nn; ++i) {
    x = lin[i];
    tmp = query(bit, x), rec = query(sm, x);
    rev += rec, ans -= (double)(n - x + 1) * (double)tmp;
    modify(bit, x, x), modify(sm, x, 1);
  }
  ans += (double)rev * (double)n * (double)(n + 1) / (double)2;
  ans /= (double)n * (double)(n + 1) / (double)2;
  cout.setf(ios ::fixed);
  cout << setprecision(12) << ans << endl;
  return 0;
}
