malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m;     cin >> n >> m;     for (long long int i = 0; i < n; i += 1) {       long long int s, f, t;       cin >> s >> f >> t;       long long int q = t / (m - 1);       long long int r = t % (m - 1);       if (s == f) {         cout << t <<   n ;         continue;       }       if (q % 2 == 0) {         long long int floor = r + 1;         if (s >= floor) {           t += (s - floor);           if (f >= s) {             t += (f - s);           } else {             t += (m - s) + (m - f);           }         } else {           t += (m - floor) + (m - s);           if (f > s) {             t += (s - 1) + (f - 1);           } else {             t += (s - f);           }         }       } else {         long long int floor = m - r;         if (s <= floor) {           t += (floor - s);           if (f <= s) {             t += (s - f);           } else {             t += (s - 1) + (f - 1);           }         } else {           t += (floor - 1) + (s - 1);           if (f >= s) {             t += (f - s);           } else {             t += (m - s) + (m - f);           }         }       }       cout << t <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 5;   long long add[N << 2], sum[N << 2], color[N << 2];   int n, m;   void down(int rt, int len) {     if (add[rt]) {       add[(rt << 1)] += add[rt];       add[(rt << 1 | 1)] += add[rt];       sum[(rt << 1)] += add[rt] * (len - (len >> 1));       sum[(rt << 1 | 1)] += add[rt] * (len >> 1);       add[rt] = 0;       color[(rt << 1)] = color[(rt << 1 | 1)] = color[rt];       color[rt] = 0;     }   }   void build(int rt, int l, int r) {     if (l == r) {       color[rt] = l;       return;     }     int mid = (l + r) >> 1;     build((rt << 1), l, mid);     build((rt << 1 | 1), mid + 1, r);   }   void modify(int rt, int l, int r, int L, int R, int x) {     if (L <= l && r <= R && color[rt]) {       add[rt] += abs(color[rt] - x);       sum[rt] += (r - l + 1) * abs(color[rt] - x);       color[rt] = x;       return;     }     down(rt, r - l + 1);     int mid = (l + r) >> 1;     if (L <= mid) modify((rt << 1), l, mid, L, R, x);     if (mid < R) modify((rt << 1 | 1), mid + 1, r, L, R, x);     color[rt] = (color[(rt << 1)] == color[(rt << 1 | 1)]) ? color[(rt << 1)] : 0;     sum[rt] = sum[(rt << 1)] + sum[(rt << 1 | 1)];   }   long long query(int rt, int l, int r, int L, int R) {     if (L <= l && r <= R) {       return sum[rt];     }     down(rt, r - l + 1);     long long t = 0ll;     int mid = (l + r) >> 1;     if (L <= mid) t += query((rt << 1), l, mid, L, R);     if (mid < R) t += query((rt << 1 | 1), mid + 1, r, L, R);     return t;   }   int main() {     scanf( %d%d , &n, &m);     build(1, 1, n);     while (m--) {       int op, l, r, x;       scanf( %d , &op);       if (op == 1) {         scanf( %d%d%d , &l, &r, &x);         modify(1, 1, n, l, r, x);       } else {         scanf( %d%d , &l, &r);         printf( %I64d n , query(1, 1, n, l, r));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool f[9000000];   int a[30];   bool check(int sta, int i) {     if (sta & (1 << (i - 1)))       ;     else       return false;     for (int j = 0; j < i; j++)       if (sta & (1 << j))         for (int k = j; k < i; k++)           if (sta & (1 << k))             if (a[j] + a[k] == a[i]) return true;     return false;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     memset(f, false, sizeof(f));     f[1] = true;     for (int i = 1; i < n; i++) {       int l = 1 << i, r = 1 << (i + 1);       for (int j = l; j < r; j++)         if (f[j - l] && check(j, i)) {           f[j] = true;           for (int k = 0; k < i; k++) f[j & (~(1 << k))] = true;         }     }     int ans = 30;     for (int i = (1 << (n - 1)); i < (1 << n); i++)       if (f[i]) {         int total = 0;         for (int j = 0; j < n; j++)           if (i & (1 << j)) total++;         ans = ((ans) < (total) ? (ans) : (total));       }     printf( %d n , ans == 30 ? -1 : ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 500 + 1;   int a[maxn], n;   bool check(int r) {     for (int i = 1; i <= n; i++)       if (a[i] % r > 0 && r - 1 - a[i] % r > a[i] / r) return 0;     return 1;   }   long long calc(int r) {     long long res = 0;     for (int i = 1; i <= n; i++) res += a[i] / r + (a[i] % r != 0);     return res;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int res = 1;     for (int i = 1, j, m = a[1]; i <= m; i = j + 1) {       int t = m / i;       j = m / t;       if (check(t + 1)) {         res = t + 1;         break;       }       if (check(t)) {         res = t;         break;       }     }     cout << calc(res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1005;   int n, m, k;   long long s[Maxn][Maxn], sl[Maxn][Maxn], sr[Maxn][Maxn];   inline int get() {     char ch;     while (!isdigit(ch = getchar()))       ;     int v = ch - 48;     while (isdigit(ch = getchar())) v = v * 10 + ch - 48;     return v;   }   int main() {     n = get();     m = get();     k = get();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         s[i][j] = get() + s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         sl[i][j] =             sl[i - 1][j - 1] + s[i][j] - (i > k && j > k ? s[i - k][j - k] : 0);         sr[i][j] = sr[i - 1][j + 1] + s[i][j] -                    (i > k && j + k <= m ? s[i - k][j + k] : 0);       }       sr[i][0] = sr[i - 1][1] + s[i][0] - (i > k ? s[i - k][k] : 0);     }     int wx = 0, wy = 0;     long long maxv = -1;     for (int i = k; i <= n - k + 1; i++)       for (int j = k; j <= m - k + 1; j++) {         long long v = sr[i + k - 1][j] + sr[i - 1][j - k] - sl[i - 1][j + k - 1] -                       sl[i + k - 1][j - 1];         if (maxv < v) maxv = v, wx = i, wy = j;       }     cout << wx <<     << wy << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum[3] = {0};     cin >> n;     int *x = new int[n], *y = new int[n], *z = new int[n];     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i] >> z[i];       sum[0] += x[i];       sum[1] += y[i];       sum[2] += z[i];     }     if (sum[0] == 0 && sum[1] == 0 && sum[2] == 0)       cout <<  YES ;     else       cout <<  NO ;     delete[] x;     delete[] y;     delete[] z;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct man {     long long int m, s, I;   };   man a[131072];   bool cmp(man a, man b) {     if (a.m < b.m) return true;     if (a.m > b.m) return false;     if (a.I > b.I) return true;     if (a.I < b.I) return false;   }   int main() {     queue<man> x;     long long int n, d, i, tbr = 0, maxbr = 0;     cin >> n >> d;     for (i = 0; i < n; i++) {       cin >> a[i].m >> a[i].s;       a[i].I = i;     }     sort(a, a + n, cmp);     for (i = 0; i < n; i++) {       x.push(a[i]);       struct man m = x.front(), m2 = x.back();       while (m2.m - m.m >= d) {         tbr -= m.s;         x.pop();         m = x.front();         m2 = x.back();       }       tbr += m2.s;       if (tbr > maxbr) maxbr = tbr;     }     cout << maxbr << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long long INF = 1000000000;   struct wie {     int il_50, il_100, str;   };   int main() {     ios_base::sync_with_stdio(0);     int n, k;     cin >> n >> k;     int p = 0, s = 0;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (x == 50)         ++p;       else         ++s;     }     vector<vector<long long> > C(51, vector<long long>(51));     for (int i = 0; i <= 50; ++i) {       for (int j = 0; j <= i; ++j) {         if (j == 0 || j == i)           C[i][j] = 1;         else           C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;       }     }     long long il[51][51][2];     long long odl[51][51][2];     bool odw[51][51][2];     for (int i = 0; i < 51; ++i) {       for (int j = 0; j < 51; ++j) {         for (int l = 0; l < 2; ++l) {           odw[i][j][l] = false;           odl[i][j][l] = -1;         }       }     }     queue<wie> Q;     Q.push({p, s, 1});     odw[p][s][1] = true;     while (!Q.empty()) {       wie akt = Q.front();       Q.pop();       if (akt.il_100 == s && akt.il_50 == p && akt.str == 1) {         odl[akt.il_50][akt.il_100][akt.str] = 0;         il[akt.il_50][akt.il_100][akt.str] = 1;         for (int i = 0; i <= akt.il_50; ++i) {           for (int j = 0; j <= akt.il_100; ++j) {             wie nowy = {p - akt.il_50 + i, s - akt.il_100 + j, (akt.str ^ 1)};             if (i + j != 0 && 50 * i + 100 * j <= k) {               Q.push(nowy);               odw[nowy.il_50][nowy.il_100][nowy.str] = true;             }           }         }       } else {         odl[akt.il_50][akt.il_100][akt.str] = INF;         il[akt.il_50][akt.il_100][akt.str] = 0;         for (int i = 0; i <= akt.il_50; ++i) {           for (int j = 0; j <= akt.il_100; ++j) {             wie nowy = {p - akt.il_50 + i, s - akt.il_100 + j, (akt.str ^ 1)};             if (i + j != 0 && 50 * i + 100 * j <= k) {               if (odw[nowy.il_50][nowy.il_100][nowy.str]) {                 if (odl[nowy.il_50][nowy.il_100][nowy.str] != -1) {                   odl[akt.il_50][akt.il_100][akt.str] =                       min(odl[akt.il_50][akt.il_100][akt.str],                           odl[nowy.il_50][nowy.il_100][nowy.str] + 1);                   il[akt.il_50][akt.il_100][akt.str] =                       (il[akt.il_50][akt.il_100][akt.str] +                        (C[akt.il_50][i] * C[akt.il_100][j]) % MOD *                            il[nowy.il_50][nowy.il_100][nowy.str]) %                       MOD;                 }               } else {                 Q.push(nowy);                 odw[nowy.il_50][nowy.il_100][nowy.str] = true;               }             }           }         }       }     }     if (odw[p][s][0])       cout << odl[p][s][0] <<     << il[p][s][0];     else       cout <<  -1 0 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1000 + 10, M = 998244353;   int t;   int n, m, q;   bool locked[N][N];   long long num[N][N][2];   long long ans = 0;   int calc(int i, int j, int t) {     if (i > n || j > m) return 0;     if (num[i][j][t] != 0) return num[i][j][t];     num[i][j][t] = 1;     if (t == 0)       num[i][j][t] += calc(i + 1, j, t ^ 1);     else       num[i][j][t] += calc(i, j + 1, t ^ 1);     return num[i][j][t];   }   void go(int i, int j, int t, int val) {     if (i <= 0 || j <= 0 || locked[i][j]) return;     if (t == 0) {       num[i][j][t] -= val;       ans -= val;       return go(i, j - 1, t ^ 1, val);     } else {       num[i][j][t] -= val;       ans -= val;       return go(i - 1, j, t ^ 1, val);     }   }   void go2(int i, int j, int t) {     num[i][j][t] = 1;     ans++;     if (t == 0) {       if (i < n) {         num[i][j][t] += num[i + 1][j][t ^ 1];         ans += num[i + 1][j][t ^ 1];       }     } else {       if (j < m) {         num[i][j][t] += num[i][j + 1][t ^ 1];         ans += num[i][j + 1][t ^ 1];       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         for (int k = 0; k < 2; k++) ans += calc(i, j, k);       }     }     long long free = n * m;     while (q--) {       int x, y;       cin >> x >> y;       if (!locked[x][y]) {         go(x, y, 0, num[x][y][0]);         go(x, y, 1, num[x][y][1]);         locked[x][y] = 1;         free--;       } else {         go2(x, y, 0);         go2(x, y, 1);         locked[x][y] = 0;         go(x, y, 0, -num[x][y][0]);         go(x, y, 1, -num[x][y][1]);         num[x][y][0] /= 2;         num[x][y][1] /= 2;         ans -= num[x][y][0] + num[x][y][1];         free++;       }       cout << ans - free <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int values[400][400];   int mem[400][400][2];   void read() {     cin >> n;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         cin >> values[i][j];         mem[i][j][0] = 0;         mem[i][j][1] = 0;       }     }   }   void add(int x1, int x2, int c, int v) {     if (x1 > x2) return;     int lo = max(0, c - n + 1), hi = min(n - 1, c);     if (x1 < lo || x2 > hi) return;     int y1 = c - x1, y2 = c - x2;     v += values[x1][y1] + values[x2][y2];     if (x1 == x2) v -= values[x1][y1];     if (v > mem[x1][x2][c & 1]) mem[x1][x2][c & 1] = v;   }   void solve() {     mem[0][0][0] = values[0][0];     for (int c = 0; c <= 2 * n - 3; ++c) {       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           mem[i][j][(c + 1) & 1] = -1000 * 400 * 2;         }       }       int lo = max(0, c - n + 1), hi = min(n - 1, c);       for (int x1 = lo; x1 <= hi; ++x1) {         for (int x2 = x1; x2 <= hi; ++x2) {           add(x1, x2, c + 1, mem[x1][x2][c & 1]);           add(x1 + 1, x2, c + 1, mem[x1][x2][c & 1]);           add(x1, x2 + 1, c + 1, mem[x1][x2][c & 1]);           add(x1 + 1, x2 + 1, c + 1, mem[x1][x2][c & 1]);         }       }     }   }   int main() {     read();     solve();     cout << mem[n - 1][n - 1][0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, z;     long long x1, y1, z1;     vector<long long> a(6);     long long sum = 0;     cin >> x >> y >> z;     cin >> x1 >> y1 >> z1;     for (int i = 0; i < 6; ++i) {       long long b;       cin >> b;       a[i] = b;     }     if (x < 0) {       sum += a[4];     } else if (x > x1) {       sum += a[5];     }     if (y < 0) {       sum += a[0];     } else if (y > y1) {       sum += a[1];     }     if (z < 0) {       sum += a[2];     } else if (z > z1) {       sum += a[3];     }     cout << sum;   }
#include <bits/stdc++.h>   struct node {     double x, y, z;   } p[5005];   double d[5005];   double getlen(node a, node b) {     double len;     len = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) +           (a.z - b.z) * (a.z - b.z);     return sqrt(len);   }   int main() {     int n, i, j, a, b, c;     while (scanf( %d , &n) != EOF) {       for (i = 0; i < n; i++) {         scanf( %d %d %d , &a, &b, &c);         p[i].x = a * 1.0;         p[i].y = b * 1.0;         p[i].z = c * 1.0;       }       for (i = 1; i < n; i++) {         d[i] = getlen(p[0], p[i]);       }       double lenn;       double max = 9999999.0;       for (i = 1; i < n; i++) {         for (j = 1; j <= i; j++) {           if (j == i) continue;           lenn = d[i] + d[j] + getlen(p[i], p[j]);           if (max - lenn > 1e-6) max = lenn;         }       }       printf( %.10f n , max * 1.0 / 2.0);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     if (n == 2) {       printf( -1 n );       return 0;     }     printf( 6 n10 n15 n );     for (int i = 4; i <= n; i++) {       printf( 6 );       for (int zero = 1; zero <= i - 4 + 1; zero++) printf( 0 );       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int x;       cin >> x;       int a[s.length()];       for (int i = 0; i < s.length(); i++) {         a[i] = 1;       }       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  0 ) {           if (i - x >= 0) {             a[i - x] = 0;           }           if (i + x < s.length()) {             a[i + x] = 0;           }         }       }       int tag = 0;       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  1 ) {           int tag1 = 0;           if (i - x >= 0) {             if (a[i - x] == 1) {               a[i - x] = 1;               tag1++;             }           }           if (i + x < s.length()) {             if (a[i + x] == 1) {               tag1++;             }           }           if (tag1 == 0) {             tag = 1;             break;           }         }       }       if (tag == 1) {         cout <<  -1  << endl;       } else {         for (int i = 0; i < s.length(); i++) {           cout << a[i];         }         cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, a, b, c, d, e, R, B, P, ans;   char s;   inline long long read() {     long long sum = 0, x = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) x = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       sum = sum * 10 + ch -  0 ;       ch = getchar();     }     return sum * x;   }   inline void write(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );     return;   }   signed main() {     n = read();     for (register long long i = 1; i <= n; ++i) {       m = read();       cin >> s;       if (s ==  P  || s ==  R ) {         if (R) {           ans += m - b;           a = max(a, m - b);         }         R = 1;         b = m;       }       if (s ==  P  || s ==  B ) {         if (B) {           ans += m - c;           d = max(d, m - c);         }         B = 1;         c = m;       }       if (s ==  P ) {         if (P) ans += min(0ll, m - e - d - a);         P = 1;         a = d = 0;         e = m;       }     }     write(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, x, y;     cin >> n >> x >> y;     long long a1 = y - n + 1;     if (a1 <= 0 or a1 * a1 + n - 1 < x) return cout << -1 <<   n , 0;     cout << a1 <<   n ;     for (int i = 0; i < n - 1; i++) cout << 1 <<   n ;     exit(0);   }
#include <bits/stdc++.h>   using namespace std;   int T;   priority_queue<int, vector<int>, greater<int> > q;   vector<int> g[1000005];   int main() {     scanf( %d , &T);     int n;     long long int ans;     while (T--) {       ans = 0;       scanf( %d , &n);       int x, y;       for (int i = 1; i <= n; i++) {         scanf( %d %d , &x, &y);         g[x].push_back(y);       }       for (int i = n - 1; i >= 0; i--) {         int sz = g[i].size();         for (int j = 0; j < sz; j++) q.push(g[i][j]);         while (q.size() > n - i) {           ans += q.top(), q.pop();         }       }       printf( %lld n , ans);       for (int i = 0; i < n; ++i) {         g[i].clear();         while (!q.empty()) q.pop();       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     int l1, l, r, count = 0;     cin >> s;     l1 = s.size();     int arr[l1];     memset(arr, 0, sizeof(arr));     int last = -1;     for (int i = 0; i < l1;) {       if (s[i] == s[i + 1]) {         l = i;         r = i + 1;         while (s[l] == s[r] && l >= 0 && r < l1) {           count++;           s.erase(l, 1);           s.erase(l, 1);           l--;           r--;           l1 -= 2;         }         i = r - 1;         last = r - 1;       }       i++;     }     if (count % 2)       cout <<  Yes n ;     else       cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int maxn = 1100;   const int maxk = 2 * maxn;   long long dp[maxn][maxk][4];   long long st[4][4] = {{0, 1, 1, 1}, {1, 0, 1, 1}, {0, 0, 0, 2}, {0, 0, 2, 0}};   int main() {     int n, k;     scanf( %d%d , &n, &k);     dp[1][1][0] = 1;     dp[1][1][1] = 1;     dp[1][2][2] = 1;     dp[1][2][3] = 1;     for (int i = 2; i <= n; i++)       for (int j = 1; j <= k; j++)         for (int a = 0; a < 4; a++)           for (int b = 0; b < 4; b++)             dp[i][j + st[b][a]][a] += dp[i - 1][j][b] % mod;     printf( %d n , (dp[n][k][0] + dp[n][k][1] + dp[n][k][2] + dp[n][k][3]) % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long int, long long int>> a;   vector<pair<long long int, long long int>> b;   vector<long long int> c;   long long int n, m, T;   bool solve(long long int d) {     priority_queue<long long int, vector<long long int>, greater<long long int>>         s;     long long int j = 0;     long long int sum = 0;     for (long long int i = 0; i < m; i = i + d) {       while (j < n && a[j].first >= b[i].first) {         s.push(c[a[j].second]);         j++;       }       if (s.empty()) return false;       long long int temp = s.top();       s.pop();       sum += temp;     }     return sum <= T;   }   signed main(void) {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       cin >> n >> m >> T;       a.resize(0);       b.resize(0);       c.resize(n);       for (long long int i = 0; i < m; i++) {         long long int temp;         cin >> temp;         b.push_back({temp, i});       }       for (long long int i = 0; i < n; i++) {         long long int temp;         cin >> temp;         a.push_back({temp, i});       }       for (long long int i = 0; i < n; i++) cin >> c[i];       sort(b.begin(), b.end(), greater<pair<long long int, long long int>>());       sort(a.begin(), a.end(), greater<pair<long long int, long long int>>());       long long int l = 1;       long long int r = m;       long long int ans = -1;       while (l <= r) {         long long int mid = (l + r) / 2;         if (solve(mid)) {           r = mid - 1;           ans = mid;         } else           l = mid + 1;       }       if (ans == -1) {         cout <<  NO  << endl;         continue;       }       cout <<  YES  << endl;       priority_queue<pair<long long int, long long int>,                      vector<pair<long long int, long long int>>,                      greater<pair<long long int, long long int>>>           s;       long long int j = 0;       long long int sum = 0;       vector<long long int> p(m);       for (long long int i = 0; i < m; i = i + ans) {         while (j < n && a[j].first >= b[i].first) {           s.push({c[a[j].second], a[j].second});           j++;         }         long long int index = s.top().second;         s.pop();         for (long long int k = i; k < min(i + ans, m); k++) {           p[b[k].second] = index;         }       }       for (long long int i = 0; i < m; i++) cout << p[i] + 1 <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 6e1;   map<string, int> mp;   int n;   int answer = 1;   string To(string a) {     for (int i = 0; i < a.size(); i++)       if (a[i] >  Z ) a[i] = a[i] - 32;     return a;   }   int main() {     mp[ POLYCARP ] = 1;     cin >> n;     for (int i = 0; i < n; i++) {       string n1, r, n2;       cin >> n1 >> r >> n2;       n1 = To(n1);       n2 = To(n2);       mp[n1] = mp[n2] + 1;       answer = max(answer, mp[n1]);     }     cout << answer;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   struct Node {     long long l, r;   } dict[maxn];   long long N, s;   inline bool check(long long mid) {     long long cnt = 0, cost = 0;     priority_queue<long long, vector<long long>, greater<long long>> q;     for (int i = 1; i <= N; ++i) {       cost += dict[i].l;       if (dict[i].l < mid && dict[i].r >= mid) {         q.push(mid - dict[i].l);       } else if (dict[i].l >= mid) {         ++cnt;       }     }     while (!q.empty() && cnt < (N + 1) / 2) {       cost += q.top();       q.pop();       cnt++;     }     return cost <= s && cnt >= (N + 1) / 2;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %lld%lld , &N, &s);       for (int i = 1; i <= N; ++i) {         scanf( %lld%lld , &dict[i].l, &dict[i].r);       }       long long l = 1, r = 1e14, ans;       while (l <= r) {         long long mid = (l + r) >> 1;         if (check(mid))           ans = mid, l = mid + 1;         else           r = mid - 1;       }       cout << ans << endl;     }     return 0;   }