#include <stdio.h>
#include <stdlib.h>
#pragma warning(disable:4996)

int main() {
	int n;
	scanf("%i", &n);
	int group = 1;
	int* A;
	A = (int*)malloc(n*sizeof(int));
	for (int i = 0; i < n; i++)
	{
		scanf("%i", &A[i]);
		if (A[i] == 10 && A[i - 1] == 10)
			continue;
		else if (A[i] == 10 && A[i - 1] == 01)
			group += 1;
		else if (A[i] == 01 && A[i - 1] == 01)
			continue;
		else if (A[i] == 01 && A[i - 1] == 10)
			group += 1;
	}
	if (n == 1)
		printf("1");
	else
	printf("%i", group);
	return 0;

}


#include <stdio.h>
#pragma warning(disable:4996)

int main() {
	int n;
	scanf("%i", &n);
	int group = 1;
	for (int i = 0; i < n; i++)
	{
		int A[10000];
		scanf("%i", &A[i]);
		if (A[i] == 10 && A[i - 1] == 10)
			continue;
		else if (A[i] == 10 && A[i - 1] == 01)
			group += 1;
		else if (A[i] == 01 && A[i - 1] == 01)
			continue;
		else if (A[i] == 01 && A[i - 1] == 10)
			group += 1;
	}
	if (n == 1)
		printf("1");
	else
	printf("%i", group);
	return 0;

}


#include<iostream>
using namespace std;
int main()
{
    long long int n,i,c=0;
    cin>>n;
    int a[100001];
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n-1;i++)
    {
        if(a[i]!=a[i+1])
        c++;
    }
    if(n==1)
    cout<<1;
    else
    cout<<c+1;
}


#include<iostream>
using namespace std;
int main()
{
    long long int n,i,c=0;
    cin>>n;
    int a[100001];
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n-1;i++)
    {
        if(a[i]==a[i+1])
        c++;
    }
    cout<<c;
}


#include<iostream>
using namespace std;
int main()
{
    long long int n,i;
    cin>>n;
    int a[100001];
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n-1;i++)
    {
        if(a[i]==a[i+1])
        c++;
    }
    cout<<c+1;
}


#include<iostream>
using namespace std;
int main()
{
    long long int n,i;
    cin>>n;
    int a[100001];
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n-1;i++)
    {
        if(a[i]==a[i+1])
        c++;
    }
    cout<<c;
}


#include<iostream>
using namespace std;
int main()
{
    long long int n,i,c=0;
    cin>>n;
    int a[100001];
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n-1;i++)
    {
        if(a[i]==a[i+1])
        c++;
    }
    cout<<c+1;
}


#include"algorithm"
#include"iostream"
#include"string.h"
#include"stdlib.h"
#include"stdio.h"
#include"math.h"
#include"vector"
#define ll long long
using namespace std;
namespace io
{
	char B[1<<20],*S,*T;
	inline char gc()
	{
		if(S==T)
		{
			T=(S=B)+fread(B,1,1<<20,stdin);
			return S==T?EOF:*S++;
		}
		return *S++;
	}
	template<class T>
	void gi(T&x)
	{
		x=0;register char ch=gc();register int f=1;
		while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
		while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=gc();}
		x*=f;
	}
}
using io::gi;
const int Maxn=1000005;
int a[Maxn],p[Maxn];
bool flag[Maxn];
vector<int>next[Maxn];
int main()
{
	#ifdef whlzy
	freopen("text.in","r",stdin);
	#endif
	int n;scanf("%d",&n);ll ans=0;
	memset(next,0,sizeof(next));
	for(int i=1;i<=n;i++)
	{
		gi(a[i]);
		if(flag[a[i]]==0)
			next[a[i]].push_back(0),flag[a[i]]=1;
		else
			next[a[i]][++next[a[i]][0]]=i,p[a[i]]=1;
	}
	for(int i=1;i<=n;i++)
		if(next[a[i]][0]==p[a[i]]-1||next[a[i]][0]==0)ans+=i*(n-i)+i-1;
		else ans+=i*(next[a[i]][p[a[i]]]-i-1)+i-1,p[a[i]]++;
	printf("%.5f",(double)(ans*2+n)/(double)(n*n));
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 1e6 + 10;
ll a[maxn], last[maxn], sum[maxn];

int main(){
	ll n;
	int i;
	scanf("%d",&n);
	memset(last,-1,sizeof last);
	ll ans = 0;
	sum[0] = 1;

	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		if(i==0){
			ans=1;
			last[a[0]] = 0;
			continue;
		}
		if(last[a[i]]==-1){
			sum[i] = sum[i-1] + i + 1;
		}else{
			sum[i] = sum[i-1] + i - last[a[i]];
		}
		ans+=sum[i];
		last[a[i]] = i;
		// printf("last[%d]: %d\n",a[i],last[a[i]]);
		//  printf("sum[%d]: %lld ans jd: %lld\n",i,sum[i],ans);
	}
	ans = ans*2 - n;
	printf("%.6lf\n", (double)ans/(double)(n*n));
	return 0;
};


#include <bits/stdc++.h>

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 1e6 + 10;
ll a[maxn], last[maxn], sum[maxn];

int main(){
	ll n;
	int i;
	scanf("%lld",&n);
	memset(last,-1,sizeof last);
	ll ans = 0;
	sum[0] = 1;

	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		if(i==0){
			ans=1;
			last[a[0]] = 0;
			continue;
		}
		if(last[a[i]]==-1){
			sum[i] = sum[i-1] + i + 1;
		}else{
			sum[i] = sum[i-1] + i - last[a[i]];
		}
		ans+=sum[i];
		last[a[i]] = i;
		// printf("last[%d]: %d\n",a[i],last[a[i]]);
		//  printf("sum[%d]: %lld ans jd: %lld\n",i,sum[i],ans);
	}
	ans = ans*2 - n;
	printf("%.6lf\n", (double)ans/(double)(n*n));
	return 0;
};


#include <bits/stdc++.h>

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 1e6 + 10;
ll a[maxn], last[maxn], sum[maxn];

int main(){
	ll n;
	int i;
	scanf("%d",&n);
	memset(last,-1,sizeof last);
	ll ans = 0;
	sum[0] = 1;
	last[a[0]] = 0;
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);

		if(last[a[i]]==-1){
			sum[i] = sum[i-1] + i + 1;
		}else{
			sum[i] = sum[i-1] + i - last[a[i]];
		}
		ans+=sum[i];
		last[a[i]] = i;
		// printf("last[%d]: %d\n",a[i],last[a[i]]);
		//  printf("sum[%d]: %lld ans jd: %lld\n",i,sum[i],ans);
	}
	ans = ans*2 - n;
	printf("%.6lf\n", (double)ans/(double)(n*n));
	return 0;
};


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <iomanip>
#define  ms(a,b) memset(a,b,sizeof(a))

using namespace std;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=1e6+5;
const int Mod=1e9+7;
int t[maxn],n,a;

int main()
{

    ios::sync_with_stdio(false);
    cin>>n;
    ms(t,0);
    ull ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        ull l=i-t[a],r=n-i+1;
        ans+=2*l*r-1;
        t[a]=i;
    }
    cout.setf(ios::fixed);
    cout<<setprecision(10)<<(double)ans/((double)n*n)<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <iomanip>
#define  ms(a,b) memset(a,b,sizeof(a))

using namespace std;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=1e6+5;
const int Mod=1e9+7;
namespace fastIO {
    #define BUF_SIZE 1000000
    //fread -> read
    bool IOerror = 0;
    inline char nc() {
        static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
        if(p1 == pend) {
            p1 = buf;
            pend = buf + fread(buf, 1, BUF_SIZE, stdin);
            if(pend == p1) {
                IOerror = 1;
                return -1;
            }
        }
        return *p1++;
    }
    inline bool blank(char ch) {
        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
    }
    inline void read(int &x) {
        char ch;
        while(blank(ch = nc()));
        if(IOerror)
            return;
        for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
    }
    #undef BUF_SIZE
};
using namespace fastIO;
int t[maxn],n,a;

int main()
{

    ios::sync_with_stdio(false);
    read(n);
    ms(t,0);
    ull ans=0;
    for(int i=1;i<=n;i++)
    {
        read(a);
        ull l=i-t[a],r=n-i+1;
        ans+=2*l*r-1;
        t[a]=i;
    }
    cout.setf(ios::fixed);
    cout<<setprecision(10)<<(double)ans/((double)n*n)<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <iomanip>
#define  ms(a,b) memset(a,b,sizeof(a))

using namespace std;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=1e6+5;
const int Mod=1e9+7;
int t[maxn],n,a;

int main()
{

    ios::sync_with_stdio(false);
    cin>>n;
    ms(t,0);
    ull ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        ull l=(i-1)-t[a]+1,r=n-i+1;
        ans+=2*l*r-1;
        t[a]++;
    }
    cout.setf(ios::fixed);
    cout<<setprecision(10)<<(double)ans/((double)n*n)<<endl;
    return 0;
}


#include <cstdio>
typedef long long int64;
static const int MAXN = 1e6 + 4;
static const int MAXA = 1e6 + 3;

int n, a[MAXN];
int last[MAXN];

int main()
{
    scanf("%d", &n);

    for (int i = 0; i < MAXA; ++i) last[i] = -1;
    int64 ans = 0;

    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        ans += (int64)(i - last[a[i]]) * (n - i);
        last[a[i]] = i;
    }

    ans = ans * 2 - n;
    printf("%.8lf\n", (double)ans / n / n);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1000006;
int a[N] , prev[N];

int main()
{
    int n;
    scanf("%d" , &n);
    long long nn = (long long)n * n;
    ++n;
    for(int i=1 ; i<n ; i++)
        scanf("%d" , &a[i]);
    long long res = 0;
    for(int i=1 ; i<n ; i++)
    {
        res += (long long)(i-prev[a[i]])*(n-i);
        prev[a[i]] = i;
    }
    cout << (double)(res+res-n+1) / nn;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1000006;
int a[N] , prev[N];

int main()
{
    int n;
    scanf("%d" , &n);
    int nn = n*n;
    ++n;
    for(int i=1 ; i<n ; i++)
        scanf("%d" , &a[i]);
    long long res = 0;
    for(int i=1 ; i<n ; i++)
    {
        res += (i-prev[a[i]])*(n-i);
        prev[a[i]] = i;
    }
    cout << (double)(res+res-n+1)/nn;
    return 0;
}


#include <cstdio>

const int MAXN = 1000005, MAXV = 1000000;
int N, lastPos[MAXN] = {0};
long long s[MAXN] = {0};

inline long long sqr(long long x) {return x * x;}

int main() {
	int x;
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", &x);
		s[i] += sqr(i - lastPos[x] - 1);
		lastPos[x] = i;
	}
	double ans = 0;
	for (int i = 1; i <= MAXV; ++i) {
		s[i] += sqr(N - lastPos[i]);
		ans += 1 - (double)s[i] / N / N;
	}
	printf("%.6f\n", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int a,amin=INT_MAX,amax;
long long n,sum,de;
vector<int> v[1000009];

int main(){
    scanf("%I64d",&n);
    de=n*n;
    for(int i=1;i<=n;i++){
        scanf("%d",&a);
        amin=min(a,amin);
        amax=max(a,amax);
        v[a].push_back(i);
    }
    for(int i=amin;i<=amax;i++){
        int si=v[i].size();
        if(si==0) continue;
        long long in=v[i][0];
        sum+=in*(n-in+1)*2-1;
        for(int j=1;j<si;j++){
            long long in1=v[i][j-1],in2=v[i][j];
            sum+=(in2-in1)*(n-in2+1)*2-1;
        }
    }
    printf("%lf",sum*1.0/de);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n,a,amin=INT_MAX,amax;
long long sum,de;
vector<int> v[1000009];

int main(){
    scanf("%d",&n);
    de=n*n;
    for(int i=1;i<=n;i++){
        scanf("%d",&a);
        amin=min(a,amin);
        amax=max(a,amax);
        v[a].push_back(i);
    }
    for(int i=amin;i<=amax;i++){
        int si=v[i].size();
        if(si==0) continue;
        long long in=v[i][0];
        sum+=in*(n-in+1)*2-1;
        for(int j=1;j<si;j++){
            long long in1=v[i][j-1],in2=v[i][j];
            sum+=(in2-in1)*(n-in2+1)*2-1;
        }
    }
    printf("%lf",sum*1.0/de);
    return 0;
}


//TEMPLATE BEGIN
//#define ONLINE_JUDGE
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>
//#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <functional>
#include <algorithm>
#include <complex>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
using namespace std;

#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); ++ (i))
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); -- (i))
#define FOREDGE(i, u, head, next) for (int (i) = (head[(u)]); (i); (i) = (next[(i)]))
#define FORSTL(it, A) for (__typeof((A).begin()) it = (A).begin(); it != (A).end(); ++ it)
#define CLR(a, b) memset((a), (b), sizeof (a))
#define CPY(a, b) memcpy((a), (b), sizeof (a))
#define DEBUG cerr << "debug" << endl
#define STAR cerr << "**********" << endl

#define RT return
#define BK break
#define CT continue
#define ALL(x) (x).begin(), (x).end()
#define HEAP priority_queue
#define st first
#define nd second
#define pf push_front
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define mp make_pair
#define re real()
#define im imag()

#define LIST0(A, n) {						\
	FOR (i, 0, n - 1) printf("%d ", A[i]);	\
	printf("\n");							\
}											\

