#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int n, a[maxn];
vector<int> v[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int t;
    scanf("%d", &t);
    v[t].push_back(i);
  }
  long long res = 0;
  for (int i = 1; i < maxn; ++i)
    for (int j = 0; j < (int)v[i].size(); ++j) {
      long long l = 0, r = n + 1, m = v[i][j];
      if (j > 0) l = v[i][j - 1];
      res += (r - l - 1) * (r - l - 1) - (m - l - 1) * (m - l - 1) -
             (r - m - 1) * (r - m - 1);
    }
  printf("%.12f\n", 1.0 * res / n / n);
  return 0;
}
