#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1LL;
  long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = mul(_ret, _a, _mod);
  return _ret;
}
long long mymul(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 0LL;
  long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = add(_ret, _a, _mod);
  return _ret;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, _cs;
void build() {}
int n, per[101010];
long long BIT[101010];
inline void bit_init() {
  for (int i = 0; i <= n; i++) BIT[i] = 0;
}
inline int lb(int x) { return x & (-x); }
inline void modify(int x, long long dlt) {
  for (int i = x; i <= n; i += lb(i)) BIT[i] += dlt;
}
inline long long query(int x) {
  long long ret = 0;
  for (int i = x; i; i -= lb(i)) ret += BIT[i];
  return ret;
}
void init() {
  n = getint();
  for (int i = 1; i <= n; i++) per[i] = getint();
}
void solve() {
  double all = 0, dn = (double)n * (n + 1) * 0.5;
  for (int i = n; i >= 1; i--) {
    all += query(per[i]);
    modify(per[i], 1);
  }
  bit_init();
  double suminv = 0;
  for (int i = n; i >= 1; i--) {
    suminv += query(per[i]);
    all += (double)(n - i + 1) * i * (i - 1) / 4 / dn;
    all -= suminv / dn;
    modify(per[i], n - i + 1);
  }
  printf("%.12f\n", all);
}
int main() {
  build();
  while (__--) {
    init();
    solve();
  }
}