#define LIST1(A, n) {						\
	FOR (i, 1, n) printf("%d ", A[i]);		\
	printf("\n");							\
}											\

#define SHOW0(A, n, m) {					\
	FOR (i, 0, n - 1) {						\
		FOR (j, 0, m - 1)					\
			printf("%d ", A[i][j]);			\
		printf("\n");						\
	}										\
}											\

#define SHOW1(A, n, m) {					\
	FOR (i, 1, n) {							\
		FOR (j, 1, m)						\
			printf("%d ", A[i][j]);			\
		printf("\n");						\
	}										\
}											\

typedef long long LL;
typedef double DB;
typedef long double LDB;
typedef unsigned int UINT;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<DB> VB;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef map<int, int> MII;
typedef map<LL, LL> MLL;
typedef map<int, string> MIS;
typedef map<string, int> MSI;

const int INF(0x3f3f3f3f);
const LL LINF(0x3f3f3f3f3f3f3f3fLL);
const DB DINF(1e20);
const DB EPS(1e-12); //adjustable
const DB PI(acos(-1.0));

inline DB cot(DB x) { RT 1.0 / tan(x); }
inline DB sec(DB x) { RT 1.0 / cos(x); }
inline DB csc(DB x) { RT 1.0 / sin(x); }

template<class T> inline T max(T a, T b, T c) { RT max(max(a, b), c); }
template<class T> inline T max(T a, T b, T c, T d) { RT max(max(a, b), max(c, d)); }
template<class T> inline T min(T a, T b, T c) { RT min(min(a, b), c); }
template<class T> inline T min(T a, T b, T c, T d) { RT min(min(a, b), min(c, d)); }

template<class T> inline void Scan(T& x) { //int, LL
    char c;
    for (c = getchar(); c <= ' '; c = getchar()) ;
    bool ngt(c == '-');
    if (ngt) c = getchar();
    for (x = 0; c > ' '; c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    if (ngt) x = -x;
}
template<class T> inline void Scan(T& x, T& y) { Scan(x), Scan(y); }
template<class T> inline void Scan(T& x, T& y, T& z) { Scan(x), Scan(y), Scan(z); }
//TEMPLATE END

const int N = 1000010;

int n, a[N], last[N];
LL dp[N];

void Main() {
	Scan(n);
	FOR (i, 1, n) Scan(a[i]);

	FOR (i, 1, n) {
		dp[i] = dp[i - 1] + i - last[a[i]];
		last[a[i]] = i;
	}

	//LIST1(dp, n);
	LL sum = 0;
	FOR (i, 1, n) sum += dp[i];
	printf("%lf\n", (DB)(2 * sum - n) / n / n);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	Main();
    RT 0;
}
//imagasaikou!


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> pos[1000005];
int main() {
    int n,hi=1000000;

    scanf("%d",&n);
    ll den = n;
    den = den * den;
    int i;
    for(i=1;i<=hi;i++)pos[i].push_back(0);
    int x;
    for(i=1; i<=n;i++)
    {
        scanf("%d",&x);
        pos[x].push_back(i);
    }
    for(i=1; i<=hi;i++)pos[i].push_back(n+1);
    ll num = 0;
    for(i=1; i<=hi; i++)
    {
        int l = pos[i].size();
        int j;
        ll total = den;
        ll rem = 0;
        for(j=1; j<l;j++)
        {
            int dif = pos[i][j] - pos[i][j-1]-1;
            rem += dif*(ll)dif;
        }
        num += total - rem;
    }
   // printf("%lld %lld\n",num,den);
    printf("%.8lf\n",num/(den*1.0));
    return 0;
}


// Codeforces Educational Round 28 F
#include <iostream>
#include <cstdio>
#include <memory.h>
using namespace std;

int a[1000100];
long long gsum;
int lpos[1000100];
int rpos[1000100];

long long count(int* arr, int size){
	if (size == 1){
		// gsum++;
		return 1;
	}

	int hf = size >> 1;
	long long lres = count(arr, hf);
	long long rres = count(arr + hf, size - hf);
	long long res = lres + rres;

	memset(lpos, 0xFF, sizeof(lpos));
	memset(rpos, 0xFF, sizeof(rpos));
	for (int i = hf - 1; i >= 0; i--){
		if (lpos[arr[i]] == -1)
			lpos[arr[i]] = i;
	}
	long long cur = lres;
	for (int i = hf; i <= size - 1; i++){
		if (rpos[arr[i]] != -1)
			res += cur;
		else {
			rpos[arr[i]] = i - hf;
			if (lpos[arr[i]] == -1){
				cur += hf;
				res += cur;
			}
			else {
				cur += hf - lpos[arr[i]] - 1;
				res += cur;
			}
		}
	}
	cur = rres;
	for (int i = hf - 1; i >= 0; i--){
		if (lpos[arr[i]] != i)
			res += cur;
		else {
			if (rpos[arr[i]] == -1){
				cur += (size - hf);
				res += cur;
			}
			else {
				cur += rpos[arr[i]];
				res += cur;
			}
		}
	}

	return res;
}

int main(){
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	long long res = count(a + 1, n);
	double expt = double(res) / (double(n) * n);

	printf("%.6f\n", expt);

	return 0;
}


// Codeforces Educational Round 28 F
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <map>
using namespace std;

int a[1000100];
long long gsum;
int lmap[1000100];
int rmap[1000100];

long long count(int* arr, int size, long long& lres, long long& rres){
	if (size == 1){
		lres = 1;
		rres = 1;
		return 1;
	}

	// map<int, int> lmap, rmap;
	memset(lmap, 0xFF, sizeof(lmap));
	memset(rmap, 0xFF, sizeof(rmap));
	int lcnt = 0, rcnt = 0;
	int hf = size >> 1;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] == -1){
			lmap[arr[i]] = i;
			lcnt++;
		}
	}
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] == -1){
			rmap[arr[i]] = i;
			rcnt++;
		}
	}
	long long llres, lrres, rlres, rrres;
	long long ltres = count(arr, hf, llres, lrres);
	long long rtres = count(arr + hf, size - hf, rlres, rrres);
	long long cur;
	lres = llres;
	cur = lcnt;
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] != i) lres += cur;
		else if (lmap[arr[i]] == -1){
			cur++;
			lres += cur;
		}
		else lres += cur;
	}
	rres = rrres;
	cur = rcnt;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] != i) rres += cur;
		else if (rmap[arr[i]] == -1){
			cur++;
			rres += cur;
		}
		else rres += cur;
	}
	long long res = ltres + rtres;
	cur = lrres;
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] != i) res += cur;
		else {
			if (lmap[arr[i]] == -1){
				cur += hf;
				res += cur;
			}
			else {
				cur += hf - lmap[arr[i]] - 1;
				res += cur;
			}
		}
	}
	cur = rlres;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] != i) res += cur;
		else {
			if (rmap[arr[i]] == -1){
				cur += (size - hf);
				res += cur;
			}
			else {
				cur += rmap[arr[i]] - hf;
				res += cur;
			}
		}
	}

	return res;
}

int main(){
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	long long lres, rres;
	long long res = count(a + 1, n, lres, rres);
	double expt = double(res) / (double(n) * n);

	printf("%.6f\n", expt);

	return 0;
}


// Codeforces Educational Round 28 F
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <map>
using namespace std;

int a[1000100];

int lmap[1000100];
int rmap[1000100];

long long count(int* arr, int size, long long& lres, long long& rres){
	if (size == 1){
		lres = 1;
		rres = 1;
		return 1;
	}

	// map<int, int> lmap, rmap;

	long long llres, lrres, rlres, rrres;
	long long ltres = count(arr, hf, llres, lrres);
	long long rtres = count(arr + hf, size - hf, rlres, rrres);

	memset(lmap, 0xFF, sizeof(lmap));
	memset(rmap, 0xFF, sizeof(rmap));
	int lcnt = 0, rcnt = 0;
	int hf = size >> 1;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] == -1){
			lmap[arr[i]] = i;
			lcnt++;
		}
	}
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] == -1){
			rmap[arr[i]] = i;
			rcnt++;
		}
	}

	long long cur;
	lres = llres;
	cur = lcnt;
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] != i) lres += cur;
		else if (lmap[arr[i]] == -1){
			cur++;
			lres += cur;
		}
		else lres += cur;
	}
	rres = rrres;
	cur = rcnt;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] != i) rres += cur;
		else if (rmap[arr[i]] == -1){
			cur++;
			rres += cur;
		}
		else rres += cur;
	}
	long long res = ltres + rtres;
	cur = lrres;
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] != i) res += cur;
		else {
			if (lmap[arr[i]] == -1){
				cur += hf;
				res += cur;
			}
			else {
				cur += hf - lmap[arr[i]] - 1;
				res += cur;
			}
		}
	}
	cur = rlres;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] != i) res += cur;
		else {
			if (rmap[arr[i]] == -1){
				cur += (size - hf);
				res += cur;
			}
			else {
				cur += rmap[arr[i]] - hf;
				res += cur;
			}
		}
	}

	return res;
}

int main(){
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	long long lres, rres;
	long long res = count(a + 1, n, lres, rres);
	double expt = double(res) / (double(n) * n);

	printf("%.6f\n", expt);

	return 0;
}


// Codeforces Educational Round 28 F
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <map>
using namespace std;

int a[1000100];

int lmap[1000100];
int rmap[1000100];

long long count(int* arr, int size, long long& lres, long long& rres){
	if (size == 1){
		lres = 1;
		rres = 1;
		return 1;
	}

	// map<int, int> lmap, rmap;
	int hf = size >> 1;
	long long llres, lrres, rlres, rrres;
	long long ltres = count(arr, hf, llres, lrres);
	long long rtres = count(arr + hf, size - hf, rlres, rrres);

	// memset(lmap, 0xFF, sizeof(lmap));
	// memset(rmap, 0xFF, sizeof(rmap));
	int lcnt = 0, rcnt = 0;

	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] == -1){
			lmap[arr[i]] = i;
			lcnt++;
		}
	}
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] == -1){
			rmap[arr[i]] = i;
			rcnt++;
		}
	}

	long long cur;
	lres = llres;
	cur = lcnt;
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] != i) lres += cur;
		else if (lmap[arr[i]] == -1){
			cur++;
			lres += cur;
		}
		else lres += cur;
	}
	rres = rrres;
	cur = rcnt;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] != i) rres += cur;
		else if (rmap[arr[i]] == -1){
			cur++;
			rres += cur;
		}
		else rres += cur;
	}
	long long res = ltres + rtres;
	cur = lrres;
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] != i) res += cur;
		else {
			if (lmap[arr[i]] == -1){
				cur += hf;
				res += cur;
			}
			else {
				cur += hf - lmap[arr[i]] - 1;
				res += cur;
			}
		}
	}
	cur = rlres;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] != i) res += cur;
		else {
			if (rmap[arr[i]] == -1){
				cur += (size - hf);
				res += cur;
			}
			else {
				cur += rmap[arr[i]] - hf;
				res += cur;
			}
		}
	}

	for (int i = hf - 1; i >= 0; i--) lmap[arr[i]] = -1;
	for (int i = hf; i <= size - 1; i++) rmap[arr[i]] = -1;

	return res;
}

int main(){
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	memset(lmap, 0xFF, sizeof(lmap));
	memset(rmap, 0xFF, sizeof(rmap));

	long long lres, rres;
	long long res = count(a + 1, n, lres, rres);
	double expt = double(res) / (double(n) * n);

	printf("%.6f\n", expt);

	return 0;
}


// Codeforces Educational Round 28 F
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <map>
using namespace std;

int a[1000100];

