#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const long long LINF = INF * (long long)INF;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAX = 100005;
const int LG = 20;
long long ft[2][MAX];
void inc(int idx, int pos, int delta) {
  for (; pos < MAX; pos |= pos + 1) ft[idx][pos] += delta;
}
long long sum(int idx, int pos) {
  long long res = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) res += ft[idx][pos];
  return res;
}
int pos[MAX];
int main() {
  double ans = 0;
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) ans += i * (i - 1) * (n - i + 1) / 4.;
  long long div = n * (n + 1) / 2;
  for (int i = 0; i < n; i++) {
    int first;
    cin >> first;
    first--;
    pos[first] = i;
  }
  for (int i = n - 1; i >= 0; i--) {
    ans += sum(0, pos[i]) * n * (n + 1) / 2;
    ans -= (n - pos[i]) * sum(1, pos[i]);
    inc(0, pos[i], 1);
    inc(1, pos[i], pos[i] + 1);
  }
  cout << fixed << setprecision(10) << ans / div << endl;
}
