#include <bits/stdc++.h>
using namespace std;
int n, a[1000010], last[1000010];
double ans, res;
int main() {
  memset(last, 0, sizeof(last)), scanf("%d", &n), ans = double(n),
                                                  res = double(n) * double(n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), ans += double(n - i) * double(i + 1) * 2.0;
  for (int i = 1; i <= n; i++) {
    if (last[a[i]]) ans -= double(last[a[i]]) * double(n - i + 1) * 2.0;
    last[a[i]] = i;
  }
  printf("%.6f", ans / res);
  return 0;
}
