malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long Maxn = 1e5 + 7;   const long long Max = 1e3 + 7;   const long long Mod = 1e9 + 7;   const long long Inf = 1e9 + 7;   string s[Maxn], V[Maxn];   long long ans[5];   long long check(char t) {     if (t ==  u  || t ==  o  || t ==  a  || t ==  i  || t ==  e ) return true;     return false;   }   void f(long long a, long long b, long long c, long long d) {     if (V[a] == V[b] && V[c] == V[d])       ;     else       ans[1] = 0;     if (V[a] == V[c] && V[b] == V[d])       ;     else       ans[2] = 0;     if (V[a] == V[d] && V[c] == V[b])       ;     else       ans[3] = 0;     if (V[a] == V[b] && V[c] == V[d] && V[c] == V[b])       ;     else       ans[4] = 0;   }   void print(long long i) {     if (i == 1) cout <<  aabb  << endl;     if (i == 2) cout <<  abab  << endl;     if (i == 3) cout <<  abba  << endl;     if (i == 4) cout <<  aaaa  << endl;   }   int main() {     long long n, k;     cin >> n >> k;     for (long long i = 1; i <= 4 * n; i++) {       cin >> s[i];       long long K = k;       for (long long j = s[i].size() - 1; K && j >= 0; j--) {         V[i] += s[i][j];         if (check(s[i][j])) K--;       }       if (K) {         cout <<  NO  << endl;         return 0;       }     }     ans[1] = ans[2] = ans[3] = ans[4] = 1;     for (long long i = 1; i <= n; i++) {       long long st = (i - 1) * 4;       f(st + 1, st + 2, st + 3, st + 4);     }     for (long long i = 4; i >= 1; i--) {       if (ans[i]) {         print(i);         return 0;       }     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma gcc optimize( Ofast )   using namespace std;   using ll = long long;   const int N = 1e6 + 2;   int n, cnt, f[N], vis[N];   int qt, q[N];   vector<int> v;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     if (n & 1) return cout <<  -1 n , 0;     v.push_back(0);     for (int i = 0; i < n; ++i) {       int a;       cin >> a;       if (a > 0) {         if (f[a] || vis[a]) return cout <<  -1 n , 0;         ++f[a], ++cnt, vis[a] = 1, q[++qt] = a;       } else {         a = -a;         if (!f[a]) return cout <<  -1 n , 0;         --f[a], --cnt;         if (!cnt) {           v.push_back(i + 1);           while (qt) vis[q[qt--]] = 0;         }       }     }     if (cnt) return cout <<  -1 n , 0;     cout << v.size() - 1 <<   n ;     for (int i = 1; i < v.size(); ++i)       cout << v[i] - v[i - 1] <<    n [i + 1 == v.size()];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     cin >> n >> a >> b;     for (int i = 0; (n - a * i) >= 0; i++) {       if ((n - a * i) % b == 0) {         cout <<  YES n ;         cout << i <<     << (n - a * i) / b << endl;         return 0;       }     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void answer() {     int n;     string s, t;     cin >> n >> s >> t;     int ps[26], pt[26];     int cs[26], ct[26];     memset(ps, -1, sizeof(ps));     memset(pt, -1, sizeof(pt));     memset(cs, 0, sizeof(cs));     memset(ct, 0, sizeof(ct));     for (int i = 0; i < s.size(); i++) {       ps[s[i] -  a ] = i;       cs[s[i] -  a ]++;     }     for (int i = 0; i < t.size(); i++) {       pt[t[i] -  a ] = i;       ct[t[i] -  a ]++;     }     for (int i = 0; i < 26; i++) {       if (cs[i] != ct[i]) {         cout <<  NO  <<   n ;         return;       }     }     int c = 0;     for (int i = 0; i < 26; i++) {       if (cs[i] > 1 || ct[i] > 1) {         cout <<  YES  <<   n ;         return;       }       for (int j = i + 1; j < 26; j++) {         c += ((ps[i] < ps[j]) != (pt[i] < pt[j]));       }     }     if (c % 2)       cout <<  NO  <<   n ;     else       cout <<  YES  <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int q;     cin >> q;     for (int i = 0; i < q; i++) answer();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T ABS(T a) {     return a > 0 ? a : -a;   }   template <typename T>   inline T MIN(T a, T b) {     return a < b ? a : b;   }   template <typename T>   inline T MAX(T a, T b) {     return a > b ? a : b;   }   template <typename T>   inline T CHKMIN(T &a, T b) {     if (a > b) a = b;     return a;   }   template <typename T>   inline T CHKMAX(T &a, T b) {     if (a < b) a = b;     return a;   }   template <typename T>   inline void SWAP(T &a, T &b) {     static T c;     c = a;     a = b;     b = c;   }   template <typename T, typename... T0>   T MAX(T a, T b, T0... c) {     return a > b ? MAX(a, c...) : MAX(b, c...);   }   template <typename T, typename... T0>   T MIN(T a, T b, T0... c) {     return a < b ? MIN(a, c...) : MIN(b, c...);   }   template <typename T, int n>   void myin(T a[]) {     for (int i = (0); i < (int)(n); ++i) cin >> a[i];   }   template <typename T>   void myin(T &a) {     cin >> a;   }   template <typename T>   void print(T a) {     cout << a <<    ;   }   template <typename T, typename... T0>   void print(T a, T0... b) {     print(a);     print(b...);   }   template <typename T>   void println(T a) {     cout << a << endl;   }   template <typename T, typename... T0>   void println(T a, T0... b) {     print(a);     println(b...);   }   int n, in[120000];   long long dp[120000];   int main() {     long long sum = 0;     while (cin >> n) {       for (int i = (0); i < (int)(n); ++i) {         scanf( %d , in + i);         sum += in[i];       }       if (sum % 3 != 0) {         puts( 0 );         continue;       }       long long tmp = sum / 3, now = 0, ans = 0;       for (int i = (0); i < (int)(n); ++i) {         now += in[i];         if (i == 0)           dp[i] = 0;         else           dp[i] = dp[i - 1];         if (now == tmp) ++dp[i];       }       tmp += tmp, now = in[0];       for (int i = (1); i < (int)(n - 1); ++i) {         now += in[i];         if (now == tmp) ans += dp[i - 1];       }       println(ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int kN = 1e5 + 10;   const int MOD = 1e9 + 7;   int N, M;   int power(int d, int k) {     int ret = 1, tmp = d;     while (k) {       if (k & 1) {         ret = 1ll * ret * tmp % MOD;       }       tmp = 1ll * tmp * tmp % MOD;       k >>= 1;     }     return ret;   }   void cant() {     printf( 0 );     exit(0);   }   struct Edge {     int u, v;     bool diff;   } es[kN];   struct UFS {     int fa[kN];     int lowbit(int i) { return i & -i; }     void init() {       for (int i = 0; i < kN; i++) fa[i] = i;     }     int getFa(int i) {       if (fa[i] != i) fa[i] = getFa(fa[i]);       return fa[i];     }     bool isSameFa(int u, int v) {       int uf = getFa(u);       int vf = getFa(v);       return uf == vf;     }     void link(int u, int v) {       int uf = getFa(u);       int vf = getFa(v);       fa[uf] = vf;     }   } ufs;   int col[kN];   vector<int> G[kN];   void dfs(int u, int c) {     if (col[u]) {       if (col[u] != c) cant();       return;     }     col[u] = c;     c = c == 1 ? 2 : 1;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       dfs(v, c);     }   }   int main() {     scanf( %d %d , &N, &M);     for (int i = 1; i <= M; i++) {       int op, u, v;       scanf( %d %d %d , &u, &v, &op);       if (u > v) swap(u, v);       es[i].u = u, es[i].v = v, es[i].diff = !op;     }     ufs.init();     for (int i = 1; i <= M; i++) {       if (es[i].diff == false) {         ufs.link(es[i].u, es[i].v);       }     }     for (int i = 1; i <= M; i++) {       if (es[i].diff) {         int uf = ufs.getFa(es[i].u);         int vf = ufs.getFa(es[i].v);         G[uf].push_back(vf);         G[vf].push_back(uf);       }     }     int cnt = 0;     for (int i = 1; i <= N; i++)       if (ufs.getFa(i) == i && !col[i]) {         dfs(i, 1);         cnt++;       }     int ans = power(2, cnt - 1);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   const int maxn = 100005;   int n, cnt;   int a[maxn], p[maxn];   int main() {     scanf( %d , &n);     p[1] = 1;     for (int i = 2; i <= n; i++)       if (p[i] == 0) {         p[i] = ++cnt;         for (int j = i; j <= n; j += i) a[j] = cnt, p[j] = 1;       }     for (int i = 2; i <= n; i++) printf( %d%c , a[i], i == n ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int CMax = 5002;   const int CMax2 = 100002;   int m, B[CMax], A[CMax2], ats = 0, sk, pr;   int main() {     scanf( %d , &m);     for (int i = 0; i < CMax; i++) {       B[i] = 0;     }     for (int i = 0; i < m; i++) {       scanf( %d , &sk);       B[sk]++;     }     for (int i = 0; i < CMax; i++) {       if (B[i] > 0) {         B[i]--;         A[ats] = i;         ats++;         pr = i;       }     }     for (int i = pr - 1; i >= 0; i--) {       if (B[i] > 0) {         B[i]--;         A[ats] = i;         ats++;       }     }     printf( %d n , ats);     if (ats > 0) {       for (int i = 0; i < ats - 1; i++) {         printf( %d  , A[i]);       }       printf( %d n , A[ats - 1]);     }   }
#include<bits/stdc++.h>   #define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}   using namespace std;       const int mxn=2e5+5,mod=1e9+7;   int dp[mxn][20],a[mxn],nxt[mxn],n;   vector<int>prime_factors[mxn];      void sieve(){    for(int i=2;i<mxn;i++){     if(prime_factors[i].empty()){      nxt[i]=mxn;      for(int j=1;i*j<mxn;j++)       prime_factors[i*j].push_back(i);     }    }   }      void lifting(){    dp[n+1][0]=n+1;       for(int i=n;i>=1;i--){     dp[i][0]=dp[i+1][0];     for(auto x:prime_factors[a[i]]){      dp[i][0]=min(dp[i][0],nxt[x]);      nxt[x]=i;      }    }    for(int i=1;i<=19;i++){     for(int j=1;j<=n+1;j++)      dp[j][i]=dp[dp[j][i-1]][i-1];    }   }         void solve(){    int q,i,j;    cin>>n>>q;    for(i=1;i<=n;i++)     cin>>a[i];    sieve();    lifting();    while(q--){     int l,r;     cin>>l>>r;     int ans=0;     for(i=19;i>=0;i--){      if(dp[l][i]<=r){       ans+=1<<i;       l=dp[l][i];      }     }     cout<<ans+1<<  n ;    }   }         int main(void){    fast;    solve();   }
#include <bits/stdc++.h>   using namespace std;   bool is_pal(string a) {     string b = a;     reverse(b.begin(), b.end());     return b == a;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     string second;     cin >> second;     for (int i = 0; i < second.size(); i++) {       string temp = second;       for (char j =  a ; j <=  z ; j++) {         if (j == second[i]) continue;         temp[i] = j;         if (is_pal(temp)) {           cout <<  YES n ;           return 0;         }       }     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   unordered_map<int, pair<int, int>> resi[50 * 3 + 2];   struct FLOW {     int n, *pre, *dist;     FLOW(int n) : n(n) {       pre = (int *)malloc((n + 2) * sizeof(int));       dist = (int *)malloc((n + 2) * sizeof(int));     }     ~FLOW() {       free(pre);       free(dist);     }     pair<int, int> SAP() {       int flow = 0, cost = 0;       for (; SPFA();) {         for (int i = n + 1; i != n; i = pre[i]) {           assert(resi[pre[i]].count(i));           resi[pre[i]][i].first -= pre[n];           if (resi[i].count(pre[i]))             resi[i][pre[i]].first += pre[n];           else             resi[i][pre[i]] = make_pair(pre[n], -resi[pre[i]][i].second);         }         flow += pre[n];         cost += pre[n] * dist[n + 1];       }       return make_pair(flow, cost);     }     bool SPFA() {       int nn = n + 2, q[nn + 1];       bool v[nn];       int h = 0, l = 1, x;       for (int i = 0; i < nn; i++) dist[i] = (50 * 50 * 50);       memset(pre, -1, nn * sizeof(int));       memset(v, false, nn * sizeof(bool));       dist[n] = 0, pre[n] = -1;       q[0] = n, v[n] = true;       while (l != 0) {         x = q[h];         v[q[h]] = false;         l--;         h = (h + 1) % nn;         for (unordered_map<int, pair<int, int>>::const_iterator ix =                  resi[x].begin();              ix != resi[x].end(); ix++) {           if (ix->second.first == 0) continue;           int i = ix->first, p = ix->second.second;           if (dist[x] + p < dist[i]) {             dist[i] = dist[x] + p;             pre[i] = x;             if (!v[i]) v[q[(h + l++) % nn] = i] = true;           }         }       }       if (pre[n + 1] != -1) {         int flow = (50 * 50 * 50);         for (int i = n + 1; i != n; i = pre[i])           if (resi[pre[i]][i].first < flow) flow = resi[pre[i]][i].first;         pre[n] = flow;       }       return pre[n + 1] != -1;     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     int arr[n][2], t, l, r, v;     for (int i = 0; i < n; i++) arr[i][0] = 1, arr[i][1] = n;     for (int iq = 0; iq < q; iq++) {       cin >> t >> l >> r >> v;       if (t == 1)         for (int i = l - 1; i < r; i++) arr[i][0] = max(arr[i][0], v);       else if (t == 2)         for (int i = l - 1; i < r; i++) arr[i][1] = min(arr[i][1], v);     }     for (int i = 0; i < n; i++) {       resi[3 * n][i] = make_pair(1, 0);       resi[2 * n + i][3 * n + 1] = make_pair(n, 2 * i + 1);       for (int j = 0; j < n; j++) resi[n + i][2 * n + j] = make_pair(1, 0);       for (int j = arr[i][0] - 1; j < arr[i][1]; j++)         resi[i][n + j] = make_pair(1, 0);     }     FLOW flow(3 * n);     pair<int, int> ans = flow.SAP();     if (ans.first != n)       cout << -1 << endl;     else       cout << ans.second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 500500;   long long i, j, k, n, sum, ch, t, ans, num;   long long a[N], b[N], c[N];   void R(long long &x) {     x = 0;     ch = getchar();     while (ch <  0  ||  9  < ch) ch = getchar();     while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();   }   int main() {     R(n);     for (i = 1; i <= n; i++) {       R(a[i]);       R(b[i]);       c[i] = a[i] ^ b[i];       sum ^= a[i];     }     k = 60;     for (i = 1; i <= n; i++) {       for (j = i + 1; j <= n; j++)         if (c[i] < c[j]) t = c[i], c[i] = c[j], c[j] = t;       if (!c[i]) break;       while (!(c[i] & 1ll << k)) k--;       for (j = i + 1; j <= n; j++)         if (c[j] & 1ll << k) c[j] ^= c[i];     }     num = i - 1;     ans = 1ll << num;     j = 60;     for (i = 1; i <= num; i++) {       while (!(c[i] & 1ll << j)) j--;       if (sum & 1ll << j) sum ^= c[i];     }     if (sum)       puts( 1/1 );     else       printf( %I64d/%I64d n , ans - 1, ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     int answer = 0;     int f[n];     for (int i = 0; i < n; i++) cin >> f[i];     sort(f, f + n);     for (int i = n - 1; i >= 0; i -= k) answer += (2 * (f[i] - 1));     cout << answer << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[102];   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     puts((n % 2 == 1) && (a[0] % 2 == 1) && (a[n - 1] % 2 == 1) ?  Yes  :  No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 100000;   const int N = 1e5 + 5;   const int K = 135;   const int MOD = 1e9 + 7;   int n, first[N], incr[N], x[K];   long long pw[K][N];   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       incr[x]++;     }     for (int i = 1; i < K; ++i) pw[i][0] = 1;     for (int i = 0; i < N; ++i) pw[0][i] = 1;     for (int j = 1; j < N; ++j)       for (int i = 0; i < K; ++i) pw[i][j] = pw[i][j - 1] * i % MOD;     for (int i = MX; i >= 1; --i) first[i] = first[i + 1] + incr[i];     long long ans = 0;     for (int i = MX; i >= 1; --i)       if (first[i]) {         vector<int> d1, d2, d;         int dd = 1;         for (; dd * dd < i; ++dd)           if (i % dd == 0) {             d1.push_back(dd);             d2.push_back(i / dd);           }         if (dd * dd == i) d1.push_back(dd);         reverse(d2.begin(), d2.end());         merge(d1.begin(), d1.end(), d2.begin(), d2.end(), back_inserter(d));         int prev = 0;         long long p1 = 1, p2 = 1;         for (int j = (int)d.size() - 1; j >= 0; --j) {           x[j + 1] = first[d[j]] - prev;           prev += x[j + 1];           p1 = p1 * pw[j + 1][x[j + 1]] % MOD;           if (j + 1 == d.size())             p2 = p2 * pw[j][x[j + 1]] % MOD;           else             p2 = p2 * pw[j + 1][x[j + 1]] % MOD;         }         ans += p1 - p2;         ans %= MOD;         if (ans < 0) ans += MOD;       }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     vector<int> z[26];     string a, b;     cin >> a >> b;     for (int i = 0; i < a.size(); ++i) z[a[i] -  a ].push_back(i);     bool ok = true;     for (int i = 0; i < b.size(); ++i) {       if (z[b[i] -  a ].size() == 0) {         ok = false;         break;       }     }     if (!ok) {       cout << -1 << endl;     } else {       int cnt = 1, cur = -1;       for (int i = 0; i < b.size(); ++i) {         vector<int> &tmp = z[b[i] -  a ];         vector<int>::iterator iter = upper_bound(tmp.begin(), tmp.end(), cur);         if (iter == tmp.end()) {           ++cnt;           cur = tmp[0];         } else {           cur = *iter;         }       }       cout << cnt << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double a, v, l, d, w, t1, t2, t3, t4, t5, dis1, dis2, dis3, v1;   double chuli(double x) {     double diss = (v + w) * ((v - w) / a) / 2;     if (diss >= x)       return (-2.0 * w + sqrt(4.0 * w * w + 8.0 * a * (x))) / (2.0 * a);     else       return (v - w) / a + (x - diss) / v;   }   int main() {     cin >> a >> v >> l >> d >> w;     if (v >= w) {       t1 = w / a;       dis1 = a * t1 * t1 / 2;       v1 = a * sqrt(2 * d / a);       if (dis1 >= l)         printf( %.12lf n , sqrt(2.0 * l / a));       else if (dis1 >= d)         printf( %.12lf n , t1 + chuli(l - dis1));       else {         dis2 = 2 * (v - w) / a * w + (v - w) * (v - w) / a;         if (dis1 + dis2 >= d) {           t2 = 2.0 * (-2.0 * w + sqrt(4.0 * w * w + 4.0 * a * (d - dis1))) /                (2.0 * a);           t3 = chuli(l - d);           printf( %.12lf n , t1 + t2 + t3);         } else {           t2 = v / a;           t3 = (v - w) / a;           t4 = (d - dis2 - dis1) / v;           t5 = chuli(l - d);           printf( %.12lf n , t2 + t3 + t4 + t5);         }       }     } else {       t1 = v / a;       dis1 = a * t1 * t1 / 2;       if (dis1 < l)         t2 = (l - dis1) / v;       else {         t1 = sqrt(2 * l / a);         t2 = 0.0;       }       printf( %.12lf n , t1 + t2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A, B, C, Cans = 214748364, n, r, ansA, ansB;   bool f[1000010];   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   void Work() {     int t, i, a = A, b = B;     for (C = 0; A != 1 || B != 1;) {       if (A > B) {         f[++C] = 0;         A -= B;       } else {         f[++C] = 1;         B -= A;       }       if (C > n) break;     }     f[++C] = 0;     if (C == n) {       t = 0;       for (int i = 2; i <= C; ++i)         if (f[i] == f[i - 1]) ++t;       if (t < Cans) Cans = t, ansA = a, ansB = b;     }   }   void out() {     if (Cans == 214748364)       printf( IMPOSSIBLE n );     else {       printf( %d n , Cans);       A = ansA, B = ansB;       Work();       for (int i = n; i >= 2; --i) printf( %c , f[i] ?  B  :  T );       printf( %c n , f[1] ?  B  :  T );     }   }   int main() {     int i;     scanf( %d%d , &n, &r);     for (int i = 1; i <= r; ++i)       if (gcd(i, r) == 1) {         A = i, B = r;         Work();         A = r, B = i;         Work();       }     out();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char mat[1501][1501];   int visited[1501][1501][3];   int getr(int x) { return (x % n + n) % n; }   int getc(int x) { return (x % m + m) % m; }   int dx[] = {0, -1, 0, 1};   int dy[] = {-1, 0, 1, 0};   bool dfs(int lx, int ly) {     int x = getr(lx), y = getc(ly);     if (visited[x][y][0] && (lx != visited[x][y][1] || ly != visited[x][y][2]))       return 1;     if (mat[x][y] ==  #  || visited[x][y][0]) return 0;     visited[x][y][0] = 1;     visited[x][y][1] = lx;     visited[x][y][2] = ly;     for (int i = 0; i < 4; ++i) {       if (dfs(lx + dx[i], ly + dy[i])) return 1;     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     while (cin >> n >> m) {       int sx, sy;       memset(visited, 0, sizeof(visited));       for (int i = 0; i < n; ++i) {         for (int j = 0; j < m; ++j) {           cin >> mat[i][j];           if (mat[i][j] ==  S ) sx = i, sy = j;         }       }       if (dfs(sx, sy))         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   vector<long long> prime;   bool num[1000005 + 2];   void sieve() {     num[0] = true;     num[1] = true;     for (long long i = 2; i <= 1000005; i++) {       if (num[i] == false) {         prime.push_back(i);         for (long long j = 2 * i; j <= 1000005; j = j + i) {           num[j] = true;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m, i, j, k, l, a, b, c, p, q, r, t, ans, sum;     cin >> t;     vector<pair<long long, long long> > v;     while (t--) {       cin >> n;       m = n;       j = 0;       while (n--) {         cin >> k >> a;         b = a + 1;         c = b + 1;         for (i = 1; i < k; i++) {           cin >> a;           if (a >= c) {             b = b + (a - c) + 1;             c = a + 2;           } else             c++;         }         v.push_back(make_pair(b, k));       }       sort(v.begin(), v.end());       b = v[0].first + v[0].second;       a = v[0].first;       for (i = 1; i < m; i++) {         if (v[i].first > b) {           c = v[i].first - b;           b = v[i].first + v[i].second;           a = a + c;         } else {           b = b + v[i].second;         }       }       cout << a << endl;       v.clear();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int inf = 1e9;   const int mod = 1e9 + 7;   const int maxn = 5e5 + 10;   int n;   int a[1010], b[1010];   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       cin >> b[i];     }     int ans = 0;     for (int i = 1; i <= n; i++) {       int r1 = 0, r2 = 0;       for (int j = i; j <= n; j++) {         r1 |= a[j];         r2 |= b[j];         ans = max(r1 + r2, ans);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, c;     cin >> n >> a >> b >> c;     long long res = 0;     for (int i = 0; i <= a; ++i) {       for (int j = 0; j <= b; ++j) {         if (2 * n - i - 2 * j >= 0 && !((2 * n - i - 2 * j) % 4) &&             2 * n - i - 2 * j <= 4 * c) {           ++res;         }       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   const int MAXN = (int)1e5 + 5;   const int MODN = (int)1e9 + 7;   int inf = 0x3f3f3f3f;   using namespace std;   char str[MAXN];   int num[MAXN];   int a[MAXN];   struct Com {     int cost;     int qua;   } c[MAXN];   int cmp(Com a, Com b) { return a.cost < b.cost; }   int main() {     int n, m;     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; i++) {         scanf( %d%d , &c[i].cost, &c[i].qua);       }       sort(c, c + n, cmp);       int flag = 0;       for (int i = 1; i < n; i++) {         if (c[i].qua < c[i - 1].qua && c[i].cost > c[i - 1].cost) {           flag = 1;         }       }       if (flag)         puts( Happy Alex );       else         puts( Poor Alex );     }   }