#include <bits/stdc++.h>
using namespace std;
int n;
int a[1000005];
int Last[1000005];
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  long long nume = 0;
  long long denom = 1LL * n * n;
  for (int i = 1; i <= n; i++) {
    int mark = Last[a[i]] + 1;
    nume += (((i - mark + 1) * 1LL * (n - i + 1)) - 1) * 1LL * 2;
    Last[a[i]] = i;
  }
  nume += n;
  long long g = gcd(nume, denom);
  nume /= g;
  denom /= g;
  printf("%.10Lf\n", (long double)nume / (long double)denom);
  return 0;
}