int lmap[1000100];
int rmap[1000100];

long long count(int* arr, int size, long long& lres, long long& rres){
	if (size == 1){
		lres = 1;
		rres = 1;
		return 1;
	}

	// map<int, int> lmap, rmap;
	int hf = size >> 1;
	long long llres, lrres, rlres, rrres;
	long long ltres = count(arr, hf, llres, lrres);
	long long rtres = count(arr + hf, size - hf, rlres, rrres);

	memset(lmap, 0xFF, sizeof(lmap));
	memset(rmap, 0xFF, sizeof(rmap));
	int lcnt = 0, rcnt = 0;

	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] == -1){
			lmap[arr[i]] = i;
			lcnt++;
		}
	}
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] == -1){
			rmap[arr[i]] = i;
			rcnt++;
		}
	}

	long long cur;
	lres = llres;
	cur = lcnt;
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] != i) lres += cur;
		else if (lmap[arr[i]] == -1){
			cur++;
			lres += cur;
		}
		else lres += cur;
	}
	rres = rrres;
	cur = rcnt;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] != i) rres += cur;
		else if (rmap[arr[i]] == -1){
			cur++;
			rres += cur;
		}
		else rres += cur;
	}
	long long res = ltres + rtres;
	cur = lrres;
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] != i) res += cur;
		else {
			if (lmap[arr[i]] == -1){
				cur += hf;
				res += cur;
			}
			else {
				cur += hf - lmap[arr[i]] - 1;
				res += cur;
			}
		}
	}
	cur = rlres;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] != i) res += cur;
		else {
			if (rmap[arr[i]] == -1){
				cur += (size - hf);
				res += cur;
			}
			else {
				cur += rmap[arr[i]] - hf;
				res += cur;
			}
		}
	}

	return res;
}

int main(){
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	long long lres, rres;
	long long res = count(a + 1, n, lres, rres);
	double expt = double(res) / (double(n) * n);

	printf("%.6f\n", expt);

	return 0;
}


// Codeforces Educational Round 28 F
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <map>
using namespace std;

int a[1000100];
long long gsum;
int lpos[1000100];
int rpos[1000100];

long long count(int* arr, int size, long long& lres, long long& rres){
	if (size == 1){
		lres = 1;
		rres = 1;
		return 1;
	}

	map<int, int> lmap, rmap;
	int lcnt = 0, rcnt = 0;
	int hf = size >> 1;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap.find(arr[i]) == lmap.end()){
			lmap[arr[i]] = i;
			lcnt++;
		}
	}
	for (int i = hf; i <= size - 1; i++){
		if (rmap.find(arr[i]) == rmap.end()){
			rmap[arr[i]] = i;
			rcnt++;
		}
	}
	long long llres, lrres, rlres, rrres;
	long long ltres = count(arr, hf, llres, lrres);
	long long rtres = count(arr + hf, size - hf, rlres, rrres);
	long long cur;
	lres = llres;
	cur = lcnt;
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] != i) lres += cur;
		else if (lmap.find(arr[i]) == lmap.end()){
			cur++;
			lres += cur;
		}
		else lres += cur;
	}
	rres = rrres;
	cur = rcnt;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] != i) rres += cur;
		else if (rmap.find(arr[i]) == rmap.end()){
			cur++;
			rres += cur;
		}
		else rres += cur;
	}
	long long res = ltres + rtres;
	cur = lrres;
	for (int i = hf; i <= size - 1; i++){
		if (rmap[arr[i]] != i) res += cur;
		else {
			if (lmap.find(arr[i]) == lmap.end()){
				cur += hf;
				res += cur;
			}
			else {
				cur += hf - lmap[arr[i]] - 1;
				res += cur;
			}
		}
	}
	cur = rlres;
	for (int i = hf - 1; i >= 0; i--){
		if (lmap[arr[i]] != i) res += cur;
		else {
			if (rmap.find(arr[i]) == rmap.end()){
				cur += (size - hf);
				res += cur;
			}
			else {
				cur += rmap[arr[i]] - hf;
				res += cur;
			}
		}
	}

	return res;
}

int main(){
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	long long lres, rres;
	long long res = count(a + 1, n, lres, rres);
	double expt = double(res) / (double(n) * n);

	printf("%.6f\n", expt);

	return 0;
}


/*
给定一个长度为n的序列，随机选择两个数l,r，若l>r，则交换他们。
求出[l,r]不同元素个数的期望值。
n<=10^6
*/
#include<bits/stdc++.h>
using namespace std;

const int maxn = 1000009;
int n, a[maxn], last[maxn];
long double ans;
long long sum;

int main(){
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%d", &a[i]);
	ans = 1.0 / n;
	for (int i=1; i<=n; i++){
		sum += i - last[a[i]] - 1;
		ans += 2.0 * sum / n / n;
		last[a[i]] = i; sum++;
	}
	printf("%.12lf\n", double(ans));
	return 0;
}


#include<bits/stdc++.h>
#define N 1000005
#define int long long
using namespace std;

int n,a[N],f[4*N],lazy[4*N], pos[N], l[N];
int INF=1e9+7;

void dolazy(int k,int l,int r){
	if (lazy[k]==0) return;
	f[k] += lazy[k]*(r-l+1);
	if (l!=r){
		lazy[2*k] += lazy[k];
		lazy[2*k+1] += lazy[k];
	}
	lazy[k]=0;
}
void up(int k,int l,int r,int L,int R,int val){
	dolazy(k,l,r);
	if (l > R || L > r) return ;
	if (L <= l && r <= R){
	    f[k] += val*(r-l+1);
		if (l!=r){
    		lazy[2*k] += val;
    		lazy[2*k+1] += val;
	    }
		return;
	}
	int mid=(l+r)/2;
	up(2*k,l,mid,L,R,val);
	up(2*k+1,mid+1,r,L,R,val);
	f[k] = f[2*k] + f[2*k+1];
}

int gett(int k,int l,int r,int L,int R){
	dolazy(k,l,r);
	if (l > R || L > r) return 0;
	if (L <= l && r <= R) return f[k];
	int mid=(l+r)/2;
	return (gett(2*k,l,mid,L,R)+gett(2*k+1,mid+1,r,L,R));
}

main(){
    ios_base::sync_with_stdio(0);
    cout << fixed << setprecision(9);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        l[i] = pos[a[i]];
        pos[a[i]] = i;
    }
    double ans = 0;
    for(int i = 1; i <= n; i++){
        up(1,1,n,i,i,1);
        if(l[i] == i-1){
            ans += 1;
            continue;
        }
        up(1,1,n,l[i]+1,i-1,1);
        ans += gett(1,1,n,l[i]+1,i-1) + gett(1,1,n,1,l[i]);
    }
    //cout << ans << endl;
    cout << (long double) (ans * 2.0 / (n * n)) ;
}


#include<bits/stdc++.h>
#define N 1000005
#define int long long
using namespace std;

int n,a[N],f[4*N],lazy[4*N], pos[N], l[N];

void dolazy(int k,int l,int r){
	if (lazy[k]==0) return;
	f[k] += lazy[k]*(r-l+1);
	if (l!=r){
		lazy[2*k] += lazy[k];
		lazy[2*k+1] += lazy[k];
	}
	lazy[k]=0;
}
void up(int k,int l,int r,int L,int R,int val){
	dolazy(k,l,r);
	if (l > R || L > r) return ;
	if (L <= l && r <= R){
	    f[k] += val*(r-l+1);
		if (l!=r){
    		lazy[2*k] += val;
    		lazy[2*k+1] += val;
	    }
		return;
	}
	int mid=(l+r)/2;
	up(2*k,l,mid,L,R,val);
	up(2*k+1,mid+1,r,L,R,val);
	f[k] = f[2*k] + f[2*k+1];
}

int gett(int k,int l,int r,int L,int R){
	dolazy(k,l,r);
	if (l > R || L > r) return 0;
	if (L <= l && r <= R) return f[k];
	int mid=(l+r)/2;
	return (gett(2*k,l,mid,L,R)+gett(2*k+1,mid+1,r,L,R));
}

main(){
    ios_base::sync_with_stdio(0);
    cout << fixed << setprecision(5);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        l[i] = pos[a[i]];
        pos[a[i]] = i;
    }
    long double ans = 0;
    int  t = 0;
    for(int i = 1; i <= n; i++){
        up(1,1,n,i,i,1);
        up(1,1,n,l[i]+1,i-1,1);
        ans += gett(1,1,n,l[i]+1,i-1) + gett(1,1,n,1,l[i]);
    }
    //cout << ans << endl;
    cout << (long double) ( (ans * 2.0+n) / (n * n)) ;
}


#include<bits/stdc++.h>
#define N 1000005
#define int long long
using namespace std;

int n, a[N], pos[N], l[N];

main(){
    ios_base::sync_with_stdio(0);
    cout << fixed << setprecision(5);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        l[i] = pos[a[i]];
        pos[a[i]] = i;
    }
    long double ans = 0;
    int t = 0;
    for(int i = 1; i <= n; i++){
        t += i-l[i];
        ans += t-1;
    }
    cout << (long double) ( (ans * 2.0+n) / (n * n)) ;
}


#include<bits/stdc++.h>
#define N 1000005
#define int long long
using namespace std;

int n,a[N],f[4*N],lazy[4*N], pos[N], l[N];

void dolazy(int k,int l,int r){
	if (lazy[k]==0) return;
	f[k] += lazy[k]*(r-l+1);
	if (l!=r){
		lazy[2*k] += lazy[k];
		lazy[2*k+1] += lazy[k];
	}
	lazy[k]=0;
}
void up(int k,int l,int r,int L,int R,int val){
	dolazy(k,l,r);
	if (l > R || L > r) return ;
	if (L <= l && r <= R){
	    f[k] += val*(r-l+1);
		if (l!=r){
    		lazy[2*k] += val;
    		lazy[2*k+1] += val;
	    }
		return;
	}
	int mid=(l+r)/2;
	up(2*k,l,mid,L,R,val);
	up(2*k+1,mid+1,r,L,R,val);
	f[k] = f[2*k] + f[2*k+1];
}

int gett(int k,int l,int r,int L,int R){
	dolazy(k,l,r);
	if (l > R || L > r) return 0;
	if (L <= l && r <= R) return f[k];
	int mid=(l+r)/2;
	return (gett(2*k,l,mid,L,R)+gett(2*k+1,mid+1,r,L,R));
}

main(){
    ios_base::sync_with_stdio(0);
    cout << fixed << setprecision(5);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        l[i] = pos[a[i]];
        pos[a[i]] = i;
    }
    long double ans = 0;
    for(int i = 1; i <= n; i++){
        up(1,1,n,i,i,1);
        if(l[i] == i-1){ ans += 1 + gett(1,1,n,1,l[i]); continue; }
        up(1,1,n,l[i]+1,i-1,1);
        ans += gett(1,1,n,l[i]+1,i-1) + gett(1,1,n,1,l[i]);
    }
    //cout << ans << endl;
    cout << (long double) ( (ans * 2.0-n) / (n * n)) ;
}


