#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, z, w, t, s, f, d, ans, a[1000100];
vector<long long> v[1000100];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    v[a[i]].push_back(i + 1);
  }
  ans = n;
  for (int i = 1; i <= 1e6; i++) {
    m = n * (n - 1);
    v[i].push_back(n + 1);
    for (int j = 0; j < v[i].size() - 1; j++) {
      x = (v[i][j + 1] - v[i][j] - 1);
      m -= x * (x - 1);
    }
    x = v[i][0] - 1;
    m -= x * (x - 1);
    ans += m;
  }
  long double xx = ans, yy = n * n;
  cout << fixed << setprecision(6);
  cout << xx / yy;
  return 0;
}
