Can anybody explain me what is wrong with my code as it passes sample case but gets WA

here is the link to the question: Contest Page | CodeChef
here is my code:
#include
#include
#include
#include
#include <unordered_map>
#include <unordered_set>
#include
#include
#include
#include
#include
#include

using namespace std;

#define int long long int
#define endl “\n”
//#define mod 1000000007
#define pb push_back

void solve()
{
int n;
cin >> n;
vector v(n);
for(int i=0;i<n;i++)
cin >> v[i];
unordered_map<int, int> mp;
for(int i=0;i<n;i++)
mp[v[i]]++;
int count=0, rect=0;
for(auto it=mp.begin(); it!=mp.end(); it++)
{
int x=it->second;
if(x%2)
count++, x++;
if(rect==0)
rect+=(x/2);
else
rect=abs(rect-(x/2));
}
cout << count+(rect*2) << endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
cin >> tc;
while (tc–)
solve();
}

Thanks for your help in advance.

Try:
1
4
100 100 100 100

Expected answer: 0
Your code gives: 4

may be this will be helpful :slight_smile:

cin>>N;
    vector<int>arr;
    read(arr,N);

    vector<int>cnt(101);
    for(int i=0;i<N;i++){
        cnt[arr[i]]++;
    }

    int ans=0;
    for(int i=0;i<101;i++){
        if(cnt[i]%2) {
            cnt[i]++;
            ans++;
        }
    }
    int bad=0;
    for(int i=0;i<101;i++){
        while(cnt[i]>=4){
            cnt[i]-=4;
        }
        if(cnt[i]==2)
            bad++;
    }
    if(bad%2)
        ans+=2;

    cout<<ans<<endl;

ok ok, ya i understood what was wrong. Thank you everyone for help. Actually I was not considering square as a rectangle.