//Author: Lixiang
#include<stdio.h>
const int maxn=1000001;
struct F{
	long long N;
	double sum;
	int last[maxn];
	void init(){
		int t;
		scanf("%I64d",&N);
		for(long long i=1;i<=N;i++){
			scanf("%d",&t);
			sum+=(i-last[t])*(N-i+1);
			last[t]=i;
		}
	}
	void work(){
		sum=(sum-N)*2+N;
		double now=N*N;
		sum/=now;
		printf("%.6lf\n",sum);
	}
}sol;
int main(){
	sol.init();
	sol.work();
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define N 300100
#define M 510
#define MOD 1000000007
#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define X first
#define Y second
using namespace std;
int pre[N];
int main(){
	int n;
	scanf("%d",&n);
	LL s = 0;
	double ans = 0;
	FOR(i,1,n){
		int x;
		scanf("%d",&x);
		s += i - pre[x];
		pre[x] = i;
		ans += 2 * s - 1;
	}
	printf("%.9lf\n",ans / n / n);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define N 1000100
#define M 510
#define MOD 1000000007
#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define X first
#define Y second
using namespace std;
int pre[N];
int main(){
	int n;
	scanf("%d",&n);
	LL s = 0;
	double ans = 0;
	FOR(i,1,n){
		int x;
		scanf("%d",&x);
		s += i - pre[x];
		pre[x] = i;
		ans += 2 * s - 1;
	}
	printf("%.9lf\n",ans / n / n);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
const double EPS = 1e-9;
const int INF = 1 << 29;
#define mp make_pair
#define el putchar('\n')
#define sp putchar(' ')
#define Fill(a,val) memset(a,val,sizeof a)
#define all(a) a.begin(),a.end()
#ifndef ONLINE_JUDGE
#define tr(a, it) for (decltype(a.begin()) it = a.begin(); it != a.end(); ++it)
#else
#define tr(a, it) for (typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#endif
#define in(n) scanf("%d",&n)
#define inl(n) scanf("%I64d",&n)
#define out(n) printf("%d",n);
#define outl(n) printf("%I64d",n);

int const NN = 1e6 + 6;
int a[NN];
int pos[NN];
int prv[NN];

int main(){
	int n; in(n);
	for (int i = 1; i <= n; ++i){
		in(a[i]);
		pos[i] = prv[a[i]];
		prv[a[i]] = i;
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i){
		int L = pos[i] + 1;
		int R = n;
		ll cnt = (i - L + 1ll) * 1ll * (R - i + 1ll);
		cnt = cnt * 2ll; --cnt;
		ans += cnt;
	}
	double answer = ans * 1.0 / ll(n) / ll(n) * 1.0;
	printf("%.12lf\n", answer);
	return 0;
}


#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int N=1000000;
int n,a[N+5];
int mas[N+5];
double ans;
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for (int i=1;i<=N;i++)
        mas[i]=n+1;
    for (int i=n;i>0;i--){
        ans+=(mas[a[i]]-i)*i*2-1;
        mas[a[i]]=i;
    }
    double x=n*n;
    ans/=x;
    printf("%.6f",ans);
    return 0;
}


#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
using namespace std;
const ll N=1000000;
ll n,a[N+5];
ll mas[N+5];
double ans;
int main()
{
    cin>>n;
    for (ll i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for (ll i=1;i<=N;i++)
        mas[i]=n+1;
    for (ll i=n;i>0;i--){
        ans+=(mas[a[i]]-i)*i*2-1;
        mas[a[i]]=i;
    }
    double x=n*n;
    ans/=x;
    printf("%.6f",ans);
    return 0;
}


#include<vector>
#include<stdio.h>
#include<algorithm>
using namespace std;
#define ll long long
vector<int>q[1000005];
ll n,a[1000005],b[1000005],ans;
int main(void)
{
	scanf("%lld",&n);
	for(int i=1;i<=1000000;i++)
		q[i].push_back(0);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		q[a[i]].push_back(i);
		b[a[i]]=1;
	}
	for(int i=1;i<=1000000;i++)
		q[i].push_back(n+1);
	for(int i=0;i<=1000000;i++)
	{
		if(b[i]==0) continue;
		ans+=n*n;
		for(int j=1;j<q[i].size();j++)
			ans-=(ll)(q[i][j]-q[i][j-1]-1)*(q[i][j]-q[i][j-1]-1);
	}
	printf("%.10f\n",1.0*ans/n/n);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define maxn 100005
#define inf (1ll<<60)-1
vector<pair<int,int> > q[maxn];
ll a[maxn],b[maxn],dp[maxn];
void dfs(int u)
{
	dp[u]=b[u]-a[u];
	for(int i=0;i<q[u].size();i++)
	{
		int v=q[u][i].first;
		int val=q[u][i].second;
		dfs(v);
		if(dp[v]<0)
		{
			if(-dp[v]<inf/val)
				dp[u]+=dp[v]*val;
			else
				dp[u]=-inf;
			if(dp[u]<-inf)
				dp[u]=-inf;
		}
		else
			dp[u]+=dp[v];
	}
}
int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&b[i]);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=2;i<=n;i++)
	{
		int x,k;
		scanf("%d%d",&x,&k);
		q[x].push_back(make_pair(i,k));
	}
	dfs(1);
	if(dp[1]>=0)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include <cstdio>
#include <cstring>
#define ll long long
#define MAXN 1000000
using namespace std;

ll n,x;
ll ans = 0;
ll pre[MAXN+5];
ll last[MAXN+5];

void isi() {
  memset(pre, 0, sizeof pre);
  for (ll i=1; i<=MAXN; i++) {
    pre[i] = i + pre[i-1];
  }
  for (ll i=1; i<=MAXN; i++) {
    pre[i] += pre[i-1];
  }
  for (ll i=1; i<=MAXN; i++) {
    pre[i] = pre[i] * 2 - i;
  }
}

int main() {
  memset(last, -1, sizeof last);
  isi();
  scanf("%I64d", &n);
  ans = pre[n];

  for (ll i=1; i<=n; i++) {
    scanf("%I64d",&x);
    if (last[x] != -1) {
      ans -= 2 * (n - i + 1) * (last[x]);
    }
    last[x] = i;
  }

  printf("%.6lf\n", (double) ans / n / n);
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <list>
#include <queue>
#include <bitset>
#include <complex>
#include <deque>
#include <climits>
#include <cassert>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <cctype>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
typedef long long ll;
typedef double db;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
const db PI = acos(-1.0);
const ll inf = 0xf0000000;
const ll mod = 1e9 + 7;
const int maxn = 1000;
//freopen("test.out", "w", stdout);
//std::ios::sync_with_stdio(false);
int a[1000005];
int main()
{
    int n,x;
    double ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        ans+=(i-a[x])*(n-i+1)*2-1;
        a[x]=i;
        //cout<<ans<<endl;
    }
    ans=ans/(double)(n*n);
    printf("%.6lf\n",ans);

    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <list>
#include <queue>
#include <bitset>
#include <complex>
#include <deque>
#include <climits>
#include <cassert>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <cctype>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
typedef long long ll;
typedef double db;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
const db PI = acos(-1.0);
const ll inf = 0xf0000000;
const ll mod = 1e9 + 7;
const int maxn = 1000;
//freopen("test.out", "w", stdout);
//std::ios::sync_with_stdio(false);
int a[1000005];
int main()
{
    ll n;
    int x;
    ll ans=0;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        ans+=(i-a[x])*(n-i+1)*2-1;
        a[x]=i;
    }
    double ans1=(double)ans/(ll)(n*n);
    printf("%.6lf\n",ans1);

    return 0;
}


#include<bits/stdc++.h>
#define MX 1000005
using namespace std;
typedef long long ll;

ll ara[MX], pos[MX];

ll func(ll n){
    return (n*(n+1))/2;
}

int main(){
    ll i, j, k;
    ll n, sm;
    scanf("%lld", &n);
    for(i=0; i<n; ++i) scanf("%lld", &ara[i]);
    for(i=0; i<MX; ++i) pos[i]=-1;
    for(i=0, sm=0; i<n; ++i) sm+=func(i+1)+func(n-i)-1;
    for(i=0; i<n; ++i){
        if(pos[ara[i]]!=-1) sm-=2LL*(pos[ara[i]]+1)*(n-i);
        pos[ara[i]]=i;
    }
    double ans=(double)sm/(double)(n*n);
    printf("%0.8lf\n", ans);
}


#include<bits/stdc++.h>

using namespace std;

const int maxn = 1000010;

int nxt[maxn], vis[maxn];

int a[maxn], n, tot;

long long sum, ans;

int main() {

  cin >> n;

  for( int i = 1; i <= n; i ++ ) cin >> a[i];

  for( int i = 1; i <= n; i ++ ) {

    if( vis[a[i]] ) nxt[vis[a[i]]] = i;

    else {

      sum += i;

      tot++;

    }

    vis[a[i]] = i;

  }

  ans += 1ll * ( n + 1 ) * tot - sum;

  for( int i = 1; i < n; i ++ ) {

    tot--;

    sum -= i;

    if( nxt[i] ) {

      tot++;

      sum += nxt[i];

    }

    ans += 1ll * ( n + 1 ) * tot - sum;

  }

  ans *= 2;

  ans -= n;

  printf("%.12lf\n", ans / ( 1.0 * n * n ) );

  return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define mp make_pair

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

inline void gn(long long&x){

	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');

	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;

}

inline void gn(int&x){long long t;gn(t);x=t;}

inline void gn(unsigned long long&x){long long t;gn(t);x=t;}

inline void gn(double&x){double t;scanf("%lf",&t);x=t;}

inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)

    #define lld "%I64d"

#else

    #define lld "%lld"

#endif

struct Bigint {

	static const int LEN = 50;

	static const int BLEN = 30;

	static const int BIGMOD = 1<<BLEN;

	static const INT BIGMOD1 = 1LL<<(BLEN<<1);

	static const int bmod=BIGMOD-1;

	static const INT bmod1=BIGMOD1-1;

	int s, vl, v[LEN];

	void pb(int x) {v[vl ++] = x;}

	int len() const {return vl;}

	bool empty() const { return len() == 0 ; }

	void pop_back() {vl --;}

	int back() const {return v[vl - 1];}

	void n() {while (!empty() && !back()) pop_back(); if (empty()) s=1;}

	void resize(int nl) {vl = nl;memset(v, 0, sizeof(int) * (nl + 1));}

	Bigint() : s(1) {vl = 0;}

	Bigint(long long a) {

		s = 1; vl = 0;

		if (a < 0) {s = -1; a = -a;}

		while (a) {

			pb(a & bmod);

			a >>= BLEN;

		}

		n();

	}

	Bigint(string str) {

		s = 1; vl = 0;

		int stPos = 0, num = 0;

		if (!str.empty() && str[0] == '-') {

			s = -1; stPos=1;

		}

		vector<int> vp;

		int tmod=(int)1e8;

		for (int i = str.size() - 1, q = 1; i >= stPos; i --) {

			num += (str[i] - '0') * q;

			if ((q*=10) >= tmod) {

				vp.pb(num);

				num = 0; q = 1;

			}

		}

		if (num) vp.pb(num);

		while (!vp.empty()) {

			INT r=0;

			for (int i=vp.size()-1; i>=0; i--) {

				r=r*tmod+vp[i];

				vp[i]=r>>BLEN; r&=bmod;

			}

			while (!vp.empty() && !vp.back()) vp.pop_back();

			pb(r);

		}

		n();

	}

	void print() const {

		if (empty()) {puts("0");return ;}

		int c=back(), la=1;

		printf("%o", c);

		for (int i = len() - 2; i >= 0; i --) printf("%.10o", v[i]); putchar('\n');

	}

	void print10() const {

		if (empty()) {puts("0");return ;}

		VI vp(1, 0), tp;

		if (s==-1) putchar('-');

		int tmod=(int)1e9;

		for (int i=len()-1; i>=0; i--) {

			INT r=0;

			tp=vp; vp.clear(); vp.resize(tp.size(), 0);

			for (int j=0; j<tp.size(); j++) {

				r=(INT)tp[j]*BIGMOD+vp[j];

				vp[j]=r%tmod; r/=tmod;

				for (int k=j+1; r; k++) {

					if (k==vp.size()) vp.pb(0);

					r+=vp[k];

					vp[k]=r%tmod; r/=tmod;

				}

			}

			r=v[i];

			for (int j=0; j<vp.size() && r; j++) {

				r+=vp[j]; vp[j]=r%tmod; r/=tmod;

			}

			if (r) vp.pb(r);

		}

		int c=vp.back();

		printf("%d", c);

		for (int i=vp.size()-2; i>=0; i--) printf("%.9d", vp[i]);puts("");

	}

	int cp3(const Bigint &b) const {

		if (s != b.s) return s - b.s;

		if (s == -1) return -(-*this).cp3(-b);

		if (len() != b.len()) return len() - b.len();

		for (int i = len() - 1; i >= 0; i --)

			if (v[i] != b.v[i]) return v[i] - b.v[i];

		return 0;

	}

	bool operator < (const Bigint &b) const { return cp3(b) < 0; }

	bool operator <= (const Bigint &b) const { return cp3(b) <= 0; }

	bool operator == (const Bigint &b) const { return cp3(b) == 0; }

	bool operator != (const Bigint &b) const { return cp3(b) != 0; }

	bool operator > (const Bigint &b) const { return cp3(b) > 0; }

	bool operator >= (const Bigint &b) const { return cp3(b) >= 0; }

	Bigint operator - () const {

		Bigint r = (*this);

		r.s = -r.s;

		if (r.len()==0) r.s=1;

		return r;

	}

	Bigint operator + (const Bigint &b) const {

		if (s == -1) return -(-(*this) + (-b));

		if (b.s == -1) return (*this) - (-b);

		Bigint r;

		int nl = max(len(), b.len());

		r.resize(nl + 1);

		for (int i = 0; i < nl; i ++) {

			if (i < len()) r.v[i] += v[i];

			if (i < b.len()) r.v[i] += b.v[i];

			if (r.v[i] >= BIGMOD) {

				r.v[i+1]++, r.v[i]&=bmod;

			}

		}

		r.n();

		return r;

	}

	Bigint operator - (const Bigint &b) const {

		if (s == -1) return -(-(*this) - (-b));

		if (b.s == -1) return (*this) + (-b);

		if ((*this) < b) return -(b - (*this));

		Bigint r;

		r.resize(len());

		for (int i = 0; i < len(); i ++) {

			r.v[i] += v[i];

			if (i < b.len()) r.v[i] -= b.v[i];

			if (r.v[i] < 0) {

				r.v[i] += BIGMOD ;

				r.v[i + 1] --;

			}

		}

		r.n();

		return r;

	}

	Bigint operator * (const Bigint &b) {

		Bigint r;

		r.resize(len() + b.len() + 1);

		r.s = s * b.s;

		INT c=0, up=0;

		for (int i=0; i<r.len(); i++) {

			c=up; up=0;

			for (int j=max(0, i-b.len()+1); j<len() && j<=i; j++) {

				c+=(INT)v[j]*b.v[i-j];

				if (c>=BIGMOD1) {

					up+=c>>BLEN; c&=bmod;

				}

			}

			up+=c>>BLEN; c&=bmod;

			r.v[i]=c;

		}

		r.n();

		return r;

	}

	Bigint operator / (const Bigint &b) {

		if (len()<b.len()) return 0;

		Bigint r;

		r.resize(max(1, len() - b.len() + 1));

		int oriS = s;

		Bigint b2 = b;

		Bigint a2 = *this, a3;

		a2.s = b2.s = r.s = 1;

		for (int i = r.len() - 1; i >= 0; i --) {

			INT d = 0, u = bmod;

			a3=a2>>(i*30);

			if (a3.len()>b2.len()) {

				INT r=((INT)a3.back()<<BLEN)+a3.v[a3.len()-2];

				u=r/b2.back()+1;

			} else if (a3.len()==b2.len() && b2.len()>1) {

				INT r=((INT)a3.back()<<BLEN)+a3.v[a3.len()-2];

				u=r/(((INT)b2.back()<<BLEN)+b2.v[b2.len()-2])+1;

			} else if (a3.len()==b2.len() && b2.len()==1) {

				u=a3.back()/b2.back()+1;

			}

			while (d < u) {

				INT m = (d + u + 1) >> 1;

				r.v[i] = m;

				if (((b2 * m)) > a3) u = m - 1;

				else d = m;

			}

			r.v[i] = d;

			a2=a2-((b2*d)<<i*30);

			a2.n();

		}

		s = oriS;

		r.s = s * b.s;

		r.n();

		return r;

	}

	Bigint operator % (const Bigint &b) {

		return (*this) - (*this) / b * b;

	}

	int len1() {

		return 32-__builtin_clz(back())+(len()-1)*30;

	}

	Bigint operator << (const int &u) {

		if (u==0) return *this;

		Bigint r;

		r.resize((len1()+u+29)/30);

		for (int V=u%30, i=r.len()-1, t=u/30; i>=t; i--) {

			r.v[i]=((i-t<len()?(INT)v[i-t]<<V:0)|(i-t?v[i-t-1]>>30-V:0))&bmod;

		}

		r.n();

		return r;

	}

	Bigint operator >> (const int &u) {

		int nn=len1();

		if (nn<=u) return 0;

		Bigint r; r.resize((nn-u+29)/30);

		for (int V=u%30, c=(1<<V)-1, i=u/30, j=0; j<r.len(); i++, j++) {

			r.v[j]=(v[i]>>V)|(i<len()-1?(v[i+1]&c)<<30-V:0);

		}

		r.n();

		return r;

	}

} ;

Bigint _INF=Bigint(INF)*Bigint(INF)*Bigint(INF)*Bigint(INF)*Bigint(-1LL);

#define MM 1000010

int a[MM], pre[MM], u, N;

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.txt", "r", stdin);

	int _time=clock();

#endif

	gn(N);

	for(int i=1; i<=N; i++) {

		gn(u); pre[i]=a[u]; a[u]=i;

	}

	INT ans=0;

	for(int i=1; i<=N; i++) {

		ans+=1LL*(i-pre[i])*(N-i+1)*2-1;

	}

	printf("%.10f\n", 1.0*ans/(1.0*N*N));

#ifndef ONLINE_JUDGE

	cerr<<endl<<"time:"<<(int)(clock()-_time)<<endl;

#endif

	return 0;

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-9

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(_) ((_)*(_))

#define cb(_) ((_)*(_)*(_))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bclzl(x) (__builtin_clzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template<class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1), gn(x2), gn(x3);}

template<class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1), gn(x2), gn(x3), gn(x4);}

