#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << "," << p.second << "}";
  return os;
}
const long long N = 1e6 + 5;
const long long oo = 1e9 + 7;
long long a[N];
vector<long long> idx[N];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    idx[a[i]].push_back(i);
  }
  long double ans = 0;
  for (long long i = 1; i < N; i++) {
    if (idx[i].empty()) continue;
    long long last = 0;
    for (long long j : idx[i]) {
      ans += (j - last) * (n - j + 1) - 1;
      last = j;
    }
  }
  ans = (ans * 2 + n) / n / n;
  cout << setprecision(10) << ans << "\n";
}
