malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T, class L>   bool smax(T& x, L y) {     return x < y ? (x = y, 1) : 0;   }   template <class T, class L>   bool smin(T& x, L y) {     return x > y ? (x = y, 1) : 0;   }   const int maxn = 2e5 + 17;   int n, m, gp[maxn], rate[maxn], cnt, sz[maxn];   unordered_map<int, pair<int, int> > p;   set<int> s[maxn];   vector<int> ag[maxn];   void dfs(int v, int rt = 0) {     if (gp[v]) return;     gp[v] = cnt, rate[v] = rt;     s[cnt].insert(rt);     sz[cnt]++;     dfs((v + m) % n, rt + 1);   }   int main() {     long long ans = 0;     p.max_load_factor(0.25), p.reserve(512);     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++)       if (!gp[i]) cnt++, dfs(i);     int q;     cin >> q;     for (int id, h; q--;) {       char c;       scanf(  %c %d , &c, &id);       if (c ==  + ) {         scanf( %d , &h);         int g = gp[h], r = rate[h];         auto it = s[g].lower_bound(r);         if (it == s[g].end()) it = s[g].begin(), ans += sz[g];         ans += *it - r;         p[id] = {g, *it};         s[g].erase(it);       } else {         auto tmp = p[id];         s[tmp.first].insert(tmp.second);       }     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   long long v[100000];   vector<long long> V[200005];   long long sum[200005] = {0}, l[5005], r[5005], ans[5005];   int main() {     long long int n, k, q, i, j, a, b, d, l1, t, sm = 0;     cin >> t;     for (i = 1; i <= t; i++) {       cin >> l[i];     }     for (i = 1; i <= t; i++) {       memset(r, 0, sizeof(r));       long long mx = 0, w = -1;       for (j = i; j <= t; j++) {         r[l[j]]++;         if (r[l[j]] > mx) {           mx = r[l[j]];           w = l[j];         } else if (r[l[j]] == mx && w > l[j]) {           w = l[j];         }         ans[w]++;       }     }     for (i = 1; i <= t; i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int MAX = 1e5 + 5;   const long long MAX2 = 11;   const int MOD = 1000000000 + 7;   const long long INF = 20000;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};   const double pi = acos(-1);   long long n;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     cout << n / 2520;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[1000001];   int main() {     int n;     scanf( %d , &n);     scanf( %s , str);     int sum = 0;     int ln = -1;     int i, j, k, ans = 0;     for (i = 0; i < n; i++) {       if (str[i] ==  ( ) {         sum++;         if (sum == 0) {           ans += i - ln + 1;           ln = -1;         }       } else {         sum--;         if (sum < 0 && ln == -1) ln = i;       }     }     if (sum != 0) {       printf( -1 n );     } else       printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const long long N = (long long)2e6 + 222;   const long long INF = (long long)1e18;   const double eps = (double)1e-6;   long long n, m, l, r, used[N];   vector<long long> g[N];   set<long long> s;   long long cnt = 0;   void dfs(long long x) {     used[x] = 1;     s.erase(x);     cnt++;     long long pr = 0;     for (auto to : g[x]) {       while (s.upper_bound(pr) != s.end() && (*s.upper_bound(pr)) < to) {         long long k = (*s.upper_bound(pr));         if (!used[k]) dfs(k);       }       pr = to;     }   }   void solve() {     cin >> n >> m;     for (long long i = 1; i <= m; ++i) {       cin >> l >> r;       g[l].push_back(r);       g[r].push_back(l);     }     for (long long i = 1; i <= n; ++i) s.insert(i);     long long ans = 0;     for (long long i = 1; i <= n; ++i) sort(g[i].begin(), g[i].end());     for (long long i = 1; i <= n; ++i) g[i].push_back(n + 1);     for (long long i = 1; i <= n; ++i) {       if (!used[i]) {         ans++;         dfs(i);       }     }     cout << ans - 1;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (n <= 3 || n == 5 || n == 7 || n == 11) {         cout <<  -1               <<   n ;       } else {         if (n % 2 == 0) {           cout << n / 4 <<   n ;         } else {           cout << n / 4 - 1 <<   n ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int arr[300005];   map<int, int> mp;   vector<int> opt;   int main() {     int n, lst = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       if (mp[arr[i]] && mp[arr[i]] > lst) {         mp[arr[i]] = 0;         opt.push_back(++lst);         opt.push_back(i);         lst = i;       } else {         mp[arr[i]] = i;       }     }     int l = opt.size();     if (l / 2 == 0) {       printf( -1 n );       return 0;     }     printf( %d n , l / 2);     opt[l - 1] = n;     for (int i = 0; i < l; i++) {       printf( %d  , opt[i++]);       printf( %d n , opt[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const double EPS = 1e-9;   const long long INF = 1e18 + 2007;   const double PI = 3.1415926535897932384626433832795;   const long long N = 200005;   long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }   signed main() {     ios_base::sync_with_stdio(0);     long long n, k;     cin >> n >> k;     long long g = 0;     for (long long i = 0; i < n; i++) {       long long a;       cin >> a;       g = gcd(g, a);     }     set<long long> ans;     for (long long i = 0; i < k; i++) {       ans.insert((g * i) % k);     }     cout << ans.size() << endl;     for (auto x : ans) {       cout << x <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, j, z, x = 10, k = 0, year = 0, l = 0, f = 0;     string s;     cin >> n;     while (n--) {       cin >> s;       x = 10;       f = 0;       year = 0;       k = s.length() - 4;       for (i = 1; i < k; i++) {         f += x;         x *= 10;       }       for (i = 4; i < s.length(); i++) {         year = year * 10 + 10 * (s[i] - 48);       }       year /= 10;       while (year < 1989 + f) {         year += x;       }       cout << year << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long f = 1, x = 0;     char ss = getchar();     while (ss <  0  || ss >  9 ) {       if (ss ==  - ) f = -1;       ss = getchar();     }     while (ss >=  0  && ss <=  9 ) {       x = x * 10 + ss -  0 ;       ss = getchar();     }     return f * x;   }   long long seed, vmax;   long long rnd() {     long long res = seed;     seed = (seed * 7 + 13) % 1000000007;     return res;   }   const int maxn = 100010;   int n, m;   long long a[maxn];   struct node {     int ll, rr;     mutable long long val;     bool operator<(const node& tt) const { return ll < tt.ll; }   };   set<node> st;   long long qpow(long long a, long long k, long long p) {     long long res = 1;     a %= p;     while (k > 0) {       if (k & 1) res = (res * a) % p;       a = (a * a) % p;       k >>= 1;     }     return res;   }   set<node>::iterator split(int pos) {     set<node>::iterator it = st.lower_bound(node{pos});     if (it != st.end() && it->ll == pos) return it;     --it;     int ll = it->ll, rr = it->rr;     long long val = it->val;     st.erase(it);     st.insert(node{ll, pos - 1, val});     return st.insert(node{pos, rr, val}).first;   }   void assign(int ll, int rr, long long val) {     set<node>::iterator itr = split(rr + 1), itl = split(ll);     st.erase(itl, itr);     st.insert(node{ll, rr, val});   }   void add(int ll, int rr, long long val) {     set<node>::iterator itr = split(rr + 1), itl = split(ll);     for (; itl != itr; ++itl) itl->val += val;   }   long long kth(int ll, int rr, int k) {     vector<pair<long long, int> > vec;     set<node>::iterator itr = split(rr + 1), itl = split(ll);     for (; itl != itr; ++itl)       vec.push_back(pair<long long, int>(itl->val, itl->rr - itl->ll + 1));     sort(vec.begin(), vec.end());     for (vector<pair<long long, int> >::iterator it = vec.begin();          it != vec.end(); ++it) {       k -= it->second;       if (k <= 0) return it->first;     }     return -1;   }   long long qsum(int ll, int rr, long long x, long long y) {     long long res = 0;     set<node>::iterator itr = split(rr + 1), itl = split(ll);     for (; itl != itr; ++itl)       res += (qpow(itl->val, x, y) * ((itl->rr - itl->ll + 1) % y)) % y, res %= y;     return res;   }   int main() {     n = read();     m = read();     seed = read();     vmax = read();     for (int i = 1; i <= n; ++i) {       a[i] = (rnd() % vmax) + 1;       st.insert(node{i, i, a[i]});     }     for (int i = 1; i <= m; ++i) {       int op = (rnd() % 4) + 1;       int ll = (rnd() % n) + 1, rr = (rnd() % n) + 1;       long long x, y;       if (ll > rr) swap(ll, rr);       if (op == 3)         x = (rnd() % (rr - ll + 1)) + 1;       else         x = (rnd() % vmax) + 1;       if (op == 4) y = (rnd() % vmax) + 1;       if (op == 1)         add(ll, rr, x);       else if (op == 2)         assign(ll, rr, x);       else if (op == 3)         printf( %lld n , kth(ll, rr, x));       else if (op == 4)         printf( %lld n , qsum(ll, rr, x, y));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fw[100005], s[100005], t[100005];   bool r[100005], v[100005];   int res = 0;   void dfs(int i) {     v[i] = true;     if (v[fw[i]]) {       t[res] = i;     } else {       dfs(fw[i]);     }   }   int main() {     int n = 0;     ios::sync_with_stdio(false);     memset(fw, 0, sizeof(fw));     memset(r, true, sizeof(r));     memset(v, false, sizeof(v));     cin >> n;     int num = 0;     for (int i = 1; i <= n; ++i) {       cin >> fw[i];       r[fw[i]] = false;     }     for (int i = 1; i <= n; ++i) {       if (r[i] && !v[i]) {         ++res;         s[res] = i;         dfs(i);       }     }     int cur = res;     for (int i = 1; i <= n; ++i) {       if (!v[i]) {         ++res;         s[res] = i;         dfs(i);       }     }     if (cur == 0 && res == 1) {       cout << 0 << endl;     } else {       cout << res << endl;       for (int i = 1; i <= res; ++i) {         cout << t[i] <<     << s[i % res + 1] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class F, class T>   T convert(F input, int width = 0, int prec = -1) {     stringstream A;     T res;     if (prec > -1) A << fixed << setprecision(prec);     A << setw(width) << setfill( 0 ) << input;     A >> res;     return res;   }   int main() {     string nm;     cin >> nm;     int ln = nm.length() - 1;     int dt = find((nm).begin(), (nm).end(),  . ) - nm.begin();     if (nm[dt - 1] !=  9  && nm[dt + 1] <  5 ) {       cout << nm.substr(0, dt);       return 0;     }     if (nm[dt - 1] !=  9  && nm[dt + 1] >=  5 ) {       string res = nm.substr(0, dt);       res[int((res).size()) - 1] = res[int((res).size()) - 1] + 1;       cout << res;       return 0;     }     cout <<  GOTO Vasilisa. ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string board[8];   int main() {     for (int i = 0; i < 8; ++i) cin >> board[i];     const char* s =  WB ;     for (int i = 0; i < 8; ++i) {       int c = board[i][0] ==  B ;       for (int j = 1; j < 8; ++j) {         if (board[i][j] != s[(c + j) % 2]) {           cout <<  NO n ;           return 0;         }       }     }     cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   std::mt19937 rng(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   const int ms = 101;   long long memo[ms][ms], memo2[ms][ms][ms];   long long a[ms];   std::string str;   long long dp(int l, int r);   long long dp2(int l, int r, int x) {     if (r - l <= 0) return 0;     long long &ans = memo2[l][r][x];     if (ans != -1) return ans;     ans = dp(l + 1, r) + a[x];     for (int i = l + 1; i < r; i++) {       if (str[i] == str[l]) {         ans = std::max(ans, dp(l + 1, i) + dp2(i, r, x + 1));       }     }     return ans;   }   long long dp(int l, int r) {     if (r - l <= 0)       return 0;     else if (r - l == 1)       return a[1];     long long &ans = memo[l][r];     if (ans != -1) return ans;     ans = 0;     for (int m = l; m < r; m++) {       ans = std::max(ans, dp2(m, r, 1) + dp(l, m));     }     return ans;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     int n;     std::cin >> n >> str;     for (int i = 0; i < n; i++) {       std::cin >> a[i + 1];     }     memset(memo, -1, sizeof memo);     memset(memo2, -1, sizeof memo2);     std::cout << dp(0, n) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, x, b[110000];   void modify(int x, int y) {     for (; x <= n; x += x & -x) b[x] = ((b[x]) > (y) ? (b[x]) : (y));   }   int get(int x) {     int ans = 0;     for (; x; x -= x & -x) ans = ((ans) > (b[x]) ? (ans) : (b[x]));     return ans;   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &x);       modify(x, get(x) + 1);     }     printf( %d n , get(n));   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, arr[200001], arr2[200001], e, f, g, mn = 1e9, ans, sum, ct, t,                                                       ct2, mx, sum2;   bool kk;   int main() {     cin >> a;     for (int i = 0; i < a; i++) {       cin >> arr[i];       sum += arr[i];     }     for (int i = 0; i < a; i++) {       sum2 += arr[i];       if (sum % 2) {         if (sum2 >= sum / 2 + 1) {           cout << i + 1;           return 0;         }       } else {         if (sum2 >= sum / 2) {           cout << i + 1;           return 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[5], y[5];   int matr[5005][5005];   inline void err() {     for (int i = 0; i <= 5000; ++i)       for (int j = 0; j <= 5000; ++j) matr[i][j] = -1;   }   inline void fil(int i, int j, int ii, int jj, int val) {     for (int a = i; a <= ii; ++a)       for (int b = j; b <= jj; ++b) matr[a][b] = val;   }   int main() {     ios ::sync_with_stdio(false);     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     int S = a * b + c * d + e * f;     int rad = (int)sqrt((double)S);     if (rad * rad != S) {       cout << -1;       exit(0);     }     x[0] = a;     y[0] = b;     x[1] = c;     y[1] = d;     x[2] = e;     y[2] = f;     int lim = 1 << 3;     lim--;     for (int i = 0; i <= lim; ++i) {       for (int j = 0; j <= 3; ++j)         if (i & (1 << j)) swap(x[j], y[j]);       err();       for (int masca = 0; masca <= lim; ++masca) {         if (__builtin_popcount(masca) < 2) continue;         int xx1 = 0;         int m = 0;         m ^= 1;         m ^= 2;         m ^= 4;         int ymax = 0;         int ymin = 1 << 30;         int tx = 0;         int ty = 0;         for (int j = 0; j <= 2; ++j)           if (masca & (1 << j)) {             xx1 += x[j];             m ^= (1 << j);             ymax = max(ymax, y[j]);             ymin = min(ymin, y[j]);           } else {             tx = x[j];             ty = y[j];           }         if (ty != ymax - ymin and ty != rad - ymax) continue;         if (xx1 == rad) {           err();           int lastx = 1;           int lasty = 1;           for (int j = 0; j <= 3; ++j)             if (masca & (1 << j)) {               fil(lastx, lasty, lastx + x[j] - 1, lasty + y[j] - 1, j);               lastx = lastx + x[j];               lasty = 1;             }           int muie = -1;           while (m) {             ++muie;             m >>= 1;           }           cout << rad <<   n ;           for (int i = 1; i <= rad; ++i) {             for (int j = 1; j <= rad; ++j) {               if (matr[i][j] == -1) matr[i][j] = muie;               cout << (char)(matr[i][j] +  A );             }             cout <<   n ;           }           exit(0);         }       }       for (int j = 0; j <= 3; ++j)         if (i & (1 << j)) swap(x[j], y[j]);     }     cout << -1;     exit(0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n[101];   vector<int> cost;   int main() {     int N, B;     cin >> N >> B;     int o, e;     o = e = 0;     for (int i = 0; i < N; i++) {       cin >> n[i];     }     for (int i = 0; i < N; i++) {       if (n[i] % 2)         o++;       else         e++;       if (o == e) {         if (i < N - 1) {           cost.push_back(abs(n[i] - n[i + 1]));         }       }     }     if (o != e) {       cout << 0 << endl;     } else {       sort(cost.begin(), cost.end());       int i = 1, tot = 0;       for (; i <= cost.size(); i++) {         tot += cost[i - 1];         if (tot > B) break;       }       cout << i - 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int root, n;   vector<int> mp[200605];   int Dfs(int u, int from) {     set<int> s;     for (int i = 0; i < mp[u].size(); i++) {       int v = mp[u][i];       if (v == from) continue;       int tmp = Dfs(v, u);       if (tmp == -1) return -1;       s.insert(tmp + 1);     }     if (s.size() == 0) return 0;     if (s.size() == 1) return *s.begin();     if (s.size() == 2) {       if (from == -1) {         int sum = 0;         for (set<int>::iterator it = s.begin(); it != s.end(); it++) {           sum += *it;         }         return sum;       } else {         root = u;         return -1;       }     }     return -1;   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++) mp[i].clear();       for (int i = 1; i <= n - 1; i++) {         int x, y;         scanf( %d%d , &x, &y);         mp[x].push_back(y);         mp[y].push_back(x);       }       root = 1;       int ans = Dfs(root, -1);       if (ans == -1 && root != 1) ans = Dfs(root, -1);       while (ans % 2 == 0) ans /= 2;       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   long long dx[] = {1, 0, -1, 0};   long long dy[] = {0, 1, 0, -1};   long long gcd(long long x, long long y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   long long expo(long long n, long long m, long long p) {     long long r = 1;     n = n % p;     while (m > 0) {       if (m % 2) r = (r * n) % p;       n = (n * n) % p;       m = m / 2;     }     return r % p;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   vector<long long> z_function(string s) {     long long n = (long long)s.length();     vector<long long> z(n);     for (long long i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     return z;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m;     cin >> n >> m;     long long a[n], b[m];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long ans = 0;     for (long long i = 0; i < m; i++) {       cin >> b[i];     }     long long j = 0;     for (long long i = 0; i < n; i++) {       if (a[i] <= b[j]) {         ans++;         j++;       }       if (j == m) break;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 14050;   template <class t>   inline void read(t &s) {     s = 0;     register int f = 1;     register char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();     s *= f;     return;   }   template <class t, class... A>   inline void read(t &x, A &...a) {     read(x);     read(a...);   }   template <class t>   inline void write(t x) {     if (x < 0) putchar( - ), x = -x;     int buf[21], top = 0;     while (x) buf[++top] = x % 10, x /= 10;     if (!top) buf[++top] = 0;     while (top) putchar(buf[top--] ^  0 );     return;   }   inline void setIn(string s) {     freopen(s.c_str(),  r , stdin);     return;   }   inline void setOut(string s) {     freopen(s.c_str(),  w , stdout);     return;   }   inline void setIO(string s =   ) {     setIn(s +  .in );     setOut(s +  .out );     return;   }   template <class t>   inline bool checkmin(t &x, t y) {     if (x > y) {       x = y;       return 1;     }     return 0;   }   template <class t>   inline bool checkmax(t &x, t y) {     if (x < y) {       x = y;       return 1;     }     return 0;   }   inline int lowbit(int x) { return x & (-x); }   int s[2][MaxN], m[2];   int n;   bool vis[2][MaxN], win[2][MaxN];   int cnt[2][MaxN];   inline void dfs(int k, int u) {     if (!win[k][u])       for (int i = 1; i <= m[k ^ 1]; ++i) {         register int nxt = (u - s[k ^ 1][i] - 1 + n) % n + 1;         if (!vis[k ^ 1][nxt])           win[k ^ 1][nxt] = vis[k ^ 1][nxt] = true, dfs(k ^ 1, nxt);       }     else       for (int i = 1; i <= m[k ^ 1]; ++i) {         register int nxt = (u - s[k ^ 1][i] - 1 + n) % n + 1;         if (!vis[k ^ 1][nxt] && ++cnt[k ^ 1][nxt] >= m[k ^ 1])           vis[k ^ 1][nxt] = true, dfs(k ^ 1, nxt);       }     return;   }   signed main(void) {     read(n);     read(m[0]);     for (int i = 1; i <= m[0]; ++i) read(s[0][i]);     read(m[1]);     for (int i = 1; i <= m[1]; ++i) read(s[1][i]);     vis[0][1] = vis[1][1] = true;     dfs(1, 1);     dfs(0, 1);     for (int i = 0; i < 2; ++i, puts(  ))       for (int j = 2; j <= n; ++j)         printf( %s  , (vis[i][j] ? (win[i][j] ?  Win  :  Lose ) :  Loop ));     return 0;   }
/*    Solution by:-     --------------Sannidhay Vashal    ----------------NIT SRINAGAR       */   #include<iostream>   #include<vector>   #include<algorithm>   #include<stack>   #include<queue>   #include<map>   #include<math.h>   #include<climits>   #include<set>   #include<cstring>   #include<unordered_map>   #include <cstdlib>    #include<cmath>       #define fio ios_base::sync_with_stdio(false);cin.tie(NULL)   #define ll            long long int   #define ull           unsigned long long int   #define cinll(x)      ll x;cin>>x;   #define cini(x)       int x;cin>>x;   #define cins(x)       string x;cin>>x;   #define vect(x)       vector<ll> x;   #define vect1(x)      vector<ll> x;x.push_back(0);   #define pb(x)         push_back(x)   #define mp(x,y)       make_pair(x,y)   #define MAX           1e18   #define MIN           -1000000007   #define MOD           1000000007      using namespace std;      bool compare(pair<ll,ll> a,pair<ll,ll> b){     return a.second<b.second;   }      int main(){     cinll(t);     while(t--){       cinll(n);       vector<ll> arr;       unordered_map<ll,ll> mapit;       vector<pair<ll,ll>> ans;       for(ll i=0;i<n;i++) {         cinll(x);         arr.pb(x);         mapit[x]++;       }       ll anss = -1;       for(ll i=0;i<n;i++){         if(mapit[arr[i]]==1) ans.pb(mp(i+1,arr[i]));       }       sort(ans.begin(),ans.end(),compare);       if(ans.size()>=1) anss = ans[0].first;       cout<<anss<<  n ;     }     return 0;   }