#include <bits/stdc++.h>
using namespace std;
int n;
vector<long long> freq[1000001];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    freq[a].push_back(i);
  }
  long long sumprob = 0;
  for (int i = 1; i <= 1000000; i++) {
    long long temp = 0;
    for (long long ind : freq[i]) {
      sumprob += (ind - temp - 1) * (ind - temp - 1);
      temp = ind;
    }
    sumprob += (n - temp) * (n - temp);
  }
  cout << fixed << setprecision(6) << 1e6 - 1.0 * sumprob / n / n;
  return 0;
}