template<class T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T> inline void printsp(T x) {print(x); putchar(' ');}

template<class T> inline void println(T x) {print(x); putchar('\n');}

template<class T1, class T2> inline void print(T1 x1, T2 x2){printsp(x1), println(x2);}

template<class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3){printsp(x1), printsp(x2), println(x3);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#ifndef ONLINE_JUDGE

void debug() {cout << endl;}

template<typename T, typename... Args>void debug(T&& head, Args&&... tail) {cout << head << ' ';debug(tail...);}

#endif

#define NN 1000010

int pre[NN], id[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n, x;

	gn(n);

	for(int i=1; i<=n; i++) {

		gn(x);

		pre[i]=id[x];

		id[x]=i;

	}

	INT num=0;

	for(int i=1; i<=n; i++) num+=2LL*(i-pre[i])*(n-i+1)-1;

	printf("%.7lf\n", 1.*num/n/n);

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define mp make_pair

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x);putchar(' ');}

template<class T>inline void println(T x) {print(x);putchar('\n');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 1000010

int a[NN];

int vst[NN];

int nxt[NN], pre[NN];

int main(){

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

#endif

	int n;

	cin>>n;

	for (int i=1; i<=n; i++) gn(a[i]);

	for (int i=1; i<=n; i++) pre[i]=0, nxt[i]=n+1;

	for (int i=1; i<=n; i++) {

		if (vst[a[i]]) pre[i]=vst[a[i]];

		vst[a[i]]=i;

	}

	memset(vst, 0, sizeof(vst));

	for (int i=n; i>=1; i--) {

		if (vst[a[i]]) nxt[i]=vst[a[i]];

		vst[a[i]]=i;

	}

	INT ans=0;

	for (int i=1; i<=n; i++) {

		int l1=n-i;

		int l2=i-pre[i]-1;

		int l=n-pre[i];

		ans+=1ll*l*l-1ll*l1*l1-1ll*l2*l2;

	}

	printf("%.10lf\n", 1.0*ans/n/n);

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define rands(n) (rand()%n+1)

#define rand0(n) (rands(n)-1)

#define Rands(n) ((INT)rand()*rand()%n+1)

#define Rand0(n) (Rands(n)-1)

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)

    #define lld "%I64d"

#else

    #define lld "%lld"

#endif

#define NN 1000111

int a[NN];

int pos[NN];

int pre[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

	int _time=clock();

#endif

	int n;

	cin >> n;

	for(int i=1; i<=n; i++) {

		scanf("%d", a+i);

		pre[i] = pos[a[i]];

		pos[a[i]] = i;

	}

	DO ans=0;

	for(int i=1; i<=n; i++) {

		ans += (DO)(i - pre[i])*(n-i+1)*2;

		ans --;

	}

	printf("%.10lf\n", ans/n/n);

#ifndef ONLINE_JUDGE

	cerr<<(int)(clock()-_time)<<endl;

#endif

	return 0;

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-9

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(_) ((_)*(_))

#define cb(_) ((_)*(_)*(_))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bclzl(x) (__builtin_clzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template<class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1), gn(x2), gn(x3);}

template<class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1), gn(x2), gn(x3), gn(x4);}

template<class T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T> inline void printsp(T x) {print(x); putchar(' ');}

template<class T> inline void println(T x) {print(x); putchar('\n');}

template<class T1, class T2> inline void print(T1 x1, T2 x2){printsp(x1), println(x2);}

template<class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3){printsp(x1), printsp(x2), println(x3);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#ifndef ONLINE_JUDGE

void debug() {cout << endl;}

template<typename T, typename... Args>void debug(T&& head, Args&&... tail) {cout << head << ' ';debug(tail...);}

#endif

#define NN 1000010

int a[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n;

	gn(n);

	for(int i=0; i<n; i++) gn(a[i]);

	sort(a, a+n);

	int nn=unique(a, a+n)-a;

	INT k=1LL*n*n;

	INT x=1LL*nn*(nn+1);

	if(nn==1) puts("1.000000");

	else printf("%.7lf\n", 1.*x/k);

	return 0;

}


/*
 * test.cpp
 *
 *
 *      Author: Fireworks
 */

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<cmath>
#include<bitset>
#include<set>
#include<iomanip>
#include<fstream>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<list>
#include<sstream>

using namespace std;

typedef pair<int,int> ii;
typedef pair<int,long long> il;
typedef pair<long long,long long> ll;
typedef pair<ll,int> lli;
typedef pair<long long,int> li;
typedef pair<double,double> dd;
typedef pair<ii,int> iii;
typedef pair<double,int> di;
long long mod = 1000000007LL;
long long base = 37;
long long large = 1000000000000000000LL;

int main(){

	int n;
	cin>>n;
	vector<int> a(n,0);
	for(int i=0;i<n;i++) cin>>a[i];
	vector<int> last(1000010,-1);
	long long sum = 0;
	long long acc = 0;
	for(int i=0;i<n;i++){
		sum+=i-last[a[i]];
		acc+=sum;
		last[a[i]] = i;
	}
	acc-=n;
	acc*=2;
	acc+=n;

	cout<<setprecision(10)<<fixed<<(long double)acc/n/n<<endl;

/*
	int totalcase;
	int testcase=0;
	cin>>totalcase;
	ofstream out;
	out.open("result.txt");

	while(totalcase--){
		testcase++;
		out<<"Case #"<<testcase<<": ";
		cout<<testcase<<": "<<endl;

		//GOGOGO

		//END
	}
	out.close();
*/

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, la[1000005], ta;
long long ans;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &ta);
		ans += (long long)(i - la[ta]) * (n - i + 1) * 2 - 1;
		la[ta] = i;
	}
	printf("%.10lf\n", (double)ans / n / n);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <algorithm>
using namespace std;

typedef long double ld;

const int Maxn = 1000005;

int n;
vector <int> seq[Maxn];
ld tot;

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int a; scanf("%d", &a);
		seq[a].push_back(i);
	}
	for (int i = 0; i < Maxn; i++) {
		seq[i].push_back(n);
		for (int j = 0; j + 1 < seq[i].size(); j++)
			tot += 2.0l * ld(seq[i][j + 1] - seq[i][j]) * ld(seq[i][j] + 1) - 1ll;
	}
	tot /= ld(n) * ld(n);
	cout << fixed << setprecision(15) << tot << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ok printf("ok\n");
#define pf printf
#define sc scanf
#define br printf("\n")

#define scs(a) scanf("%s",a)
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define sc3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sc1l(a) scanf("%lld",&a)
#define sc2l(a,b) scanf("%lld %lld",&a,&b)
#define sc3l(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define sc1d(a) scanf("%lf",&a)
#define sc2d(a,b) scanf("%lf %lf",&a,&b)
#define sc3d(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define pfs(a) printf("%s",a)
#define pf1(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf1l(a) printf("%lld",a)
#define pf2l(a,b) printf("%lld %lld",a,b)
#define pf1d(a) printf("%lf",a)
#define pf2d(a,b) printf("%lf %lf",a,b)

#define pii pair<int,int>
#define pll pair<long long,long long>
#define mp make_pair
#define F first
#define S second
#define pb push_back

#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))

#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)

long long inline gcd(long long x,long long y){return !y?(long long)abs(x):gcd(y,x%y);}  //returns always positive gcd
long long inline lcm(long long a,long long b){return ((long long)abs((a/gcd(a,b))*b));} //returns always positive lcm
double inline cartesian_dist(double x1,double y1,double x2,double y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}

long long bigmod(long long b,long long p,long long m){              //for both positive and negative base
    if(!p)return 1%m;
    else if(p&1)return (((b%m)+m)%m*bigmod(b,p-1,m))%m;
    else {long long ret=bigmod(b,p/2,m);return (ret*ret)%m;}
}
// inverse will exist if and only if gcd(a,m) is 1
long long inverse(long long a,long long m){return bigmod(a,m-2,m);}  //if Mod is prime
long long extended(long long a,long long m){
    long long oldr=a,r=m,oldans=1,ans=0,quotient;
    while(r){
        quotient=oldr/r;
        oldr=oldr-r*quotient;
        swap(oldr,r);
        oldans=oldans-ans*quotient;
        swap(oldans,ans);
    }
    return ((oldans%m)+m)%m;
}

