#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n;
cin >> n;
vector<ll> a(n + 1);
for (ll i = 1; i <= n; i++)
cin >> a[i];
vector<ll> lastOcc(n + 1, 0);
vector<ll> ans(n + 1, 0);
ans[0] = 0;
double sum = 0.0;
for (ll i = 1; i <= n; i++)
{
ans[i] = ans[i - 1] + (i - lastOcc[a[i]]);
lastOcc[a[i]] = i;
sum = sum + ans[i];
}
double expected = 0.0;
expected = (2 * (sum - n) + n) / (n * n * 1.0);
cout << fixed << setprecision(6) << expected << endl;
return 0;
}