i can’t find why it is showing in testcase 3 and 4 but correct in all other cases
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<=n;i++)
int unique(vectorv,vector&dp){
int i;
int sz=v.size();
map<int,int>prevind;
f1(i,sz-1){
prevind[v[i]]=0;
}
dp[1]=1;
prevind[v[1]]=1;
f1(i,sz-1){
dp[i+1]=dp[i]+(i+1-prevind[v[i+1]]);
prevind[v[i+1]]=i+1;
}
int sum=0;
f1(i,sz-1) sum+=dp[i];
return sum;
}
main(){
int n;
cin>>n;
int i;
vectorv(n+1);
vectordp(n+1);
f1(i,n) cin>>v[i];
float ans=unique(v,dp);
ans=float(2ans-n)/(nn);
cout<<fixed<<setprecision(6)<<ans;
}