#include <bits/stdc++.h>
using namespace std;
int a[1000005], v[1000004];
long long dp[1000005], x[1000004];
int main() {
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = n; i >= 1; i--) {
    x[i] = v[a[i]];
    v[a[i]] = i;
  }
  dp[n] = 1;
  double ans = 1;
  for (long long i = n - 1; i >= 1; i--) {
    if (x[i] == 0) {
      dp[i] = dp[i + 1] + (n - i);
    } else {
      dp[i] = dp[i + 1] + (x[i] - i - 1LL);
    }
    long long u = 2LL * dp[i];
    ans += u;
    dp[i]++;
    ans++;
  }
  ans = ans / (double)(n * n);
  printf("%.12f", ans);
}
