#include <bits/stdc++.h>
template <class T>
void Swap(T& a, T& b) {
  T c = a;
  a = b;
  b = c;
}
template <class T>
T max(T& a, T& b) {
  return a < b ? b : a;
}
template <class T>
T min(T& a, T& b) {
  return a > b ? b : a;
}
using namespace std;
double ans1, ans2, tmp, S;
int a[100010], n;
long long g[100010];
void add(int x, int y) {
  for (; x <= n; x += x & -x) g[x] += y;
}
long long query(int x) {
  long long y = 0;
  for (; x; x -= x & -x) y += g[x];
  return y;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = n; i >= 1; i--) {
    ans1 += (double)query(a[i]);
    add(a[i], 1);
  }
  memset(g, 0, sizeof g);
  for (int i = n; i >= 1; i--) {
    ans2 -= (double)query(a[i]) * i;
    add(a[i], n - i + 1);
  }
  for (int i = 1; i <= n; i++) {
    tmp += (double)(i - 1) / 2.0;
    ans2 += (double)tmp * (n - i + 1);
  }
  printf("%.10f", ans1 + 2.0 * ans2 / n / (n + 1));
  return 0;
}
