#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000 + 20;
long long n, a[MAXN];
vector<long long> gr[MAXN];
long double ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= 1000 * 1000 + 3; i++) gr[i].push_back(0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    gr[a[i]].push_back(i);
  }
  for (int i = 1; i <= 1000 * 1000 + 3; i++) gr[i].push_back(n + 1);
  for (int i = 1; i <= 1000 * 1000 + 3; i++)
    for (int j = 1; j < int(gr[i].size() - 1); j++)
      ans += (long double)(((gr[i][j]) * (gr[i][j + 1] - gr[i][j]) - 1) * 2) /
             (n * n);
  cout << fixed << setprecision(6) << ans + ((double)(1) / n) << endl;
  return 0;
}
