#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 17;
long long fen[MAXN][2], a[MAXN];
long double ans, res, inv, n;
long long get(bool flag, int x) {
  long long res = 0;
  for (; x; x -= x & (-x)) res += fen[x][flag];
  return res;
}
void add(int x, long long y) {
  for (; x <= n; x += x & (-x)) fen[x][0]++, fen[x][1] += y;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (long long i = n; i > 0; i--) {
    inv += get(0, a[i]);
    res += i * get(1, a[i]);
    add(a[i], n - i + 1);
  }
  res = -res;
  for (long long i = 2; i <= n; i++) res += (n - i + 1) * i * (i - 1) / 4;
  ans = inv;
  ans += res / (n * (n + 1) / 2);
  cout << fixed << setprecision(11) << ans << endl;
  return 0;
}
