#include <bits/stdc++.h>
using namespace std;
int A[100005];
pair<long long, long long> tree[500005];
long long treeR[500005];
long long cum[100005];
long long cumR[100005];
double dp[100005];
void update(int a, int l, int r, int node, int i) {
  if (l > a || r < a) return;
  if (l == a && l == r) {
    tree[node].first = i;
    tree[node].second = 1;
    return;
  }
  update(a, l, (l + r) / 2, 2 * node, i);
  update(a, (l + r) / 2 + 1, r, 2 * node + 1, i);
  tree[node] = make_pair(tree[2 * node].first + tree[2 * node + 1].first,
                         tree[2 * node].second + tree[2 * node + 1].second);
}
pair<long long, long long> query(int a, int b, int l, int r, int node) {
  if (l > b || r < a) return make_pair(0, 0);
  if (l >= a && r <= b) return tree[node];
  pair<long long, long long> lef = query(a, b, l, (l + r) / 2, 2 * node);
  pair<long long, long long> righ =
      query(a, b, (l + r) / 2 + 1, r, 2 * node + 1);
  return make_pair(lef.first + righ.first, lef.second + righ.second);
}
void updateR(int a, int l, int r, int node) {
  if (l > a || r < a) return;
  if (l == a && l == r) {
    treeR[node] = a;
    return;
  }
  updateR(a, l, (l + r) / 2, 2 * node);
  updateR(a, (l + r) / 2 + 1, r, 2 * node + 1);
  treeR[node] = treeR[2 * node] + treeR[2 * node + 1];
}
long long queryR(int a, int b, int l, int r, int node) {
  if (l > b || r < a) return 0;
  if (l >= a && r <= b) return treeR[node];
  long long lef = queryR(a, b, l, (l + r) / 2, 2 * node);
  long long righ = queryR(a, b, (l + r) / 2 + 1, r, 2 * node + 1);
  return lef + righ;
}
int main() {
  long long int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &A[i]);
  }
  double ans = 0;
  for (long long int i = 1; i <= n; ++i) {
    update(A[i], 1, 100001, 1, i);
    pair<long long, long long> need = query(A[i] + 1, 100001, 1, 100001, 1);
    ans += (((n * (n + 1)) / 2.0) * need.second - (need.first) * (n - i + 1.0));
  }
  dp[1] = 0;
  for (int i = 2; i <= 100000; ++i) {
    dp[i] = (1.0 * i - 1.0) / 2.0 + dp[i - 1];
  }
  for (int i = 1; i <= n; ++i) ans += 1.0 * (n - i + 1) * dp[i];
  ans = ans / (1.0 * n);
  ans = ans / (1.0 * (n + 1.0));
  ans = ans * 2.0;
  printf("%.10f\n", ans);
  return 0;
}
