Unstable Subarray Problem Last Test case keeps failing

I have seen the solutions of other people after continuous failing of my code. It seems that everyone has used an algorithm similar to mine, but still my code keeps failing on the last test case.

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

void solve(){
int n;
cin>>n;
int tot=(n*(n-1))/2;
map<int,int> m;

``````while(n--){

int cur;
cin>>cur;
//cout<<" entered for"<<cur<<endl;
m[cur]+=1;
}
//auto it = map.begin();
int useless=0;
for(auto it=m.begin();it!=m.end();it++){
auto pai=(*it);
//cout<<"first is:    "<<pai.first<<" second is   "<<pai.second<<endl;
//auto pair=(*it);
int freq=pai.second;
if(freq>1){
useless=useless+(((freq)*(freq-1))/2);
}
}
cout<<tot-useless<<endl;
``````

}

int main() {
int t;
cin>>t;

``````while(t--){
solve();
}
return 0;
``````

}

@kanavkapoor
can u send the question link.??

@kanavkapoor
here is my code

``````#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define test lli t; cin>>t; while(t--)
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif

test{
lli n;
cin>>n;
lli a[n];
map<lli,lli> mp;
for(lli i=0;i<n;i++)
{
cin>>a[i];
mp[a[i]]++;
}

lli cnt=0;
for(auto x:mp)
{
cnt+=((x.second)*(x.second-1))/2;
}
n=(n*(n-1))/2;
n-=cnt;
cout<<n<<endl;
}

}
``````

The logic is u have to count the frequency and subtract the pairs u can form with them from the total count of the subarray.