Code not working

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll arr[1000009],last[1000009],ans[1000009];
int main()
{
int n;
cin>>n;
for(ll i=1;i<=n;i++)
cin>>arr[i];
ans[0]=0;
ll sum=0;
for(ll i=1;i<=n;i++)
{
ans[i]=ans[i-1]+(i-last[arr[i]]);
last[arr[i]]=i;
sum=sum+ans[i];
}
double res=0.0;
res=(2*(sum-n)+n)/(nn1.0);
cout<<fixed<<setprecision(6)<<res<<"\n";
return 0;
}
why this code is not submiting on codeforces ? it seems that the answer overflows the datatype?

Why aren’t you taking mod then if you feel your answer is overflowing.