Ideas de resolución de problemas: codicioso. Primero, cuente el número de cada número y guárdelo en la cola de prioridad. Elija los dos más grandes cada vez y reduzca su número en 1 hasta que sepa que ya no puede hacerlo.
#include<bits/stdc++.h>
using namespace std;typedeflonglong ll;typedeflongdouble lf;typedefunsignedlonglong ull;typedef pair<ll,int>P;constint inf =0x7f7f7f7f;const ll INF =1e16;constint N =1e5+10;const ull base =131;const ll mod =1e9+7;constdouble PI =acos(-1.0);constdouble eps =1e-4;inlineintread(){
int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';ch=getchar();}return x*f;}inline string readstring(){
string str;char s=getchar();while(s==' '||s=='\n'||s=='\r'){
s=getchar();}while(s!=' '&&s!='\n'&&s!='\r'){
str+=s;s=getchar();}return str;}intrandom(int n){
return(int)(rand()*rand())%n;}voidwritestring(string s){
int n = s.size();for(int i =0;i < n;i++){
printf("%c",s[i]);}}voidsolve(){
map<int,int>vis;int n =read();for(int i =1;i <= n;i++){
int x =read();
vis[x]++;}
priority_queue<int>que;for(auto it = vis.begin();it != vis.end();it++){
que.push(it->second);}while(que.size()>1){
int a = que.top();que.pop();int b = que.top();que.pop();
a--;b--;if(a) que.push(a);if(b) que.push(b);}int ans =0;while(que.size()){
ans += que.top();
que.pop();}
cout<<ans<<endl;}intmain(){
int t =read();while(t--){
solve();}return0;}