malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long sqr(long long x) { return x * x; }   int mysqrt(long long x) {     int l = 0, r = 1e9 + 1;     while (r - l > 1) {       int m = (l + r) / 2;       if (m * (long long)m <= x)         l = m;       else         r = m;     }     return l;   }   mt19937 rnd(1227);   mt19937_64 rndll(12365);   long long AR = 19, BR = 13, CR = 23, XR = 228, YR = 322, MODR = 1e9 + 993;   long long myrand() {     long long ZR = (XR * AR + YR * BR + CR) % MODR;     XR = YR;     YR = ZR;     return ZR;   }   const int Mod = 1e9 + 9;   int bpow(int x, int y) {     if (y == 0) return 1;     if (y == 1) return x;     int ret = bpow(x, y >> 1);     ret = (ret * (long long)ret) % Mod;     if (y & 1) ret = (ret * (long long)x) % Mod;     return ret;   }   int bdiv(int x, int y) { return (x * (long long)bpow(y, Mod - 2)) % Mod; }   void setmin(int &x, int y) { x = min(x, y); }   void setmax(int &x, int y) { x = max(x, y); }   void setmin(long long &x, long long y) { x = min(x, y); }   void setmax(long long &x, long long y) { x = max(x, y); }   int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }   const long long llinf = 2e18 + 100;   const double eps = 1e-9;   const int maxn = 2e5 + 100, maxw = 1e7 + 100, inf = 2e9 + 100, sq = 300,             mod = 1e9 + 9, LG = 17;   int n;   vector<int> e[maxn];   int a[maxn];   vector<int> ans;   bool vis[maxn];   void go(int v, int par) {     ans.push_back(v);     vis[v] = 1;     for (int i : e[v])       if (i != par && !vis[i]) go(i, v);   }   void dfs(int v, int par) {     for (int i : e[v])       if (i != par) {         dfs(i, v);         if (vis[i]) a[v] ^= 1;       }     if (a[v] == 0) go(v, par);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       int v = i, u;       cin >> u;       u--;       if (u >= 0) {         e[v].push_back(u);         e[u].push_back(v);         a[v] ^= 1;         a[u] ^= 1;       }     }     dfs(0, -1);     if (ans.size() < n)       cout <<  NO ;     else {       cout <<  YES n ;       for (int i : ans) cout << i + 1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = int(1e5 + 5);   int n, A, cf, cm;   int a[MAXN], tmp1[MAXN], tmp2[MAXN];   long long s[MAXN], m;   int _max = 0, _min = int(1e9);   bool cmp(int x, int y) { return a[x] < a[y]; }   int main() {     cin >> n >> A >> cf >> cm >> m;     for (int i = 0; i < n; i++) tmp1[i] = i, cin >> a[i];     if (!cm && !cf) {       puts( 0 );       for (int i = 0; i < n; i++) cout << a[i] <<    ;       return 0;     }     sort(tmp1, tmp1 + n, cmp);     sort(a, a + n);     for (int i = 0; i < n; i++) {       s[i] = a[i];       i ? s[i] += s[i - 1] : 0;     }     long long ret, ans = 0;     a[n] = A;     for (int i = n; i >= 0; i--) {       ret = m - (1ll * A * (n - i) - (s[n - 1] - (i ? s[i - 1] : 0)));       if (ret < 0) break;       if (!cm) {         ans = 1ll * (n - i) * cf;         _max = n - i;         _min = 0;         continue;       }       long long l = a[0], r = A, mid;       while (l < r) {         mid = r - ((r - l) >> 1);         int k = upper_bound(a, a + n, mid) - a;         k = min(k, i);         if (ret >= 1ll * k * mid - (k ? s[k - 1] : 0))           l = mid;         else           r = mid - 1;       }       long long force = 1ll * (n - i) * cf + 1ll * l * cm;       if (force > ans) {         ans = force;         _max = n - i;         _min = l;       }     }     cout << ans << endl;     for (int i = 0; i < n - _max; i++) tmp2[tmp1[i]] = max(_min, a[i]);     for (int i = n - _max; i < n; i++) tmp2[tmp1[i]] = A;     for (int i = 0; i < n; i++) cout << tmp2[i] <<    ;     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   double v1, v2, l;   int main() {     scanf( %d%lf%lf%lf%d , &n, &l, &v1, &v2, &k);     int T = n / k;     if (n % k) T++;     printf( %.7lf n , (2 * T - 2 + (v1 + v2) / v1 - v2 / v1 + v1 / v2) * l /                           ((2 * T - 2) * v1 + v1 + v2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool ans[310000];   struct Query {     int x1, y1, x2, y2, id;   } querys[310000];   bool operator<(Query a, Query b) { return a.x2 < b.x2; }   struct Point {     int x, y;   } points[310000];   bool operator<(Point a, Point b) { return a.x < b.x; }   int minv[310000 << 2];   void pushup(int o) { minv[o] = min(minv[((o) << 1)], minv[((o) << 1 | 1)]); }   void update(int o, int L, int R, int x, int val) {     if (L == R) {       minv[o] = val;       return;     }     int M = (L + R) >> 1;     if (x <= M)       update(((o) << 1), L, M, x, val);     else       update(((o) << 1 | 1), M + 1, R, x, val);     pushup(o);   }   int query(int o, int L, int R, int ql, int qr) {     if (ql <= L && R <= qr) return minv[o];     int M = (L + R) >> 1;     int ans = 0x3f3f3f3f;     if (ql <= M) ans = min(ans, query(((o) << 1), L, M, ql, qr));     if (qr > M) ans = min(ans, query(((o) << 1 | 1), M + 1, R, ql, qr));     return ans;   }   int main() {     int n, m, t, q;     scanf( %d%d%d%d , &n, &m, &t, &q);     for (int i = 1; i <= t; i++) scanf( %d%d , &points[i].x, &points[i].y);     for (int i = 1; i <= q; i++)       scanf( %d%d%d%d , &querys[i].x1, &querys[i].y1, &querys[i].x2,             &querys[i].y2),           querys[i].id = i;     sort(points + 1, points + t + 1);     sort(querys + 1, querys + q + 1);     for (int i = 1, j = 1; i <= q; i++) {       while (j <= t && points[j].x <= querys[i].x2) {         update(1, 1, m, points[j].y, points[j].x);         j++;       }       ans[querys[i].id] |=           query(1, 1, m, querys[i].y1, querys[i].y2) >= querys[i].x1;     }     swap(n, m);     for (int i = 1; i <= t; i++) swap(points[i].x, points[i].y);     for (int i = 1; i <= q; i++) {       swap(querys[i].x1, querys[i].y1);       swap(querys[i].x2, querys[i].y2);     }     sort(points + 1, points + t + 1);     sort(querys + 1, querys + q + 1);     memset(minv, 0, sizeof(minv));     for (int i = 1, j = 1; i <= q; i++) {       while (j <= t && points[j].x <= querys[i].x2) {         update(1, 1, m, points[j].y, points[j].x);         j++;       }       ans[querys[i].id] |=           query(1, 1, m, querys[i].y1, querys[i].y2) >= querys[i].x1;     }     for (int i = 1; i <= q; i++) {       if (ans[i])         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x = n / 2, y = (n / 2) + 1, prime1 = 0, prime2 = 0;     if (n % 2 == 0) {       x = (n / 2);       y = n / 2;     }     for (int i = 1; i <= n; i++) {       for (int j = 2; j < x; j++) {         if (x % j == 0) {           prime1++;           break;         } else if (j == x - 1) {           prime1 = 0;           break;         }       }       for (int j = 2; j < y; j++) {         if (y % j == 0) {           prime2++;           break;         } else if (j == y - 1) {           prime1 = 0;           prime2 = 0;         }       }       if (prime1 >= 1 && prime2 >= 1)         break;       else {         x--;         y++;       }     }     cout << x <<     << y;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5, inf = 1e9 + 7;   long long n, k, f[30];   string s, t, r;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long i, j, a, b, ans = 0;     cin >> s >> t;     r = s;     sort(r.begin(), r.end(), greater<long long>());     if (r <= t) return cout << -1, 0;     n = s.size();     for (i = 0; i < n; i++) f[s[i] -  a ]++;     k = t.size();     for (i = 0; i < min(k, n); i++) {       if (f[t[i] -  a ]) {         s[i] = t[i], f[t[i] -  a ]--;       } else {         for (j = t[i] -  a ; j < 26; j++)           if (f[j]) {             s[i] = char(j +  a );             f[j]--;             i++;             for (j = 0; j < 26; j++) {               while (f[j]--) s[i] = char(j +  a ), i++;             }             cout << s;             return 0;           }         for (j = 25; j >= 0; j--) {           while (f[j]--) s[i] = char(j +  a ), i++;         }         next_permutation(s.begin(), s.end());         cout << s;         return 0;       }     }     if (i == n) next_permutation(s.begin(), s.end());     for (j = 0; j < 26; j++) {       while (f[j]--) s[i] = char(j +  a ), i++;     }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, k;     cin >> n;     int a[n], b[n];     for (i = 1; i <= n; i++) {       cin >> a[i];     }     for (i = 1; i <= n; i++) {       k = a[i];       b[k] = i;     }     for (i = 1; i <= n; i++) {       cout << b[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const double Pi = acos(-1.0);   const int INF = 1 << 29;   const int MAXN = 505;   int n;   int M[MAXN][MAXN];   int R[MAXN];   long long A[MAXN];   int main(int argc, char** argv) {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         scanf( %d , &M[i][j]);       }     }     for (int i = 0; i < n; i++) {       scanf( %d , &R[n - i - 1]);       R[n - i - 1]--;     }     for (int k = 0; k < n; k++) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           M[R[i]][R[j]] = min(M[R[i]][R[j]], M[R[i]][R[k]] + M[R[k]][R[j]]);         }       }       for (int i = 0; i <= k; i++) {         for (int j = 0; j <= k; j++) {           A[n - k - 1] += M[R[i]][R[j]];         }       }     }     for (int i = 0; i < n; i++) {       printf( %I64d  , A[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const long long INF = 2000000000LL;   long long res[MAXN], xx[MAXN << 1], cnt[MAXN << 1], la[MAXN << 1];   struct Event {     long long l, r, y, v;     Event() {}     Event(long long _l, long long _r, long long _y, long long _v)         : l(_l), r(_r), y(_y), v(_v) {}     bool operator<(const Event &t) const { return y < t.y; }   } e[MAXN << 1];   int main() {     int n, k;     scanf( %d%d , &n, &k);     int tot = 0;     xx[tot++] = -INF;     for (int i = 0; i < n; i++) {       long long x, y;       scanf( %I64d%I64d , &x, &y);       xx[tot++] = x;       xx[tot++] = x + k;       e[i << 1] = Event(x, x + k, y, 1);       e[i << 1 | 1] = Event(x, x + k, y + k, -1);     }     sort(xx, xx + tot);     tot = unique(xx, xx + tot) - xx;     sort(e, e + 2 * n);     for (int i = 0; i < tot; i++) la[i] = -INF;     for (int i = 0; i < 2 * n; i++) {       int l = upper_bound(xx, xx + tot, e[i].l) - xx;       int r = lower_bound(xx, xx + tot, e[i].r) - xx;       for (int j = l; j <= r; j++) {         res[cnt[j]] += (xx[j] - xx[j - 1]) * (e[i].y - la[j]);         cnt[j] += e[i].v;         la[j] = e[i].y;       }     }     for (int i = 1; i <= n; i++) printf( %I64d  , res[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   long long l, val[205], cst[205];   char s[205];   long long ch[205][26], fail[205], cnt = 1;   void Insert(char *s, long long w) {     long long len = strlen(s), r = 0;     for (long long i = 0; i < len; i++) {       long long val = s[i] -  a ;       if (!ch[r][val]) ch[r][val] = cnt++;       r = ch[r][val];     }     val[r] += w;   }   long long Q[205], L, R;   void build(long long r) {     Q[L = 0] = r, R = 1;     long long p, c;     for (; L < R;) {       r = Q[L++];       for (long long i = 0; i < 26; i++)         if (c = ch[r][i]) {           Q[R++] = c;           for (p = fail[r]; p != 0 && ch[p][i] == 0; p = fail[p])             ;           long long tmp = ch[p][i];           if (tmp && tmp != c)             fail[c] = tmp;           else             fail[c] = 0;           val[c] += val[fail[c]];         } else {           for (p = fail[r]; p != 0 && ch[p][i] == 0; p = fail[p])             ;           long long tmp = ch[p][i];           if (tmp)             ch[r][i] = tmp;           else             ch[r][i] = 0;         }     }   }   long long dp[205][205], dp2[205][205], dp3[205][205], A[205][205], B[205][205];   void solve(long long a[205][205], long long b[205][205],              long long c[205][205]) {     memcpy(A, a, sizeof A), memcpy(B, b, sizeof B);     for (long long k = 0; k < cnt; k++)       for (long long i = 0; i < cnt; i++)         for (long long j = 0; j < cnt; j++)           if (A[i][k] != -0x3f3f3f3f3f3f3f3fll &&               B[k][j] != -0x3f3f3f3f3f3f3f3fll)             c[i][j] = max(c[i][j], A[i][k] + B[k][j]);   }   int main() {     scanf( %lld%lld , &n, &l);     for (long long i = 1; i <= n; i++) scanf( %lld , &cst[i]);     fail[0] = -1;     for (long long i = 1; i <= n; i++) {       scanf( %s , s);       Insert(s, cst[i]);     }     build(0);     for (long long i = 0; i < cnt; i++)       for (long long j = 0; j < cnt; j++)         dp[i][j] = dp2[i][j] = -0x3f3f3f3f3f3f3f3fll;     for (long long i = 0; i < cnt; i++) dp[i][i] = dp2[i][i] = 0;     for (long long i = 0; i < cnt; i++)       for (long long j = 0; j < 26; j++) dp[i][ch[i][j]] = val[ch[i][j]];     for (; l; l >>= 1, solve(dp, dp, dp))       if (l & 1) solve(dp, dp2, dp2);     printf( %lld n , *max_element(dp2[0], dp2[0] + cnt + 1));   }
#include <bits/stdc++.h>   int main() {     int t, n, a, b, c, x, z = 0, e = 0, r = 0, o = 0, n1 = 0;     char s[100000];     scanf( %d , &n);     scanf( %s , &s);     for (x = 0; x < n; x++) {       if (s[x] ==  z )         z++;       else if (s[x] ==  e )         e++;       else if (s[x] ==  r )         r++;       else if (s[x] ==  o )         o++;       else if (s[x] ==  n )         n1++;     }     if (n1 <= o && n1 <= e) {       for (x = 0; x < n1; x++) printf( 1  );       o -= n1;       e -= n1;       a = (o > e) ? e : o;       b = (z > r) ? r : z;       c = (a > b) ? b : a;       for (x = 0; x < c; x++) printf( 0  );     } else {       t = (o > e) ? e : o;       for (x = 0; x < t; x++) printf( 1  );     }   }
#include <bits/stdc++.h>   using namespace std;   int a[20002][11] = {0};   int b[20002] = {0};   int c[11] = {0};   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);     for (int i = 0; i < k; i++) {       int x, y;       cin >> x >> y;       c[y - 1]++;       b[x - 1] -= a[x - 1][y - 1];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         b[i] += c[j] * a[i][j];       }       cout << b[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 2e5, mod = 1e9 + 7;   vector<char> s;   long long X;   void paste(long long p, long long l, long long cnt) {     if (s.size() > X + 3 || l == 0) return;     for (long long i = 0; i < cnt; ++i)       for (long long j = 0; j < l; ++j)         if (s.size() > X + 3)           return;         else           s.push_back(s[p + j]);   }   long long md(long long a) {     if (a < 0)       return (a + mod * 2) % mod;     else       return a % mod;   }   void solve() {     long long x;     cin >> x;     X = x;     string str;     cin >> str;     s = vector<char>(str.begin(), str.end());     long long p = 0;     long long cl = s.size();     while (p < x) {       ++p;       long long num = s[p - 1] -  0 ;       paste(p, s.size() - p, num - 1);       cl = (cl + (num - 1) * md(cl - p)) % mod;     }     cout << cl << endl;     return;   }   signed main() {     ios::sync_with_stdio(false);     long long t;     cin >> t;     for (long long i = 0; i < t; ++i) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using seg = pair<int, int>;   using ll = long long;   seg intersect(seg a, seg b) {     seg ret = {max(a.first, b.first), min(a.second, b.second)};     if (ret.first > ret.second) return {-1, -1};     return ret;   }   inline int len(const seg& a) { return a.second - a.first; }   const int inf = 1234567890;   struct node {     int l, r;     seg x;     node() {}     node(int _l, int _r) : l(_l), r(_r), x(0, inf) {}     node(int _l, int _r, const seg& _x) : node(_l, _r) { x = _x; }     node(node a, node b) : node(a.l, b.r) { x = intersect(a.x, b.x); }     void update(const seg& v) { x = v; }   };   struct segment_tree {     int n;     vector<node> arr;     segment_tree(const vector<seg>& a) : n(a.size()), arr(4 * n) {       mk(a, 0, 0, n - 1);     }     node mk(const vector<seg>& a, int i, int l, int r) {       int m = (l + r) / 2;       return arr[i] = l > r    ? node(l, r)                       : l == r ? node(l, r, a[l])                                : node(mk(a, 2 * i + 1, l, m),                                       mk(a, 2 * i + 2, m + 1, r));     }     node update(int at, seg v, int i = 0) {       int hl = arr[i].l, hr = arr[i].r;       if (at < hl || hr < at) return arr[i];       if (hl == at && at == hr) {         arr[i].update(v);         return arr[i];       }       return arr[i] = node(update(at, v, 2 * i + 1), update(at, v, 2 * i + 2));     }     node query(int l, int r, int i = 0) {       int hl = arr[i].l, hr = arr[i].r;       if (r < hl || hr < l) return node(hl, hr);       if (l <= hl && hr <= r) return arr[i];       return node(query(l, r, 2 * i + 1), query(l, r, 2 * i + 2));     }   };   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     int n;     cin >> n;     vector<seg> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;     }     segment_tree st(a);     int mx = 0;     for (int i = 0; i < n; ++i) {       st.update(i, seg(0, inf));       mx = max(mx, len(st.query(0, n - 1).x));       st.update(i, a[i]);     }     cout << mx <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[3000];   int n, k;   int ans = 0;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     sort(a + 1, a + 1 + n);     for (int i = 1; i <= k; i++) ans += a[i];     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct segment_tree {     int val[200005 << 2];     inline void update(int l, int r, int k, int x, int w) {       if (l == r) {         val[k] = w;         return;       }       int mid = l + r >> 1;       if (x <= mid)         update(l, mid, k << 1, x, w);       else         update(mid + 1, r, k << 1 | 1, x, w);       val[k] = max(val[k << 1], val[k << 1 | 1]);     }     inline int query(int l, int r, int k, int L, int R) {       if (L <= l && r <= R) return val[k];       int mid = l + r >> 1, ans = 0;       if (L <= mid) ans = max(ans, query(l, mid, k << 1, L, R));       if (mid < R) ans = max(ans, query(mid + 1, r, k << 1 | 1, L, R));       return ans;     }   } sgt;   int p[200005], pos[200005], a[200005], lg2[200005];   int lastp[200005], pre[200005][20];   char str[200005];   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     lg2[1] = 0;     for (int i = 2; i <= m; i++) lg2[i] = lg2[i >> 1] + 1;     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i]);       pos[p[i]] = i;     }     p[n + 1] = p[1], p[0] = p[n];     for (int i = 1; i <= m; i++) {       scanf( %d , &a[i]);       pre[i][0] = lastp[p[pos[a[i]] - 1]];       for (int k = 1; k <= lg2[i]; k++) pre[i][k] = pre[pre[i][k - 1]][k - 1];       lastp[a[i]] = i;     }     for (int i = 1; i <= m; i++) {       int x = i, k = n - 1;       while (k) {         x = pre[x][lg2[k]];         k -= 1 << lg2[k];       }       if (x) sgt.update(1, m, 1, i, x);     }     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       int t = sgt.query(1, m, 1, l, r);       if (t >= l)         str[i] =  1 ;       else         str[i] =  0 ;     }     str[q + 1] =   0 ;     puts(str + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double PI = acos(-1.0);   const int N = 1e5 + 5;   int n;   map<string, set<string> > m;   map<string, set<string> > m2;   set<string> host;   vector<set<string> > res;   int main(void) {     ios_base::sync_with_stdio(false);     cin >> n;     while (n--) {       string s;       cin >> s;       host.insert(s);       string s1 =   , s2 =   ;       int count = 0;       for (int i = 0; i < (int)s.size(); i++) {         if (s[i] ==  / ) count++;         if (count < 3) {           s1 += s[i];         } else {           s2 += s[i];         }       }       s1 +=    ;       s2 +=    ;       m[s1].insert(s2);     }     for (map<string, set<string> >::iterator it = m.begin(); it != m.end();          it++) {       string str =   ;       for (set<string>::iterator itt = (it->second).begin();            itt != (it->second).end(); itt++) {         str += (*itt);       }       m2[str].insert(it->first);     }     for (map<string, set<string> >::iterator it = m2.begin(); it != m2.end();          it++) {       if ((it->second).size() > 1) {         res.push_back(it->second);       }     }     cout << res.size() << endl;     for (int i = 0; i < (int)res.size(); i++) {       for (set<string>::iterator it = res[i].begin(); it != res[i].end(); it++) {         cout << (*it) <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   struct Block {     vector<array<int, 3>> events;     int pop_before;     vector<int> stack_after;     void add_event(array<int, 3> v) {       events.insert(upper_bound(events.begin(), events.end(), v), v);       sort(events.begin(), events.end());       pop_before = 0;       stack_after.clear();       for (auto [p, t, x] : events) {         if (t)           stack_after.push_back(x);         else {           if (stack_after.size())             stack_after.pop_back();           else             ++pop_before;         }       }     }   };   int main() {     cin.tie(0)->sync_with_stdio(0);     int q;     cin >> q;     int R = (int)sqrt(q);     int B = (q + R - 1) / R;     vector<Block> blocks(B);     for (int qq = 0; qq < q; ++qq) {       int p, t, x = 0;       cin >> p >> t;       --p;       if (t == 1) cin >> x;       blocks[p / R].add_event({p, t, x});       vector<array<int, 2>> remaining;       for (int i = 0; i < B; ++i) {         int to_pop = blocks[i].pop_before;         while (to_pop && remaining.size()) {           int pop_here = min(remaining.back()[0], to_pop);           to_pop -= pop_here;           remaining.back()[0] -= pop_here;           if (remaining.back()[0] == 0) remaining.pop_back();         }         if (blocks[i].stack_after.size())           remaining.push_back({(int)blocks[i].stack_after.size(), i});       }       if (remaining.size()) {         cout << blocks[remaining.back()[1]].stack_after[remaining.back()[0] - 1]              <<   n ;       } else         cout <<  -1 n ;     }   }