#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
double ans;
int n, a[N];
pair<int, long long> operator+(pair<int, long long> a, pair<int, long long> b) {
  return pair<int, long long>(a.first + b.first, a.second + b.second);
}
void operator+=(pair<int, long long> &a, pair<int, long long> b) {
  a.first += b.first;
  a.second += b.second;
}
pair<int, long long> t[N];
void upd(int x, pair<int, long long> v) {
  for (; x > 0; x -= x & -x) t[x] += v;
}
pair<int, long long> get(int x) {
  pair<int, long long> res = pair<int, long long>(0, 0);
  for (; x <= n; x += x & -x) res += t[x];
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    pair<int, long long> res = get(a[i]);
    ans += res.first;
    ans -= 2.0 * ((double)(n - i + 1) / n) * ((double)res.second / (n + 1));
    upd(a[i], pair<int, long long>(1, i));
  }
  for (int i = 1; i <= n; ++i)
    ans += 0.5 * ((double)(1ll * i * (i - 1)) / (n + 1)) *
           ((double)(n - i + 1) / n);
  cout << setprecision(9) << fixed << ans << endl;
}
