malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e17;   long long n, k, niv[200005];   vector<long long> muchii[200005];   bool isleaf[200005], used[200005];   long long red, blue, par[200005];   vector<long long> line;   long long timp, in[200005], out[200005];   struct date {     long long minim, best;   } arb[1400005];   long long lazy[1400005];   void dfs(int nod) {     if (nod == 1)       niv[nod] = 1;     else if (muchii[nod].size() == 1)       isleaf[nod] = 1;     timp++;     line.push_back(nod);     in[nod] = timp;     for (auto i : muchii[nod])       if (i != par[nod]) {         niv[i] = niv[nod] + 1;         par[i] = nod;         dfs(i);       }     out[nod] = timp;   }   void prop(int nod) {     long long val = lazy[nod];     arb[nod * 2].minim += val;     arb[nod * 2 + 1].minim += val;     lazy[nod * 2] += val;     lazy[nod * 2 + 1] += val;   }   void update(int nod, int st, int dr, int a, int b, long long val) {     if (lazy[nod] != 0 && st != dr) prop(nod);     lazy[nod] = 0;     if (st >= a && dr <= b) {       arb[nod].minim += val;       if (st == dr && isleaf[line[st]])         arb[nod].best = line[st];       else         lazy[nod] += val;       return;     }     int mij = (st + dr) / 2;     if (a <= mij) update(nod * 2, st, mij, a, b, val);     if (b > mij) update(nod * 2 + 1, mij + 1, dr, a, b, val);     arb[nod].minim = arb[nod].best = 0;     if (arb[nod * 2].best > 0 && arb[nod * 2].minim > arb[nod].minim)       arb[nod] = arb[nod * 2];     if (arb[nod * 2 + 1].best > 0 && arb[nod * 2 + 1].minim > arb[nod].minim)       arb[nod] = arb[nod * 2 + 1];   }   int main() {     cin >> n >> k;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       muchii[a].push_back(b);       muchii[b].push_back(a);     }     line.push_back(0);     dfs(1);     for (int i = 1; i <= n; i++) update(1, 1, n, in[i], in[i], niv[i]);     long long ans = -INF;     blue = n;     red = 0;     while (red <= k) {       long long val = red * (n - red);       long long x = min(n / 2, blue);       val -= x * (n - x);       ans = max(ans, val);       long long nod = arb[1].best;       red++;       while (nod > 0 && !used[nod]) {         used[nod] = 1;         update(1, 1, n, in[nod], out[nod], -1);         blue--;         nod = par[nod];       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int g[65]{0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,  4,  5,  5,  5,  5, 5, 5,             6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,  7,  8,  8,  8,  8, 8, 8,             8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10};   const int MAXN = 1000007;   int s[MAXN];   map<pair<int, long long>, int> dp;   int grundy(pair<int, long long> s) {     if (dp.find(s) != dp.end()) return dp[s];     long long mask = s.second;     int &res = dp[s];     set<int> S;     for (int i = 1; i <= 60; i++) {       if (!(mask & (1ll << i)) && s.first >= i) {         S.insert(grundy(make_pair(s.first - i, (mask | (1ll << i)))));       }     }     while (S.count(res) > 0) res++;     return res;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &s[i]);     }     if (n == 1)       printf( NO n );     else {       int XOR = 0;       for (int i = 0; i < n; i++) {         XOR ^= grundy(make_pair(s[i], 0));       }       if (XOR == 0)         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void cline() { cout <<   n ; }   template <typename T, typename... V>   void cline(T t, V... v) {     cout << t;     if (sizeof...(v)) cout <<    ;     cline(v...);   }   void cspc() { cout <<    ; }   template <typename T, typename... V>   void cspc(T t, V... v) {     cout << t;     if (sizeof...(v)) cout <<    ;     cspc(v...);   }   int n;   int a[105];   int dp[104][52][52][2];   int calc(int indx, int even, int odd, int pre) {     if (indx == n) return 0;     if (dp[indx][even][odd][pre] != -1) return dp[indx][even][odd][pre];     if (indx == 0) {       if (a[indx] == 0) {         if (even == 0) {           return dp[indx][even][odd][pre] = calc(indx + 1, even, odd - 1, 1);         } else if (odd == 0) {           return dp[indx][even][odd][pre] = calc(indx + 1, even - 1, odd, 0);         } else {           return dp[indx][even][odd][pre] = min(calc(indx + 1, even, odd - 1, 1),                                                 calc(indx + 1, even - 1, odd, 0));         }       } else {         return dp[indx][even][odd][pre] = calc(indx + 1, even, odd, a[indx] % 2);       }     } else {       if (a[indx] == 0) {         if (even == 0) {           if (pre % 2 == 0) {             return dp[indx][even][odd][pre] =                        calc(indx + 1, even, odd - 1, 1) + 1;           } else {             return dp[indx][even][odd][pre] = calc(indx + 1, even, odd - 1, 1);           }         } else if (odd == 0) {           if (pre % 2 == 1) {             return dp[indx][even][odd][pre] =                        calc(indx + 1, even - 1, odd, 0) + 1;           } else {             return dp[indx][even][odd][pre] = calc(indx + 1, even - 1, odd, 0);           }         } else {           if (pre % 2 != 0) {             return dp[indx][even][odd][pre] =                        min(calc(indx + 1, even, odd - 1, 1),                            calc(indx + 1, even - 1, odd, 0) + 1);           } else {             return dp[indx][even][odd][pre] =                        min(calc(indx + 1, even, odd - 1, 1) + 1,                            calc(indx + 1, even - 1, odd, 0));           }         }       } else {         if (a[indx] % 2 != pre % 2) {           return dp[indx][even][odd][pre] =                      calc(indx + 1, even, odd, a[indx] % 2) + 1;         } else {           return dp[indx][even][odd][pre] =                      calc(indx + 1, even, odd, a[indx] % 2);         }       }     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     int even = n / 2, odd = (n + 1) / 2;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] % 2 == 0)         even--;       else         odd--;       if (a[i] == 0) even++;     }     for (int in1 = 0; in1 < 104; in1++) {       for (int in2 = 0; in2 < 52; in2++) {         for (int in3 = 0; in3 < 52; in3++) {           dp[in1][in2][in3][0] = -1;           dp[in1][in2][in3][1] = -1;         }       }     }     cspc(calc(0, even, odd, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 3;   int n, m, dp[N], vis[2][N];   vector<int> adj[2][N];   vector<pair<int, int>> e;   void dfs(int u, int dir) {     vis[dir][u] = 1;     for (int v : adj[dir][u])       if (!vis[dir][v]) dfs(v, dir);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0, u, v; i < m; i++) {       cin >> u >> v;       adj[0][u].push_back(v);       adj[1][v].push_back(u);       e.push_back({u, v});     }     dfs(1, 0), dfs(n, 1);     for (int i = 0; i < n - 1; i++)       for (auto [u, v] : e)         if (vis[0][u] & vis[1][v]) {           dp[u] = min(dp[u], dp[v] + 2);           dp[v] = min(dp[v], dp[u] - 1);         }     for (auto [u, v] : e)       if (vis[0][u] & vis[1][v] & (dp[u] > dp[v] + 2 || dp[v] > dp[u] - 1))         return cout <<  No  << endl, 0;     cout <<  Yes  << endl;     for (auto [u, v] : e)       cout << (vis[0][u] & vis[1][v] ? dp[u] - dp[v] : 1) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 10;   long long a[maxn], b[maxn], ans[maxn];   int32_t main() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + n);     if (b[0] == b[n - 1]) {       if (b[0] == 0) {         cout <<  YES  <<   n ;         for (long long i = 0; i < n; i++) cout <<  1  ;       } else         cout <<  NO ;       exit(0);     }     long long pos = -1, mx = b[n - 1];     for (long long i = 0; i < n; i++) {       if (a[i] == mx && a[(i - 1 + n) % n] != mx) pos = i;     }     ans[pos] = a[pos];     bool bad = 1;     for (long long i = (pos - 1 + n) % n; i != pos; i = (i - 1 + n) % n) {       if (a[i] == 0 && bad)         ans[i] = ans[(i + 1) % n] * 2LL, bad = 0;       else         ans[i] = ans[(i + 1) % n] + a[i];     }     cout <<  YES  <<   n ;     for (long long i = 0; i < n; i++) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 105;   long long l, r, dp[N];   long long gao(long long n) {     long long m = n, ans = 0;     int bit[N], len = 0;     while (n) {       bit[++len] = n % 2;       n /= 2;     }     for (int i = 2; i < len; i++) {       memset(dp, 0, sizeof(dp));       dp[1] = 1;       for (int j = 2; j < i; j++) {         if (i % j) continue;         dp[j] += 1LL << (j - 1);       }       for (int j = 1; j <= i; j++) {         for (int k = 2; k * j < i; k++)           if (i % (k * j) == 0) dp[j * k] -= dp[j];       }       for (int j = 1; j <= i; j++) ans += dp[j];     }     for (int i = len; i <= len; i++) {       memset(dp, 0, sizeof(dp));       for (int j = 1; j < i; j++) {         if (i % j) continue;         for (int k = len; k > len - j; k--) {           if (k != len && bit[k] == 1) {             dp[j] += 1LL << (k - (len - j) - 1);           }         }         long long sum = 0;         for (int k = len; k > len - j; k--) {           if (bit[k] == 0) continue;           for (int r = k; r > 0; r -= j) {             sum += 1LL << (r - 1);           }         }         if (sum <= m) dp[j]++;       }       for (int j = 1; j <= i; j++) {         for (int k = 2; k * j < i; k++)           if (i % (k * j) == 0) dp[j * k] -= dp[j];       }       for (int j = 1; j <= i; j++) ans += dp[j];     }     return ans;   }   int main() {     while (cin >> l >> r) {       cout << gao(r) - gao(l - 1) << endl;     }     return 0;   }
#include <bits/stdc++.h>   int setBit(int N, int pos) { return N = N | (1 << pos); }   int resetBit(int N, int pos) { return N = N & ~(1 << pos); }   bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); }   using namespace std;   const int maxn = 100000;   int n, m, cost[maxn + 5], okayRoad[maxn + 5], par[maxn + 5];   vector<int> graph[maxn + 5], flag[maxn + 5];   map<pair<int, int>, int> mapp, out;   map<pair<int, int>, int>::iterator it;   void bfs() {     queue<int> q;     int i, u, v;     memset(cost, 63, sizeof(cost));     ;     cost[1] = 0;     par[1] = 1;     q.push(1);     while (!q.empty()) {       u = q.front();       q.pop();       int siz = (int)graph[u].size();       for (i = 0; i < siz; i++) {         v = graph[u][i];         if (cost[u] + 1 < cost[v]) {           cost[v] = cost[u] + 1;           okayRoad[v] = okayRoad[u] + flag[u][i];           par[v] = u;           q.push(v);         } else if (cost[u] + 1 == cost[v] &&                    okayRoad[u] + flag[u][i] > okayRoad[v]) {           okayRoad[v] = okayRoad[u] + flag[u][i];           par[v] = u;           q.push(v);         }       }     }   }   void giveOutput() {     int u, v = n;     vector<int> path;     path.push_back(n);     while (v != par[v]) {       v = par[v];       path.push_back(v);     }     int i, j, siz = (int)path.size();     for (i = 1; i < siz; i++) {       u = path[i - 1];       v = path[i];       if (u > v) swap(u, v);       if (mapp[pair<int, int>(u, v)] == 0) out[pair<int, int>(u, v)] = 1;       mapp[pair<int, int>(u, v)] = -1;     }     for (__typeof((mapp).begin()) it = (mapp).begin(); it != (mapp).end(); it++) {       if (it->second == 1) out[it->first] = 0;     }     printf( %d n , (int)out.size());     for (__typeof((out).begin()) it = (out).begin(); it != (out).end(); it++) {       cout << it->first.first <<     << it->first.second <<     << it->second            <<   n ;     }   }   int main() {     int i, u, v, w;     scanf( %d %d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d %d %d , &u, &v, &w);       if (u > v) swap(u, v);       graph[u].push_back(v);       graph[v].push_back(u);       flag[u].push_back(w);       flag[v].push_back(w);       mapp[pair<int, int>(u, v)] = w;     }     bfs();     giveOutput();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[301][301], h, w, dp[301][301];   int used[601][601];   int dx[] = {0, 1, -1, 0, 0, 1, -1, 1, -1};   int dy[] = {0, 0, 0, 1, -1, 1, 1, -1, -1};   int read() {     int x;     scanf( %d , &x);     return x;   }   bool check(int x, int y) {     if (x >= 1 && x <= h && y >= 1 && y <= w && !used[x][y])       return true;     else       return false;   }   void dfs(int x, int y, int component) {     used[x][y] = component;     for (int i = 1; i <= 8; i++) {       int kx = dx[i] + x, ky = dy[i] + y;       if (check(kx, ky) && a[x][y] == a[kx][ky]) {         dfs(kx, ky, component);       }     }   }   void init() {     for (int i = 0; i <= 600; i++) {       for (int j = 0; j <= 600; j++) {         used[i][j] = 0;       }     }   }   int main() {     int q;     q = read();     while (q--) {       h = read(), w = read();       init();       for (int i = 1; i <= h; i++) {         for (int j = 1; j <= w; j++) {           a[i][j] = read();         }       }       int cntfirst = 0, cntsecond = 0;       for (int i = 1; i <= h; i++) {         for (int j = 1; j <= w; j++) {           if (!used[i][j]) dfs(i, j, cntfirst + 1), cntfirst++;         }       }       for (int i = h / 2 + 1; i <= h; i++) {         for (int j = 1; j <= w; j++) {           dp[i - h / 2][j] = a[i][j];         }       }       for (int i = 1; i <= h / 2; i++) {         for (int j = 1; j <= w; j++) {           dp[i + h / 2][j] = a[i][j];         }       }       for (int i = 1; i <= h; i++) {         for (int j = 1; j <= w; j++) {           a[i][j] = dp[i][j];         }       }       init();       for (int i = 1; i <= h; i++) {         for (int j = 1; j <= w; j++) {           if (!used[i][j]) dfs(i, j, cntsecond + 1), cntsecond++;         }       }       if (cntfirst <= cntsecond) {         printf( NO n );       } else {         printf( YES n );       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 22e4;   char s[N * 2];   int l[N * 2], r[N * 2];   int main() {     ios::sync_with_stdio(0);     int n, k;     cin >> n >> k >> s;     for (int i = 0; i < n; i++) s[i + n] = s[i];     for (int i = 0, lx = -2e9; i < n * 2; i++) {       if (s[i] == s[i + 1]) lx = i + 1;       l[i + 1] = lx;     }     for (int i = n * 2 - 1, rx = 2e9; i > 0; i--) {       if (s[i] == s[i - 1]) rx = i - 1;       r[i - 1] = rx;     }     for (int i = 0; i < n; i++) {       if (i + n - l[i + n] < r[i] - i) {         if (i + n - l[i + n] <= k)           cout << s[l[i + n]];         else if (k & 1)           cout << (s[i] ==  W  ?  B  :  W );         else           cout << s[i];       } else {         if (r[i] - i <= k)           cout << s[r[i]];         else if (k & 1)           cout << (s[i] ==  W  ?  B  :  W );         else           cout << s[i];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int p, d;     cin >> p >> d;     long long int temp = 1;     long long int po[19];     for (int i = 0; i <= 18; ++i) {       po[i] = temp;       temp *= 10;     }     int i = 1;     temp = p;     while (1) {       long long int t = temp % po[i];       t /= po[i - 1];       long long int x = temp;       x -= (t * po[i - 1]);       x += (9 * po[i - 1]);       if (p - x >= 0 && p - x <= d) {         i++;         temp = x;         continue;       }       if ((p - x + po[i]) <= d && x - po[i] >= 0) {         x -= po[i];         temp = x;         i++;       } else         break;     }     cout << temp;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[5005], dp[5005], b[5005];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     dp[0] = 0;     for (int i = 1; i <= n; i++) {       int p = i, s = a[i];       while (p > 0 && s < b[p - 1]) {         s += a[p - 1];         p--;       }       dp[i] = dp[p - 1] + i - p;       b[i] = s;     }     printf( %d n , dp[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1e5 + 5;   vector<int> a[maxn];   int res[maxn];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       int q, w;       scanf( %d%d , &q, &w);       a[q].push_back(w);     }     int ms = 0;     for (int i = 1; i <= m; i++) {       int sump = a[i].size();       sort(a[i].begin(), a[i].end());       ms = max(sump, ms);       int sum = 0;       for (int j = sump - 1; j >= 0; j--) {         sum += a[i][j];         if (sum >= 0)           res[sump - j] += sum;         else           break;       }     }     int max1 = 0;     for (int i = 1; i <= ms; i++) max1 = max(res[i], max1);     printf( %d n , max1);   }
#include <bits/stdc++.h>   using namespace std;   long long s(long long x) {     long long sum = 0;     while (x) {       sum += x % 10;       x /= 10;     }     return sum;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long T;     T = 1;     while (T--) {       long long n, i, x, ans = -1;       cin >> n;       x = sqrt(n);       for (i = 1; i <= 90; i++) {         long long l, r;         l = 1;         r = x;         while (l <= r) {           long long m = l + (r - l) / 2;           long long z = m * m + m * i;           if (z == n && s(m) == i)             ans = m, r = m - 1;           else if (z < n)             l = m + 1;           else             r = m - 1;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int N = 4000;   const int INF = 1e9;   struct edge {     int to, c, f, back;     edge(int to, int c, int f, int back) : to(to), c(c), f(f), back(back) {}   };   vector<edge> g[N];   vector<int> d(N), ptr(N);   int n, h, m;   int s, t;   void add_edge(int v, int u, int c) {     g[v].push_back({u, c, 0, (int)g[u].size()});     g[u].push_back({v, 0, 0, (int)g[v].size() - 1});   }   bool bfs() {     fill(d.begin(), d.end(), INF);     d[s] = 0;     queue<int> q;     q.push(s);     while ((int)q.size()) {       int v = q.front();       q.pop();       for (auto i : g[v]) {         if (i.c > i.f && d[i.to] == INF) {           d[i.to] = d[v] + 1;           q.push(i.to);         }       }     }     return d[t] != INF;   }   int dfs(int v, int cur_flow = INF) {     if (v == t || cur_flow == 0) return cur_flow;     for (int i = ptr[v]; i < (int)g[v].size(); i++) {       int u = g[v][i].to;       if (d[v] + 1 == d[u]) {         int push = dfs(u, min(cur_flow, g[v][i].c - g[v][i].f));         if (push) {           g[v][i].f += push;           g[u][g[v][i].back].f -= push;           return push;         }       }       ptr[v]++;     }     return 0;   }   int maxFlow() {     int ret = 0;     while (bfs()) {       int cur = dfs(s);       fill(ptr.begin(), ptr.end(), 0);       while (cur) {         ret += cur;         cur = dfs(s);       }     }     return ret;   }   int get_hash(int x, int y) { return x * 52 + y; }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> h >> m;     s = 0, t = N - 1;     for (int i = 0; i < n; i++) {       add_edge(s, get_hash(i, 0), INF);       for (int j = 0; j <= h; j++) {         add_edge(get_hash(i, j), get_hash(i, j + 1), h * h - j * j);         add_edge(get_hash(i, j + 1), get_hash(i, j), INF);       }       add_edge(get_hash(i, h), t, 0);     }     int st = 50 * 55 + 10;     assert(st + m < N);     for (int i = 0; i < m; i++) {       int l, r, x, c;       cin >> l >> r >> x >> c;       if (x == h) continue;       l--;       r--;       for (int j = l; j <= r; j++) {         add_edge(get_hash(j, x + 1), st + i, INF);       }       add_edge(st + i, t, c);     }     cout << n * h * h - maxFlow() <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n;     int x;     cin >> t;     while (t--) {       cin >> n;       map<int, int> m;       for (int i = 0; i < n; i++) {         cin >> x;         m[x] = 1;       }       cout << m.size() << endl;     }   }
#include <bits/stdc++.h>   int comp(const void *a, const void *b) { return *(int *)a - *(int *)b; }   int min(int a, int b) { return a < b ? a : b; }   int max(int a, int b) { return a > b ? a : b; }   int rev(int n) {     int r = 0;     for (int i = 0; i < 8; i++) r = r | (((n >> i) & 1) << (7 - i));     return r;   }   char c;   int n;   int main() {     int p = 0, t;     while (1) {       scanf( %c , &c);       if (c < 32 || c > 126) break;       t = (256 + rev(p) - rev(c)) % 256;       p = c;       printf( %d n , t);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const long long int mod = 1e9 + 7;   long long int pow(long long int x, long long int y) {     long long int sum = 1;     for (long long int i = 0; i < y; ++i) {       sum *= x;       sum %= mod;     }     return sum;   }   int main(void) {     long long int k, p;     cin >> p >> k;     if (k == 0) {       cout << pow(p, p - 1) << endl;       return 0;     }     if (k == 1) {       cout << pow(p, p) << endl;       return 0;     }     int o = 1;     long long int prod = k;     while (prod != 1) {       prod *= k;       prod %= p;       o++;     }     assert((p - 1) % o == 0);     cout << pow(p, (p - 1) / o) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long sum1 = 0, sum2 = 0;     vector<long long> one, two;     int last = 0;     for (int i = 0; i < n; i++) {       int temp;       scanf( %d , &temp);       if (temp < 0) {         two.push_back(abs(temp));         sum2 += abs(temp);         last = 2;       } else {         one.push_back(temp);         sum1 += temp;         last = 1;       }     }     if (sum1 != sum2) {       if (sum1 > sum2)         puts( first );       else         puts( second );       return 0;     }     for (int i = 0; i < min(one.size(), two.size()); i++) {       if (one[i] != two[i]) {         if (one[i] < two[i])           puts( second );         else if (one[i] > two[i])           puts( first );         return 0;       }     }     if (one.size() != two.size()) {       if (one.size() > two.size())         puts( first );       else         puts( second );       return 0;     }     if (last == 1)       puts( first );     else       puts( second );   }
#include <bits/stdc++.h>   using namespace std;   const int MXN = 300300;   int n, a[MXN], match[MXN], cnt[MXN];   map<int, int> prevMatch[MXN];   int main() {     int T;     scanf( %d , &T);     for (int t = 1; t <= T; ++t) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) {         scanf( %d , &a[i]);         match[i] = cnt[i] = 0;         prevMatch[i].clear();       }       for (int i = 2; i <= n; ++i) {         if (a[i] == a[i - 1]) {           match[i] = i - 1;         } else {           match[i] = max(0, prevMatch[i - 1][a[i]]);         }         if (match[i] > 1) {           swap(prevMatch[i], prevMatch[match[i] - 1]);           prevMatch[i][a[match[i] - 1]] = match[i] - 1;         }       }       long long res = 0;       for (int i = 2; i <= n; ++i) {         if (match[i] == 0) continue;         cnt[i] = cnt[match[i] - 1] + 1;         res += cnt[i];       }       cout << res <<   n ;     }     fclose(stdin);     return 0;   }