//template<class t1,class t2>  bool check_bit(t1 &mask,t2 i){return mask&((t1)1<<i);}
//template<class t1,class t2>  void set_bit(t1 &mask,t2 i){mask=mask|((t1)1<<i);}
//template<class t1,class t2>  void reset_bit(t1 &mask,t2 i){mask=mask&~((t1)1<<i);}

typedef long long ll;
const double PI=acos(-1.0);
const double eps=10E-12;
# define inf 100000000
ll MOD=101LL;

int n,arr[(int)1e6+5],lastIdx[(int)1e6+5],last[(int)1e6+5];
int main(){
    sc1(n);
    for(int i=1;i<=n;i++)sc1(arr[i]);
    for(int i=1;i<=n;i++){
        lastIdx[i]=last[arr[i]];
        last[arr[i]]=i;
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ll l=i-lastIdx[i];
        ll r=(n-i)+1;
        ans+=2*(l*r-1)+1;
    }
    //cout<<ans<<endl;
    pf1d((double)ans/(double)((ll)n*(ll)n));br;

    return 0;
}


//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
int n,x,a[100050];
double ans;
int main(){
	scanf("%d",&n),ans=-n;
	for(int i=1;i<=n;i++)scanf("%d",&x),ans+=(i-a[x])*(n-i+1)*2,a[x]=i;
	printf("%lf",ans/n/n);
}


//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
int n,x,a[1000500];
long double ans;
int main(){
	scanf("%d",&n),ans=-n;
	for(int i=1;i<=n;i++)scanf("%d",&x),ans+=(i-a[x])*(n-i+1)*2,a[x]=i;
	printf("%Lf",ans/n/n);
}


//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
int n,x,a[1000500];
double ans;
int main(){
	scanf("%d",&n),ans=-n;
	for(int i=1;i<=n;i++)scanf("%d",&x),ans+=(i-a[x])*(n-i+1)*2,a[x]=i;
	printf("%lf",ans/n/n);
}


//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
int n,x,a[1000500];
long double ans;
int main(){
	scanf("%d",&n),ans=-n;
	for(int i=1;i<=n;i++)scanf("%d",&x),ans=ans+1ll*(i-a[x])*(n-i+1)*2,a[x]=i;
	printf("%Lf",ans/n/n);
}


//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
int n,x,a[1000500];
long double ans;
int main(){
	scanf("%d",&n),ans=-n;
	for(int i=1;i<=n;i++)scanf("%d",&x),ans=ans+1ll*(i-a[x])*(n-i+1)*2,a[x]=i;
	cout<<ans/n/n<<endl;
}


#include <bits/stdc++.h>

#define FOR(x, a, b) for (int x = a; x <= b; ++x)
#define FOD(x, a, b) for (int x = a; x >= b; --x)
#define REP(x, a, b) for (int x = a; x < b; ++x)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A, n) { cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl; }
#define PR0(A, n)  { cout << #A << " = "; REP(_, 0, n) cout << A[_] << " "; cout << endl; }

using namespace std;

typedef long long LL;
typedef pair <int, int> II;

const int N = 1e6 + 10;

int n;
int pos[N], a[N];

int main() {
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    scanf("%d", &n);
    FOR(i, 1, n) scanf("%d", &a[i]);
    LL ans = 0;
    FOR(i, 1, n) {
        int j = pos[a[i]] + 1;
        ans += (LL)(i - j + 1) * (n - i + 1);
        pos[a[i]] = i;
    }
    ans <<= 1; ans -= n;
    LL numseg = ((LL)n * (n - 1) / 2 + n) * 2LL - n;
    printf("%.5f", (double)ans / (double)numseg);
    return 0;
}


#include <bits/stdc++.h>

#define FOR(x, a, b) for (int x = a; x <= b; ++x)
#define FOD(x, a, b) for (int x = a; x >= b; --x)
#define REP(x, a, b) for (int x = a; x < b; ++x)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A, n) { cout << #A << " = "; FOR(_, 1, n) cout << A[_] << " "; cout << endl; }
#define PR0(A, n)  { cout << #A << " = "; REP(_, 0, n) cout << A[_] << " "; cout << endl; }

using namespace std;

typedef long long LL;
typedef pair <int, int> II;

const int N = 1e6 + 10;

int n;
int pos[N], a[N];

int main() {
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    scanf("%d", &n);
    FOR(i, 1, n) scanf("%d", &a[i]);
    LL ans = 0;
    FOR(i, 1, n) {
        int j = pos[a[i]] + 1;
        ans += (i - j + 1) * (n - i + 1);
        pos[a[i]] = i;
    }
    ans <<= 1; ans -= n;
    LL numseg = ((LL)n * (n - 1) / 2 + n) * 2LL - n;
    printf("%.5f", (double)ans / (double)numseg);
    return 0;
}


#include <iostream>
#include <algorithm>
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
const int N = 1e6;

int n,a[N];
ii b[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i=0; i<n; ++i) {
        cin >> a[i];
        b[i] = ii(a[i], i);
    }
    sort(b,b+n);

    long long sum = 0;
    double res = 0;
    long long com = (long long)n*(n-1) + n;

    for(int i=0; i<n; ++i)
    {
        int j = lower_bound(b,b+n,ii(a[i],i)) - b;
        int x = (!j || b[j-1].fi != a[i]) ? 0 : b[j-1].se+1;
        sum += i-x;
        res += (double)sum*2/com + 1.0/com;
        sum++;
    }

    cout << res;
}


#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include<complex>
//#include <bits/stdc++.h>

using namespace std;

#define HI              printf("HI\n")
#define sf              scanf
#define pf              printf
#define sf1(a)          scanf("%d",&a)
#define sf2(a,b)        scanf("%d %d",&a,&b)
#define sf3(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d)    scanf("%d %d %d %d",&a,&b,&c,&d)
#define sf1ll(a)        scanf("%lld",&a)
#define sf2ll(a,b)      scanf("%lld %lld",&a,&b)
#define sf3ll(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define sf4ll(a,b,c,d)    scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define forln(i,a,n)    for(int i=a ; i<n ; i++)
#define foren(i,a,n)    for(int i=a ; i<=n ; i++)
#define forg0(i,a,n)    for(int i=a ; i>n ; i--)
#define fore0(i,a,n)    for(int i=a ; i>=n ; i--)
#define pb              push_back
#define ppb             pop_back
#define ppf             push_front
#define popf            pop_front
#define ll              long long int
#define ui              unsigned int
#define ull             unsigned long long
#define fs              first
#define sc              second
#define clr( a, b )     memset((a),b,sizeof(a))
#define jora            pair<int, int>
#define jora_d          pair<double, double>
#define jora_ll         pair<long long int, long long int>
#define mp              make_pair
#define max3(a,b,c)     max(a,max(b,c))
#define min3(a,b,c)     min(a,min(b,c))
#define PI              acos(0.0)
#define wait            system("pause")
#define ps              pf("PASS\n")
#define popc(a)         (__builtin_popcount(a))

template<class T1> void deb(T1 e1)
{
    cout<<e1<<endl;
}
template<class T1,class T2> void deb(T1 e1,T2 e2)
{
    cout<<e1<<" "<<e2<<endl;
}
template<class T1,class T2,class T3> void deb(T1 e1,T2 e2,T3 e3)
{
    cout<<e1<<" "<<e2<<" "<<e3<<endl;
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1,T2 e2,T3 e3,T4 e4)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<" "<<e6<<endl;
}

/// <---------------------------  For Bitmasking  -------------------------------->
//int on( int n, int pos ){
//    return n = n|( 1<<pos );
//}
//bool check( int n, int pos ){
//    return (bool)( n&( 1<<pos ) );
//}
//int off( int n, int pos ){
//    return n = n&~( 1<<pos );
//}
//int toggle( int n, int pos ){
//    return n = n^(1<<pos);
//}
//int count_bit( int n ){
//    return __builtin_popcount( n );
//}
/// <---------------------------  End of Bitmasking  -------------------------------->

/// <--------------------------- For B - Base Number System ----------------------------------->
//int base;
//int pw[10];
//void calPow(int b){
//    base = b;
//    pw[0] = 1;
//    for( int i = 1; i<10; i++ ){
//        pw[i] = pw[i-1]*base;
//    }
//}
//int getV(int mask, int pos){
//    mask /= pw[pos];
//    return ( mask%base );
//}
//int setV(int mask, int v, int pos){
//    int rem = mask%pw[pos];
//    mask /= pw[pos+1];
//    mask = ( mask*base ) + v;
//    mask = ( mask*pw[pos] ) + rem;
//    return mask;
//}
/// <--------------------------- End B - Base Number System ----------------------------------->

// moves

//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*night move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*night move*/

//double Expo(double n, int p) {
//	if (p == 0)return 1;
//	double x = Expo(n, p >> 1);
//	x = (x * x);
//	return ((p & 1) ? (x * n) : x);
//}

//ll bigmod(ll a,ll b,ll m){if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a) % m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MXN 50
#define MXE
#define MXQ
#define SZE
#define MOD
#define EPS
#define INF 100000000
#define MX  1000005
#define inf 100000000

const ll mod = 1000000007;

int prv[MX];
int arr[MX];

int main()
{
//    freopen("input.txt", "r", stdin);
    ll n;
    scanf("%lld", &n);
    ll total = 0, cost = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &arr[i]);
        cost -= prv[arr[i]];
        cost += i;
        prv[arr[i]] = i;
        total += cost;
        //deb(i,cost);
    }
    //deb(2*total-n,n*n);
    double ans = (double) (2.0*total-n)/(n*n);
    printf("%lf\n", ans);
    return 0;
}


#include <cstring>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;

const int MAXN = 1000010;
template<typename T>
inline void read(T &x) {
	char ch; while((ch = getchar()), (ch < '0' || ch > '9'));
	x = ch - '0'; while((ch = getchar()), (ch >= '0' && ch <= '9')) x = x * 10 + (ch - '0');
}

int last[MAXN], N;
ll sum = 0, Ans = 0;

