#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n;
long long BIT[2][N];
int a[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  int x;
  double ans = 0;
  for (int i = (1); i <= (n); i++) cin >> a[i];
  for (int i = n; i; i--) {
    int j = a[i];
    while (j) {
      ans += BIT[0][j];
      ans -= 2. * i * BIT[1][j] / n / (n + 1);
      j -= j & -j;
    }
    j = a[i];
    while (j <= n) {
      BIT[0][j]++;
      BIT[1][j] += n + 1 - i;
      j += j & -j;
    }
    ans += (n - i + 1.) * i * (i - 1) / n / (n + 1) / 2;
  }
  cout << fixed << setprecision(13) << ans << endl;
}
