#include <bits/stdc++.h>
using namespace std;
long long N, a[100010], s[100100], cnt[100010];
void update(long long *t, long long pos, long long val) {
  for (; pos <= N; pos += pos & (-pos)) t[pos] += val;
}
long long query(long long *t, long long r) {
  long long res = 0;
  for (; r > 0; r -= r & (-r)) res += t[r];
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N;
  int i;
  long long nr, sum;
  long double res = 0;
  for (i = 1; i <= N; i++) {
    cin >> a[i];
    update(cnt, a[i], 1);
    update(s, a[i], i);
  }
  for (i = 1; i <= N; i++) {
    nr = query(cnt, a[i] - 1);
    sum = query(s, a[i] - 1);
    res += nr - (1.0 * i * (nr * (N + 1) - sum)) / (N * (N + 1));
    nr = N - i - nr;
    sum = query(s, N) - sum - i;
    res += (1.0 * i * (nr * (N + 1) - sum)) / (N * (N + 1));
    update(cnt, a[i], -1);
    update(s, a[i], -i);
  }
  cout << fixed << setprecision(15) << res << "\n";
  return 0;
}
