Help me in solving MAXEQUAL problem

My issue

i used unordered map so it updates when the max count changes

My code

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t--){
         int n;
         cin>>n;
         vector<int>arr(n,0);
         unordered_map<int,int>hash;
         int c=n-1;
         int max_count1=-1,max_var;
         while(n--){
              int x,y;
              cin>>x>>y;
              hash[y]++;
              int ans=0;
              for(auto k : hash){
                     if(max_count1<k.second){
                           if(max_count1!=-1)
                           ans=ans+((max_count1)*(max_count1-1))/2;
                         max_count1=k.second;
                         max_var = k.first;
                     }
                     else
                      ans=ans+((k.second)*(k.second-1))/2;
                     
              }
              ans = ans + ((max_count1+c)*(max_count1+c-1))/2;
              cout<<ans<<" ";
              c--;
         }
         cout<<endl;
    }
}

Problem Link: Equal Pairs (Hard) Practice Coding Problem