#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 10;
struct fenwick {
  long long a[MAXN];
  fenwick() { fill(a, a + MAXN, 0); }
  void update(long long id, long long val) {
    for (; id < MAXN; id += ((id) & -(id))) {
      a[id] += val;
    }
  }
  long long get_sum(long long id) {
    long long sum = 0;
    for (; id > 0; id -= ((id) & -(id))) {
      sum += a[id];
    }
    return sum;
  }
};
fenwick fen_1;
fenwick fen_2;
vector<pair<long long, long long> > query;
long long a[MAXN];
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  long double res = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    query.push_back(make_pair(a[i], i));
    res += (long double)(n - i + 1) * i * (i - 1) /
           ((long double)(2) * n * (n + 1));
  }
  sort(query.begin(), query.end());
  for (long long i = 0; i < query.size(); i++) {
    long double e = (fen_1.get_sum(MAXN - 1) - fen_1.get_sum(query[i].second) -
                     (query[i].second * (fen_2.get_sum(MAXN - 1) -
                                         fen_2.get_sum(query[i].second)))) *
                    query[i].second;
    e += ((long double)(n - query[i].second) * (n - query[i].second + 1) *
          (fen_2.get_sum(MAXN - 1) - fen_2.get_sum(query[i].second))) /
         (long double)(2);
    e += ((long double)(query[i].second) * (query[i].second - 1) *
          (fen_2.get_sum(MAXN - 1) - fen_2.get_sum(query[i].second))) /
         (long double)(2);
    res += e * 2 / (n * (n + 1));
    fen_1.update(query[i].second, query[i].second);
    fen_2.update(query[i].second, 1);
  }
  cout << fixed << setprecision(15) << res;
}
