#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 5;
pair<long long, long long> seg[4 * maxn];
void add(long long id, long long L, long long R, long long idx, long long val) {
  if (idx < L || idx >= R) return;
  if (R == L + 1) {
    seg[id].second++;
    seg[id].first += val;
    return;
  }
  long long mid = (L + R) / 2;
  add(2 * id + 0, L, mid, idx, val);
  add(2 * id + 1, mid, R, idx, val);
  seg[id].second = seg[2 * id].second + seg[2 * id + 1].second;
  seg[id].first = seg[2 * id].first + seg[2 * id + 1].first;
}
pair<long long, long long> get(long long id, long long L, long long R,
                               long long l, long long r) {
  if (r <= l || R <= l) return pair<long long, long long>(0, 0);
  if (L >= l && R <= r) return seg[id];
  long long mid = (L + R) / 2;
  pair<long long, long long> P = get(2 * id + 0, L, mid, l, r);
  pair<long long, long long> Q = get(2 * id + 1, mid, R, l, r);
  return pair<long long, long long>(P.first + Q.first, P.second + Q.second);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  long double ans = (n + 2) * (n - 1) / 24.0;
  for (long long i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    tmp--;
    pair<long long, long long> P = get(1, 0, n, tmp, n);
    ans += P.second -
           (long double)((n - i) * P.first) / (long double)(n * (n + 1) / 2);
    add(1, 0, n, tmp, i + 1);
  }
  cout << setprecision(30) << ans;
}
