#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct BIT {
    int n;
    vector<ll> t;
    BIT(int n) : n(n), t(n + 1) {}
    void add(int p, ll v) {
        for (; p <= n; p += p & -p)
            t[p] += v;
    }
    ll sum(int p) {
        ll s = 0;
        for (; p; p -= p & -p)
            s += t[p];
        return s;
    }
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    BIT cnt(n), weight(n);
    ll inv = 0, W = 0;
    for (int j = 1, x; j <= n; j++) {
        cin >> x;
        inv += j - 1 - cnt.sum(x);
        W += (n - j + 1) * (1LL * j * (j - 1) / 2 - weight.sum(x));
        cnt.add(x, 1);
        weight.add(x, j);
    }
    long double M = (long double)n * (n + 1) / 2,
                ans = inv - (long double)W / M + (long double)(n - 1) * (n + 2) / 24;
    cout << fixed << setprecision(15) << ans << '\n';
}
