#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
struct BIT {
  long long N;
  vector<long long> bit;
  void init(long long n) {
    N = n;
    bit.assign(n + 1, 0);
  }
  void update(long long idx, long long val) {
    while (idx <= N) {
      bit[idx] += val;
      idx += idx & -idx;
    }
  }
  void updateMax(long long idx, long long val) {
    while (idx <= N) {
      bit[idx] = max(bit[idx], val);
      idx += idx & -idx;
    }
  }
  long long pref(long long idx) {
    long long ans = 0;
    while (idx > 0) {
      ans += bit[idx];
      idx -= idx & -idx;
    }
    return ans;
  }
  long long rsum(long long l, long long r) { return pref(r) - pref(l - 1); }
  long long prefMax(long long idx) {
    long long ans = -2e9;
    while (idx > 0) {
      ans = max(ans, bit[idx]);
      idx -= idx & -idx;
    }
    return ans;
  }
};
long long n;
long long a[N];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  BIT bit;
  bit.init(1e5);
  for (long long i = 1; i <= n; i++) cin >> a[i];
  double ans = 0;
  for (long long i = n; i >= 1; i--) {
    ans += bit.pref(a[i]);
    bit.update(a[i], 1);
  }
  bit.init(1e5);
  double extra = 0;
  for (long long i = 1; i <= n; i++) {
    extra += (n - i + 1) * bit.pref(a[i]);
    bit.update(a[i], i);
    a[i] = n - a[i] + 1;
  }
  extra /= n;
  extra /= (n + 1);
  ans += extra;
  bit.init(1e5);
  extra = 0;
  for (long long i = 1; i <= n; i++) {
    extra += (n - i + 1) * bit.pref(a[i]);
    bit.update(a[i], i);
    a[i] = n - a[i] + 1;
  }
  extra /= n;
  extra /= (n + 1);
  ans -= extra;
  cout << fixed << setprecision(12) << ans;
  return 0;
}
