#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int a[N];
inline int lowbit(int x) { return x & -x; }
struct BIT {
  long long c[N];
  void modify(int x, int v) {
    for (int i = x; i < N; i += lowbit(i)) c[i] += v;
  }
  long long query(int x) {
    long long res = 0;
    for (int i = x; i; i -= lowbit(i)) res += c[i];
    return res;
  }
} c, s;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  double res = 0;
  for (int i = 1; i <= n; ++i) {
    double cur = i * 0.5 * (n - i) * (n - i + 1);
    res += cur;
  }
  for (int i = n; i >= 1; --i) {
    double pres =
        c.query(a[i] - 1) * 1.0 * (n * 1.0 * n + n - 2 * i - 2.0 * n * i);
    pres += 2.0 * i * (s.query(a[i] - 1));
    c.modify(a[i], 1);
    s.modify(a[i], i);
    res += pres;
  }
  printf("%.18lf\n", res / n / (n + 1));
  return 0;
}
