#include <bits/stdc++.h>
using namespace std;
pair<long long, int> operator+(pair<long long, int> a, pair<long long, int> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
struct segmentTree {
  vector<pair<long long, int> > t;
  segmentTree(int n) { t.resize(4 * n + 7); }
  void change(int v, int tl, int tr, int pos, pair<long long, int> val) {
    if (tl == tr) {
      t[v] = val;
    } else {
      int tm = (tl + tr) / 2;
      if (pos <= tm) {
        change(2 * v, tl, tm, pos, val);
      } else {
        change(2 * v + 1, tm + 1, tr, pos, val);
      }
      t[v] = t[2 * v] + t[2 * v + 1];
    }
  }
  pair<long long, int> getSum(int v, int tl, int tr, int l, int r) {
    if (r < tl || l > tr) return make_pair(0, 0);
    if (tl >= l && tr <= r) return t[v];
    int tm = (tl + tr) / 2;
    return getSum(2 * v, tl, tm, l, r) + getSum(2 * v + 1, tm + 1, tr, l, r);
  }
};
int main() {
  int n;
  scanf("%d", &n);
  segmentTree st(n + 1);
  double res = 0;
  long long total = 1LL * n * (n + 1) / 2;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    pair<long long, int> go1 = st.getSum(1, 1, n, x, n);
    pair<long long, int> go2 = st.getSum(1, 1, n, 1, x);
    long long ways1 = 1LL * (n - i + 1) * go1.first;
    double prob1 = 1.0 * ways1 / total;
    res += prob1 * 0.5;
    double prob2 = 1.0 * go1.second - prob1;
    res += prob2;
    long long ways2 = 1LL * (n - i + 1) * go2.first;
    double prob3 = 1.0 * ways2 / total;
    res += prob3 * 0.5;
    st.change(1, 1, n, x, make_pair(i, 1));
  }
  printf("%.20lf\n", res);
}
