Source Code
#include <iostream>
#include<bits/stdc++.h>
#include <cmath>
#include <string>
#include <algorithm>
#define sareeeee3 ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;
using veci=vector<int>;
using vecl=vector<long long>;
#define ll long long
/*
ll kwys(ll k){

}
*/

void result()
{
    int n{};
    cin>>n;
    int a[n];
    map<int,int>mp;
    int mx{};
    for (int i = 0; i <n ; ++i) {
        cin>>a[i];
        mp[a[i]]++;
        mx= max(mx,a[i]);
    }
    if(mp[mx]%2==0){
        cout<<2;
    }else if(mp[mx]==1){
        cout<<n;
    }else{
        cout<<-1;
    }




}


int main ()
{
    cout<<fixed<<setprecision(0);
    sareeeee3
    int t=1;
   cin>>t;
#ifndef ONLINE_JUDGE
    // freopen("tests.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif

    while (t--)
    {
        result();
        cout<<"\n";
    }

}
Copy
Proud Competitors Mostafa_Fouad
GNU G++17
6 ms
312 KB
Wrong Answer