#include <bits/stdc++.h>
using namespace std;
template <typename X>
ostream& operator<<(ostream& x, const vector<X>& v) {
  for (int i = 0; i < v.size(); ++i) x << v[i] << " ";
  return x;
}
template <typename X>
ostream& operator<<(ostream& x, const set<X>& v) {
  for (auto it : v) x << it << " ";
  return x;
}
template <typename X, typename Y>
ostream& operator<<(ostream& x, const pair<X, Y>& v) {
  x << v.ff << " " << v.ss;
  return x;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
  for (auto it : v) os << it.first << "=>" << it.second << endl;
  return os;
}
struct pair_hash {
  inline std::size_t operator()(const std::pair<int, int>& v) const {
    return v.first * 31 + v.second;
  }
};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int N = 1000005;
;
vector<long long> in[N];
int main() {
  for (long long i = 0; i < N; i++) {
    in[i].push_back(-1);
  }
  long long n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  };
  for (long long i = 0; i < n; i++) {
    in[a[i]].push_back(i);
  }
  long double xx = 0;
  for (long long i = 0; i < N; i++) {
    if (in[i].size() == 1) {
      continue;
    }
    for (long long j = 1; j < in[i].size(); j++) {
      xx += ((long long)(in[i][j] - in[i][j - 1]) * (long long)(n - in[i][j]));
    }
  }
  xx *= 2;
  xx -= n;
  xx /= (long double)(n * n);
  cout << setprecision(20);
  cout << xx << endl;
}