int main() {
	int i, t; read(N);
	for(i = 1; i <= N; i++) {
		read(t); if(last[t]) sum -= last[t];
		sum += i;

		Ans += 2 * sum - 1;

		last[t] = i;
	}
	printf("%.8lf", (double)Ans / ((double)N * N));
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
inline long long read(){
	long long x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(long long a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(long long a){
    write(a); puts("");
}
const long long N=1000005;
long long n,ans;
long long a[N];
vector <long long> v[N];
int main(){
    n=read();
    for(long long i=1;i<N;i++)v[i].push_back(0);
    for(long long i=1;i<=n;i++){a[i]=read(); v[a[i]].push_back(i);}
    for(long long i=1;i<N;i++){
    	v[i].push_back(n+1);
    	for(long long j=1;j<v[i].size()-1;j++){
    		ans+=(v[i][j]-v[i][j-1])*(v[i][j+1]-v[i][j])*2-1;
		}
	}
	cout<<(double)ans/(n*n)<<endl;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
inline long long read(){
	long long x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(long long a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(long long a){
    write(a); puts("");
}
const long long N=1000005;
long long n,ans;
long long a[N],shu;
vector <long long> v[N];
int main(){
    n=read();
    for(long long i=1;i<N;i++)v[i].push_back(0);
    for(long long i=1;i<=n;i++){a[i]=read(); v[a[i]].push_back(i);}
    for(int i=1;i<N;i++)if(v[i].size()>1)shu++;
    ans=n*n*shu;
    for(long long i=1;i<N;i++)if(v[i].size()>1){
    	v[i].push_back(n+1);
    	for(long long j=1;j<v[i].size();j++){
    		ans-=(v[i][j]-v[i][j-1]-1)*(v[i][j]-v[i][j-1]-1);
		}
	}
	cout<<(double)ans/(n*n)<<endl;
}


#include<cstdio>
#include<algorithm>
using namespace std;

long long pre[1000010],n,i,j,ans;

int main()
{
	scanf("%lld",&n);
	ans-=n;
	for(i=1;i<=n;i++)
	{
		long long x;
		scanf("%lld",&x);
		ans+=(i-pre[x])*(n-i+1)*2;
		pre[x]=i;
	}
	double hehe=(double)ans/(n*n);
	printf("%.6lf",hehe);
}


//----------------------JUGNU:LET YOUR LIGHT SHINE---------------------------//
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pf push_front
#define sz size
#define mk make_pair
#define ln length
#define fr(i,a,b) for(i=a;i<b;i++)
#define fre(i,a,b) for(i=a;i<=b;i++)
#define frr(i,a,b) for(i=a;i>=b;i--)
#define sc(a) scanf("%d", &a)
#define sm(a, b) scanf("%d%d", &a, &b)
#define pr(a) printf("%d\n", a)
#define pm(a, b) printf("%d %d\n", a, b)
#define isset(x,i) ((x>>i)&1)
#define MAXN 1000005
#define MOD 1000000007LL
#define fastScan ios_base::sync_with_stdio(0); cin.tie(NULL);

#define trace1(x)       cerr << #x << " : " << x << endl;
#define trace2(x, y)    cerr << #x << " : " << x << " | " << #y << " : " << y << endl;
#define trace3(x, y, z) cerr << #x << " : " << x << " | " << #y << " : " << y << " | " << #z << " : " << z << endl;
#define cline cout << "----------------------" << endl;
using namespace std;
int prev[MAXN], nums[MAXN];
ll distinct;
int main()
{
	int i, j, t, n, m, k, l, r, temp, mini, maxi, flag, cnt;
	sc(n);
	fre(i, 1, n) sc(nums[i]);
	fre(i, 1, n){
		distinct = distinct + (i - prev[nums[i]]) * 1LL * (n - i + 1);
		prev[nums[i]] = i;
	}
	distinct = 2LL * distinct - n;
	printf("%.6lf\n", (distinct * 1.0) / (n * 1.0 * n));

return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define MP make_pair
#define F first
#define S second
using namespace std;
const int MAXB = 1e7;
char buf[MAXB], *cp = buf;
inline void rd(int &x){
	x = 0; int f = 1;
	while(*cp < '0' || '9' < *cp){if(*cp == '-') f = -1; cp++;}
	while('0' <= *cp && *cp <= '9') x = (x << 3) + (x << 1) + *cp - 48, cp++;
	x *= f;
}
const int MAXN = 1000010;
int n;
int a[MAXN], f[MAXN];
double ans;
int main(){
	//freopen("in.txt", "r", stdin);
	fread(buf, 1, MAXB, stdin);
	rd(n);
	for(int i = 1; i <= n; i++){
		rd(a[i]);
		ans += (i - f[i]) * (n - i + 1) * 2 - 1;
		f[a[i]] = i;
	}
	cout << ans / (n * n) << endl;
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define MP make_pair
#define F first
#define S second
using namespace std;
const int MAXB = 1e7;
char buf[MAXB], *cp = buf;
inline void rd(int &x){
	x = 0; int f = 1;
	while(*cp < '0' || '9' < *cp){if(*cp == '-') f = -1; cp++;}
	while('0' <= *cp && *cp <= '9') x = (x << 3) + (x << 1) + *cp - 48, cp++;
	x *= f;
}
const int MAXN = 1000010;
int n;
int a[MAXN], f[MAXN];
LL ans;
int main(){
	freopen("in.txt", "r", stdin);
	fread(buf, 1, MAXB, stdin);
	rd(n);
	for(int i = 1; i <= n; i++){
		rd(a[i]);
		ans += 1LL * (i - f[i]) * (n - i + 1) * 2 - 1;
		f[a[i]] = i;
	}
	cout << (double)ans / (double)n / (double)n << endl;
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define MP make_pair
#define F first
#define S second
using namespace std;
const int MAXB = 1e7;
char buf[MAXB], *cp = buf;
inline void rd(int &x){
	x = 0; int f = 1;
	while(*cp < '0' || '9' < *cp){if(*cp == '-') f = -1; cp++;}
	while('0' <= *cp && *cp <= '9') x = (x << 3) + (x << 1) + *cp - 48, cp++;
	x *= f;
}
const int MAXN = 1000010;
int n;
int a[MAXN], f[MAXN];
double ans;
int main(){
	//freopen("in.txt", "r", stdin);
	fread(buf, 1, MAXB, stdin);
	rd(n);
	for(int i = 1; i <= n; i++){
		rd(a[i]);
		ans += (i - f[a[i]]) * (n - i + 1) * 2 - 1;
		f[a[i]] = i;
	}
	cout << ans / (n * n) << endl;
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define MP make_pair
#define F first
#define S second
using namespace std;
const int MAXB = 1e7;
char buf[MAXB], *cp = buf;
inline void rd(int &x){
	x = 0; int f = 1;
	while(*cp < '0' || '9' < *cp){if(*cp == '-') f = -1; cp++;}
	while('0' <= *cp && *cp <= '9') x = (x << 3) + (x << 1) + *cp - 48, cp++;
	x *= f;
}
const int MAXN = 1000010;
int n;
int a[MAXN], f[MAXN];
double ans;
int main(){
	//freopen("in.txt", "r", stdin);
	fread(buf, 1, MAXB, stdin);
	rd(n);
	for(int i = 1; i <= n; i++){
		rd(a[i]);
		ans += (double)(i - f[a[i]]) * (n - i + 1) * 2 - 1;
		f[a[i]] = i;
	}
	cout << ans / n / n << endl;
	return 0;
}


/*
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;

const int N=507;

int n,m,k,r[N][N],q,now[N][N],f[N][N];

bool check(int s)
{
	memset(f,0,sizeof(f));
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			now[i][j]=max(r[i][j]-s,0);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(now[i][j]>0)
				f[i][j]=0;
			else
				f[i][j]=min(f[i][j-1],min(f[i-1][j],f[i-1][j-1]))+1;
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(f[i][j]>=k)
				return true;
	return false;
}

int main()
{
	cin>>n>>m>>k>>q;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			r[i][j]=1e9+7;
	for(int i=1;i<=q;i++)
	{
		int x,y,t;
		cin>>x>>y>>t;
		r[x][y]=t;
	}
	int l=-1,r=1e9+1;
	while(r-l>1)
	{
		int mid=(l+r)>>1;
		if(check(mid))
			r=mid;
		else
			l=mid;
	}
	if(!check(r))
		cout<<"-1";
	else
		cout<<r;
}
*/

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;

typedef long long ll;

const int N=2e6+1e3+7;

ll a[N],fd[N];

ll ans,key[N*2],ret[N],tag[N*2],next[N],tot;

ll lt[N*2],rt[N*2],n;

int vis[N];

void update(int now)
{
	key[now]=key[now*2]+key[now*2+1];
}

void pushdown(int now)
{
	key[now*2+1]+=tag[now]*(rt[now*2+1]-lt[now*2+1]+1);
	key[now*2]+=tag[now]*(rt[now*2]-lt[now*2]+1);
	tag[now*2+1]+=tag[now];
	tag[now*2]+=tag[now];
	tag[now]=0;
}

void build(int now,int l,int r)
{
	lt[now]=l;rt[now]=r;
	if(l==r)
	{
		key[now]=ret[l];
		return;
	}
	int mid=(l+r)>>1;
	build(now*2,l,mid);
	build(now*2+1,mid+1,r);
	update(now);

}

ll query(int now,int l,int r,int L,int R)
{
	pushdown(now);
	if(L<=l&&r<=R)
		return key[now];
	int mid=l+r>>1;
	ll ret=0;
	if(L<=mid)
		ret+=query(now*2,l,mid,L,R);
	if(R>mid)
		ret+=query(now*2+1,mid+1,r,L,R);
	update(now);
	return ret;
}

void modify(int now,int l,int r,int L,int R)
{
	pushdown(now);
	if(L<=l&&r<=R)
	{
		tag[now]-=1;
		key[now]-=(ll)r-l+1;
		return;
	}
	int mid=l+r>>1;
	if(L<=mid)
		modify(now*2,l,mid,L,R);
	if(R>mid)
		modify(now*2+1,mid+1,r,L,R);
	update(now);
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%I64d",&a[i]);
	for(int i=n;i>=1;i--)
	{
		if(fd[a[i]])
			next[i]=fd[a[i]];
		fd[a[i]]=i;
	}
	for(int i=1;i<=n;i++)
		if(!next[i])
			next[i]=n+1;
	for(int i=1;i<=n;i++)
	{
		if(!vis[a[i]])
			tot++,vis[a[i]]=1;
		ret[i]=tot;
		ans+=tot;
	}
	tot=ans;
	for(ll i=1;i<n;i++)
	{
		tot--;
		tot-=next[i]-i-1;
		ans+=tot;
	}
	ans=ans-(ll)n;
	ans<<=1;
	ans+=(ll)n;
	double anss=ans;
	double nn=n;
	printf("%lf",anss/(nn*nn));
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n, a[1000100], pos[1000100];
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	double ans = 0;
	for(int i = 1; i <= n; i++) {
		ans += 2.0 * (i - pos[a[i]]) * (n - i + 1) / n / n - 1.0 / n / n;
		pos[a[i]] = i;
	}
	printf("%.10lf\n", ans);
}


#include<bits/stdc++.h>
using namespace std;
#define pc putchar_unlocked
#define gc getchar_unlocked
typedef long long ll;
typedef unsigned long long llu;
#define mp make_pair
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scl(x) scanf("%lld",&x)
#define scl2(x,y) scanf("%lld%lld",&x,&y)
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define scstr(x) scanf("%s",x)
#define pd(x) printf("%d",x)
#define pstr(x) printf("%s",x)
#define newl() printf("\n")
#define fl(i,n) for (i=0;i<n;i++)
#define fle(i,n) for (i=1;i<=n;i++)
#define fla(i,a,n) for (i=a;i<n;i++)
#define mem(a,i) memset(a,i,sizeof(a))
#define fi first
#define se second
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii ;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
#define gcd __gcd
#define wl(n) while (n--)
#define debug(x) cerr<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
#define tr(container, it)  for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define all(v) v.begin(),v.end()
#define tatt(cont) typeof(cont.begin())
const double eps = 0.000000000000001 ;
#define MOD 1000000007
typedef long double LF;
typedef double lF;
#define hihihaha ((double)CLOCKS_PER_SEC)
#define nl putchar('\n')
//-------------
int A[1000100], lst[1000010];
ll got = 0, fin = 0;
int main()
{	//ios::sync_with_stdio(0), cin.tie(0);
	int n, i, j;
	sc(n);
	for (i = 1; i <= n; i++) {
		sc(A[i]);
		if (lst[A[i]] != 0) {
			got = got - lst[A[i]];
		}
		got = got + i;
		lst[A[i]] = i;
		fin += got;
		//debug3(i, got, fin);
	}
	printf("%lf\n", (double)(2.0*(LF)got / (n) / n));

	return 0;

}

//01010110 01101100 01100001 01100100 00101110


#include<bits/stdc++.h>
using namespace std;
#define pc putchar_unlocked
#define gc getchar_unlocked
typedef long long ll;
typedef unsigned long long llu;
#define mp make_pair
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scl(x) scanf("%lld",&x)
#define scl2(x,y) scanf("%lld%lld",&x,&y)
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define scstr(x) scanf("%s",x)
#define pd(x) printf("%d",x)
#define pstr(x) printf("%s",x)
#define newl() printf("\n")
#define fl(i,n) for (i=0;i<n;i++)
#define fle(i,n) for (i=1;i<=n;i++)
#define fla(i,a,n) for (i=a;i<n;i++)
#define mem(a,i) memset(a,i,sizeof(a))
#define fi first
#define se second
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii ;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
#define gcd __gcd
#define wl(n) while (n--)
#define debug(x) cerr<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
#define tr(container, it)  for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define all(v) v.begin(),v.end()
#define tatt(cont) typeof(cont.begin())
const double eps = 0.000000000000001 ;
#define MOD 1000000007
typedef long double LF;
typedef double lF;
#define hihihaha ((double)CLOCKS_PER_SEC)
#define nl putchar('\n')
//-------------
int A[1000100], lst[1000010];
ll got = 0, fin = 0;
int main()
{	//ios::sync_with_stdio(0), cin.tie(0);
	int n, i, j;
	sc(n);
	for (i = 1; i <= n; i++) {
		sc(A[i]);
		if (lst[A[i]] != 0) {
			got = got - lst[A[i]];
		}
		got = got + i;
		lst[A[i]] = i;
		fin += got;
		//debug3(i, got, fin);
	}
	printf("%.20lf\n", (double)( (LF)(2.0 * fin - n) / n / n));

	return 0;

}

//01010110 01101100 01100001 01100100 00101110


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <string>
using namespace std;
#define REP(i, a, b) for(int i = a; i < b; i++)
#define PER(i, a, b) for(int i = b - 1; i >= a; i--)
#define SZ(a) ((int)a.size())
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(a) a.begin(), a.end()
typedef long long LL;
typedef pair<int, int> PII;

const int maxn = 1000000 + 1;

int pos[maxn];

int main() {
	int n; scanf("%d", &n);
	LL sum = 0, cnt = 0;
	REP(i, 1, n + 1) {
		int x;
		scanf("%d", &x);
		cnt += i - 1 - pos[x];
		cnt++;
		sum += cnt;
		pos[x] = i;
	}
	sum = (sum << 1) - n;
	printf("%.6f\n", (double)sum / n / n);

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <string>
using namespace std;
#define REP(i, a, b) for(int i = a; i < b; i++)
#define PER(i, a, b) for(int i = b - 1; i >= a; i--)
#define SZ(a) ((int)a.size())
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(a) a.begin(), a.end()
typedef long long LL;
typedef pair<int, int> PII;

const int maxn = 1000000 + 1;

int pos[maxn];

int read(int& x) {
	x = 0;
	char c = ' ';
	while(c < '0' || c > '9') c = getchar();
	while('0' <= c && c <= '9') {
		x = (x<<3)+(x<<1)+c-'0';
		c = getchar();
	}
}

int main() {
	int n; scanf("%d", &n);
	LL sum = 0, cnt = 0;
	REP(i, 1, n + 1) {
		int x;
		read(x);
		cnt += i - pos[x];
		sum += cnt;
		pos[x] = i;
	}
	sum = (sum << 1) - n;
	printf("%.6f\n", (double)sum / n / n);

	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

typedef long long llint;

const llint MAXN = 1000005;

llint n, sol, res;
llint l[MAXN];
set <int> s;
vector <int> v[MAXN];

int nadi (int ind) {
	int res=upper_bound(v[l[ind]].begin(), v[l[ind]].end(), ind)-v[l[ind]].begin();
	if (res==v[l[ind]].size()) return n; return v[l[ind]] [res];
}

int main () {
	cin >> n;
	for (int i=0; i<n; i++) {
		scanf("%d", &l[i]);
		v[l[i]].push_back(i);
		s.insert(l[i]);
		res+=s.size();
	}
	for (int i=0; i<n; i++) {
		sol+=res;
		res-=nadi(i)-i;
	}
	printf("%.7f", ((double) (2*sol-n))/(n*n));
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

typedef long long llint;

const llint MAXN = 1000005;

llint n, pot=1, sol;
llint l[MAXN];
llint t[4*MAXN], prop[4*MAXN];
set <int> s;
vector <int> v[MAXN];

void tournament_init () {
	while (pot<n) pot*=2;
	for (int i=0; i<n; i++) {
		s.insert(l[i]);
		t[i+pot]=s.size();
	}
	for (int i=pot-1; i>=0; i--) {
		t[i]=t[i*2]+t[i*2+1];
	}
}

void propagate (int cvor, int low, int high) {
	if (prop[cvor]==0) return;
	t[cvor]+=(high-low+1)*prop[cvor];
	prop[cvor*2]+=prop[cvor];
	prop[cvor*2+1]+=prop[cvor];
	prop[cvor]=0;
}

void update (int cvor, int from, int to, int low, int high, llint val) {
	propagate(cvor, low, high);
	if (from<=low && high<=to) {
		prop[cvor]+=val;
		propagate(cvor, low, high);
		return;
	}
	if (to<low || high<from) return;
	update(cvor*2, from, to, low, (low+high)/2, val);
	update(cvor*2+1, from, to, (low+high)/2+1, high, val);
}

llint upit (int cvor, int from, int to, int low, int high) {
	propagate(cvor, low, high);
	if (from<=low && high<=to) return t[cvor];
	if (to<low || high<from) return 0;
	return upit(cvor*2, from, to, low, (low+high)/2)+upit(cvor*2+1, from, to, (low+high)/2+1, high);
}

int nadi (int ind) {
	int res=upper_bound(v[l[ind]].begin(), v[l[ind]].end(), ind)-v[l[ind]].begin();
	if (res==v[l[ind]].size()) return n; return v[l[ind]] [res];
}

int main () {
	cin >> n;
	for (int i=0; i<n; i++) {
		scanf("%d", &l[i]);
		v[l[i]].push_back(i);
	}
	tournament_init();
	for (int i=0; i<n; i++) {
		llint res=upit(1, i, n-1, 0, pot-1);
		int ind=nadi(i);
		if (i<ind-1) update(1, i+1, ind-1, 0, pot-1, -1);
		sol+=res;
	}
	printf("%.7f", ((double) (2*sol-n))/(n*n));
	return 0;
}


#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define rre(i,r,l) for(int i=(r);i>=(l);i--)
#define re(i,l,r) for(int i=(l);i<=(r);i++)
#define Clear(a,b) memset(a,b,sizeof(a))
#define inout(x) printf("%d",(x))
#define douin(x) scanf("%lf",&x)
#define strin(x) scanf("%s",(x))
#define LLin(x) scanf("%lld",&x)
#define op operator
typedef unsigned long long ULL;
typedef const int cint;
typedef long long LL;
using namespace std;
template<typename Q>
void inin(Q &ret)
{
	ret=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')ret=ret*10+ch-'0',ch=getchar();
}
int n,a[1000010],shang[1000010];
int bo[1000010];
LL sum;
int main()
{
	inin(n);
	re(i,1,n)inin(a[i]);
	re(i,1,n)sum+=1ll*(i+2)*(i-1)+1;
	re(i,1,n)if(!bo[a[i]])bo[a[i]]=i;
	else shang[i]=bo[a[i]],bo[a[i]]=i;
	for(int i=n;i>=1;i--)if(shang[i])sum-=2ll*shang[i]*(n-i+1);
	double a=1.*sum/(1.*n*n);
	printf("%.6f",a);
	return 0;
}


#include <cstdio>
#include <cstring>
using namespace std;

const int lim = 1e6 + 5;

int n, p[lim];
long long s[lim];
double ans = 0;

int main()
{
    memset(p, 0, sizeof(p));
    scanf("%d", &n); s[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cur; scanf("%d", &cur);
        s[i] = s[i - 1] + i - p[cur];
        p[cur] = i;
    } s[0] = -n;
    for (int i = 1; i <= n; ++i)
        s[i] <<= 1;
    long long tmp = n * n;
    for (int i = 0; i <= n; ++i)
        ans += s[i] / tmp + (double)(s[i] % tmp) / tmp;
    printf("%.6f", ans);
    return 0;
}


#include <cstdio>
#include <cstring>
using namespace std;

const int lim = 1e6 + 5;

int n, p[lim], s[lim];
double ans = 0;

int main()
{
    memset(p, 0, sizeof(p));
    scanf("%d", &n); s[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cur; scanf("%d", &cur);
        s[i] = s[i - 1] + i - p[cur] - 1;
        p[cur] = i;
    } s[0] = n;
    long long tmp = n * n;
    for (int i = 0; i <= n; ++i)
        ans += (double)s[i] * 2 / tmp;
    printf("%.6f", ans);
    return 0;
}


#include <cstdio>
#include <cstring>
using namespace std;

const int lim = 1e6 + 5;

int n, p[lim];
long long s[lim];
long double ans = 0;

int main()
{
    memset(p, 0, sizeof(p));
    scanf("%d", &n); s[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cur; scanf("%d", &cur);
        s[i] = s[i - 1] + i - p[cur];
        p[cur] = i;
    }
    long long tmp = n * n;
    for (int i = 1; i <= n; ++i)
        ans += (long double)s[i] / tmp * 2;
    printf("%.6f", ans - (long double)n / tmp);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

const int lim = 1e6 + 5;

int n, p[lim];
long long s[lim];
long double ans = 0;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    memset(p, 0, sizeof(p));
    cin >> n; s[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cur; cin >> cur;
        s[i] = s[i - 1] + i - p[cur];
        p[cur] = i;
    }
    long long tmp = n * n;
    for (int i = 1; i <= n; ++i)
        ans += (long double)s[i] / tmp * 2;
    cout << ans - (long double)n / tmp;
    return 0;
}


#include <cstdio>
#include <cstring>
using namespace std;

const int lim = 1e6 + 5;

int n, p[lim];
long long s[lim], ans = 0;

int main()
{
    memset(p, 0, sizeof(p));
    scanf("%d", &n); s[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cur; scanf("%d", &cur);
        s[i] = s[i - 1] + i - p[cur];
        p[cur] = i;
    }
    for (int i = 1; i <= n; ++i)
        ans += s[i];
    printf("%Lf", (long double)(ans) / n / n * 2 - (long double)1 / n);
    return 0;
}


#include <cstdio>
#include <cstring>
using namespace std;

const int lim = 1e6 + 5;

int n, p[lim];
long long s[lim];
double ans = 0;

int main()
{
    memset(p, 0, sizeof(p));
    scanf("%d", &n); s[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cur; scanf("%d", &cur);
        s[i] = s[i - 1] + i - p[cur];
        p[cur] = i;
    }
    long long tmp = n * n;
    for (int i = 0; i <= n; ++i)
        ans += (double)s[i] / tmp * 2;
    printf("%.6f", ans - (double)n / tmp);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

const int lim = 1e6 + 5;

int n, p[lim];
long long s[lim];
long double ans = 0;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    memset(p, 0, sizeof(p));
    cin >> n; s[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cur; cin >> cur;
        s[i] = s[i - 1] + i - p[cur];
        p[cur] = i;
    }
    long long tmp = n * n;
    for (int i = 1; i <= n; ++i)
        ans += (long double)s[i] / tmp * 2;
    cout << ans - n;
    return 0;
}


#include <cstdio>
#include <cstring>
using namespace std;

const int lim = 1e6 + 5;

int n, p[lim], s[lim];
double ans = 0;

int main()
{
    memset(p, 0, sizeof(p));
    scanf("%d", &n); s[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cur; scanf("%d", &cur);
        s[i] = s[i - 1] + i - p[cur];
        p[cur] = i;
    } s[0] = -n;
    for (int i = 1; i <= n; ++i)
        s[i] <<= 1;
    long long tmp = n * n;
    for (int i = 0; i <= n; ++i)
        ans += (double)s[i] / tmp;
    printf("%.6f", ans);
    return 0;
}


#include <cstdio>
#include <cstring>
using namespace std;

const int lim = 1e6 + 5;

int n, p[lim];
long long s[lim];
double ans = 0;

int main()
{
    memset(p, 0, sizeof(p));
    scanf("%d", &n); s[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cur; scanf("%d", &cur);
        s[i] = s[i - 1] + i - p[cur];
        p[cur] = i;
    } s[0] = -n;
    for (int i = 1; i <= n; ++i)
        s[i] <<= 1;
    long long tmp = n * n;
    for (int i = 0; i <= n; ++i)
        ans += (double)s[i] / tmp;
    printf("%.6f", ans);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

const int lim = 1e6 + 5;

int n, p[lim];
long long s[lim];
long double ans = 0;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    memset(p, 0, sizeof(p));
    cin >> n; s[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cur; cin >> cur;
        s[i] = s[i - 1] + i - p[cur];
        p[cur] = i;
    }
    long long tmp = (long long)n * n;
    for (int i = 1; i <= n; ++i)
        ans += (long double)s[i] / tmp * 2;
    cout << ans - (long double)1 / n;
    return 0;
}


#include<bits/stdc++.h>

#define MOD 1000000007
#define MAX 1000005
#define ll long long
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define ss(x) scanf("%s",x)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vpii vector<pii >
#define vll vector<ll>
#define clr(x) memset(x,0,sizeof(x))

#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);

using namespace std;

ll power(ll a,ll b,ll m){
	ll x=1%m; a%=m;
	while(b){
		if((1&b)) x = x * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return x;
}

int a[MAX];
int mark[MAX];

int prev[MAX];

int main(){
	int n;sd(n);
	clr(mark);
	for(int i=1;i<=n;i++){
		sd(a[i]);
		prev[i] = mark[a[i]];
		mark[a[i]] = i;
	}

	ll ways = 0;
	for(int i=1;i<=n;i++){
		int lowl = prev[i]+1;
		int highr = n;

		ways += (i-lowl+1)*2LL*(highr-i);
		ways += (i-lowl)*2;
		ways++;
	}

	double ans = ways/(n*1.0*n);
	printf("%.8lf",ans);
}