Source Code
#include <fstream>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <set>
using namespace std;

int main()
{
    int _;
    cin>>_;
    while (_--)
    {
        long long n,b,mx=0;
        cin>>n;
        bool flaj= true;
        long long ary[n];
        set<long long> st1;
        map<long long, long long> mp;
        for(int i=0; i<n; i++)
        {
            cin>>ary[i];
            mp[ary[i]]++;
            if(mp[ary[i]]>2)
            {
                flaj=false;
            }
            st1.insert(ary[i]);
        }
        if (flaj)
            cout<<st1.size()<<endl;
        else
            cout<<-1<<endl;
    }
}
Copy
Proud Competitors Abbro
GNU G++17
160 ms
2.3 MB
Wrong Answer