#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
pair<long long int, long long int> extended_euclid(long long int a,
                                                   long long int b) {
  if (b == 0)
    return pair<long long int, long long int>(1, 0);
  else {
    pair<long long int, long long int> d = extended_euclid(b, a % b);
    return pair<long long int, long long int>(d.second,
                                              d.first - d.second * (a / b));
  }
}
long long int modular_inverse(long long int a, long long int m) {
  pair<long long int, long long int> ret = extended_euclid(a, m);
  return ((ret.first % m) + m) % m;
}
const int mod = 1000000007;
long long int sum[100000 + 7], n, arr[100000 + 7];
long long int tree[4 * 100000 + 7];
long long int tree2[4 * 100000 + 7];
long long int update(int node, int base, int top, int p, long long int val) {
  if (base > p or top < p) return tree[node];
  if (base == top) {
    return tree[node] = val;
  }
  int left, right, mid;
  left = 2 * node;
  right = left + 1;
  mid = (base + top) / 2;
  tree[node] = update(left, base, mid, p, val);
  tree[node] += update(right, mid + 1, top, p, val);
  return tree[node];
}
long long int query(int node, int base, int top, int i, int j) {
  if (base > j or top < i) return 0;
  if (base >= i and top <= j) return tree[node];
  int left, right, mid;
  left = 2 * node;
  right = left + 1;
  mid = (base + top) / 2;
  long long int ret = query(left, base, mid, i, j);
  ret += query(right, mid + 1, top, i, j);
  return ret;
}
double cal_exp(long long int num) {
  long long int res1 = num * (num + 1) * (2 * num + 1);
  res1 /= 6;
  long long int res2 = num * (num + 1);
  res2 /= 2;
  long long int ret = res1 - res2;
  double res = (double)ret / 4.0;
  return res;
}
long long int update2(int node, int base, int top, int p) {
  if (base > p or top < p) return tree2[node];
  if (base == top) {
    return tree2[node] = 1;
  }
  int left, right, mid;
  left = 2 * node;
  right = left + 1;
  mid = (base + top) / 2;
  tree2[node] = update2(left, base, mid, p);
  tree2[node] += update2(right, mid + 1, top, p);
  return tree2[node];
}
long long int query2(int node, int base, int top, int i, int j) {
  if (base > j or top < i) return 0;
  if (base >= i and top <= j) return tree2[node];
  int left, right, mid;
  left = 2 * node;
  right = left + 1;
  mid = (base + top) / 2;
  long long int ret = query2(left, base, mid, i, j);
  ret += query2(right, mid + 1, top, i, j);
  return ret;
}
int main() {
  long long int i, j, k;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &arr[i]);
  }
  double ans = 0.0;
  long long int rem = 0;
  for (i = n; i > 0; i--) {
    sum[i] = sum[i + 1] + query(1, 1, n, 1, arr[i]);
    rem += query2(1, 1, n, 1, arr[i]);
    double ex = cal_exp(n - i + 1);
    ans += ex - (double)sum[i];
    update(1, 1, n, arr[i], n - i + 1);
    update2(1, 1, n, arr[i]);
  }
  long long int val = n * (n + 1);
  ans *= 2.0;
  ans /= (double)val;
  ans += rem;
  printf("%.11f\n", ans);
  return 0;
}
