#include <bits/stdc++.h>
using namespace std;
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
vector<int> g[N];
int a[N];
long long bit[2][N];
void add(int x, int val) {
  while (x < N) bit[0][x] += val, x += x & (-x);
}
void inc(int x, int val) {
  while (x < N) bit[1][x] += val, x += x & (-x);
}
long long query(int x) {
  long long ans = 0;
  while (x) ans += bit[0][x], x -= x & (-x);
  return ans;
}
long long cnt(int x) {
  long long ans = 0;
  while (x) ans += bit[1][x], x -= x & (-x);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, n, k, j;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  double num = 0;
  long long n2 = n * 1LL * (n + 1);
  for (i = n - 1; n - 1 < -1 ? i < -1 : i > -1; n - 1 < -1 ? i += 1 : i -= 1) {
    long long x;
    long long tem = query(n) - (x = query(a[i]));
    num += ((i + 1) * tem * 1.0) / n2;
    num += cnt(a[i]) - ((i + 1) * x * 1.0) / n2;
    add(a[i], n - i);
    inc(a[i], 1);
  }
  cout << fixed << setprecision(10) << num << endl;
  return 0;
}
