#include <bits/stdc++.h>
using namespace std;
const int N = 1000007;
int v[N];
vector<int> pos[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    pos[v[i]].push_back(i);
  }
  for (int i = 0; i < N; ++i) {
    reverse(pos[i].begin(), pos[i].end());
  }
  set<int> s;
  long long cnt = 0;
  for (int i = 0; i < n; ++i) {
    s.insert(v[i]);
    cnt += s.size();
  }
  long long ans = 2ll * cnt;
  long long cur = 0;
  for (int l = 0; l < n; ++l) {
    int x = v[l];
    pos[x].pop_back();
    int j = n;
    if (pos[x].size()) j = pos[x].back();
    cnt -= 1;
    cnt -= (j - l - 1);
    ans += 2ll * cnt;
  }
  ans -= n;
  cout << fixed << setprecision(10)
       << (ans / (1.0 * ((long long)n * (long long)n))) << endl;
}
