malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,avx )   using namespace std;   const int MAXSIZE = 10000020;   int bufpos;   char buf[MAXSIZE];   void init() {     buf[fread(buf, 1, MAXSIZE, stdin)] =   0 ;     bufpos = 0;   }   int readint() {     int val = 0;     for (; !isdigit(buf[bufpos]); bufpos++)       ;     for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + buf[bufpos] -  0 ;     return val;   }   char readchar() {     for (; isspace(buf[bufpos]); bufpos++)       ;     return buf[bufpos++];   }   int readstr(char *s) {     int cur = 0;     for (; isspace(buf[bufpos]); bufpos++)       ;     for (; !isspace(buf[bufpos]); bufpos++) s[cur++] = buf[bufpos];     s[cur] =   0 ;     return cur;   }   char bf[1 << 25], st[20], *w = bf;   void flush() {     fwrite(bf, 1, w - bf, stdout);     w = bf;   }   inline void pc(register char c) { *w++ = c; }   void print(register int n) {     register char *t = st;     do {       *t++ = n % 10 + 48;     } while (n /= 10);     while (t-- > st) pc(*t);   }   int n, q, fa[66666], aa[66666], kh[66666], a[66666], p[66666], fp[66666],       siz[66666], ck, pa[66666];   vector<int> edge[66666];   int dd[66666];   void dfs(int u) {     siz[u] = 1;     p[++ck] = u;     fp[u] = ck;     pa[ck] = fp[fa[u]];     dd[ck] = dd[pa[ck]] + 1;     for (auto v : edge[u]) {       dfs(v);       siz[u] += siz[v];     }   }   int main() {     init();     n = readint();     q = readint();     for (int i = 1; i <= n; ++i) {       aa[i] = readint();     }     for (int i = 2; i <= n; ++i) {       fa[i] = readint();       edge[fa[i]].push_back(i);     }     dfs(1);     for (int i = 1; i <= n; ++i) {       a[fp[i]] = aa[i];       kh[i] = -50001;     }     for (int i = 1; i <= q; ++i) {       int x = readint();       int y = siz[x];       x = fp[x];       int pp = i + 1, gg = y >> 3, *jj = kh + x, *diao = dd + x, *aa = a + x;       int ans = 0, cnt = 0;       for (int j = 0; j < gg; ++j, jj += 8, diao += 8, aa += 8) {         int w;         w = jj[0] + aa[0] < pp, jj[0] = w ? i : jj[0], ans += w * diao[0],         cnt += w;         w = jj[1] + aa[1] < pp, jj[1] = w ? i : jj[1], ans += w * diao[1],         cnt += w;         w = jj[2] + aa[2] < pp, jj[2] = w ? i : jj[2], ans += w * diao[2],         cnt += w;         w = jj[3] + aa[3] < pp, jj[3] = w ? i : jj[3], ans += w * diao[3],         cnt += w;         w = jj[4] + aa[4] < pp, jj[4] = w ? i : jj[4], ans += w * diao[4],         cnt += w;         w = jj[5] + aa[5] < pp, jj[5] = w ? i : jj[5], ans += w * diao[5],         cnt += w;         w = jj[6] + aa[6] < pp, jj[6] = w ? i : jj[6], ans += w * diao[6],         cnt += w;         w = jj[7] + aa[7] < pp, jj[7] = w ? i : jj[7], ans += w * diao[7],         cnt += w;       }       gg <<= 3;       for (int j = gg; j < y; ++j) {         int w;         w = jj[j - gg] + aa[j - gg] < pp, jj[j - gg] = w ? i : jj[j - gg],         ans += w * diao[j - gg], cnt += w;         ;       }       ans = ans - cnt * dd[x];       print(ans);       pc(   );       print(cnt);       pc(  n );     }     flush();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n);     priority_queue<pair<int, int>, vector<pair<int, int>>,                    greater<pair<int, int>>>         pq;     long long sum = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];       sum += a[i] / 10;       pq.push(pair<int, int>(10 - (a[i] % 10), i));     }     while (!pq.empty()) {       pair<int, int> t = pq.top();       pq.pop();       int val = t.first;       int ind = t.second;       sum -= a[ind] / 10;       a[ind] += val;       sum += a[ind] / 10;       if (a[ind] <= 100 && k >= val) {         k -= val;         pq.push(pair<int, int>(10 - (a[ind] % 10), ind));       } else {         sum -= a[ind] / 10;         a[ind] -= val;         sum += a[ind] / 10;       }       if (k < 0) break;     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   int main() {     string s, ans;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  . ) ans +=  0 ;       if (s[i] ==  - ) {         i++;         if (s[i] ==  . )           ans +=  1 ;         else           ans +=  2 ;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 mt_rand(time(0));   const int N = 3e5 + 5;   int q, n, s[N], maks[N], dp[N];   map<int, int> mapa[N];   int main() {     scanf( %d , &q);     while (q--) {       scanf( %d , &n);       for (int i = 0; i < n; i++) scanf( %d , &s[i]);       for (int i = 0; i < n; i++) {         maks[i] = -1;         mapa[i].clear();         dp[i] = 0;       }       mapa[0][s[0]] = 0;       for (int i = 1; i < n; i++) {         if (mapa[i - 1].count(s[i])) {           int pos = mapa[i - 1][s[i]];           maks[i] = pos;           swap(mapa[i], mapa[pos - 1]);           if (pos > 0) mapa[i][s[pos - 1]] = pos - 1;         }         mapa[i][s[i]] = i;       }       long long ans = 0;       for (int i = 1; i < n; i++) {         if (maks[i] == -1)           dp[i] = 0;         else if (maks[i] == 0)           dp[i] = 1;         else           dp[i] = 1 + dp[maks[i] - 1];         ans += dp[i];       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MAXN = 1e5 + 5;   ll x;   string s;   int ans[MAXN];   void init() {     ;     ;   }   void solve(int casei) {     ll n = s.length();     s =  #  + s;     for (int i = 1; i <= n; ++i) {       ans[i] = -1;     }     for (int i = 1; i <= n; ++i) {       if (s[i] ==  0 ) {         if (i + x <= n) ans[i + x] = 0;         if (i - x >= 1) ans[i - x] = 0;       }     }     for (int i = 1; i <= n; ++i) {       if (s[i] ==  1 ) {         bool flg = false;         if (i + x <= n && ans[i + x] != 0) ans[i + x] = 1, flg = true;         if (i - x >= 1 && ans[i - x] != 0) ans[i - x] = 1, flg = true;         if (flg == false) {           cout <<  -1 n ;           return;         }       }     }     for (int i = 1; i <= n; ++i) {       if (ans[i] == -1) ans[i] = 1;     }     for (int i = 1; i <= n; ++i) cout << ans[i];     cout << endl;   }   int main() {     int Case = 1;     ios::sync_with_stdio(false);     cin.tie(0);     cin >> Case;     for (int casei = 1; casei <= Case; ++casei) {       cin >> s >> x;       init();       solve(casei);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int v[N];   int n, k;   int main() {     scanf( %d %d , &n, &k);     n--;     for (int i = 1; i <= n; ++i) scanf( %d , v + i), v[i] += v[i - 1];     int ans = 0x3F3F3F3F;     for (int i = k; i <= n; ++i) ans = min(ans, v[i] - v[i - k]);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a, b, c, l, ans;   long long int rec(long long int A, long long int B, long long int C,                     long long int L) {     if (A < B + C) {       return 0;     }     long long int d = min(L, A - B - C);     return ((d + 1) * (d + 2)) / 2;   }   int main() {     while (cin >> a >> b >> c >> l) {       ans = (l + 3) * (l + 2) * (l + 1);       ans /= 6;       for (long long int i = 0; i <= l; i++) {         ans -= rec(a + i, b, c, l - i);         ans -= rec(b + i, a, c, l - i);         ans -= rec(c + i, a, b, l - i);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b;   long long res = 0LL;   int mod = 1000000007;   int main() {     cin >> a >> b;     cout << (((((((((a * (a + 1)) / 2 % mod) * (b % mod)) % mod) + a) % mod) %                mod) *               ((b * (b - 1)) / 2 % mod)) %              mod)          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[5050][5050], q[5050][5050];   int ans[5050], len;   char s[5050];   void init() {     for (int i = 0; i < len; i++) {       int l = 0;       while (i - l >= 0 && i + l < len && s[i - l] == s[i + l])         dp[i - l][i + l] = 1, l++;       l = 0;       while (i - l >= 0 && i + 1 + l < len && s[i - l] == s[i + l + 1])         dp[i - l][i + l + 1] = 1, l++;     }   }   void solve() {     for (int t = 0; t < len; t++) {       for (int j = 0; j + t < len; j++) {         if (!dp[j][j + t]) continue;         int mid;         if (t % 2 == 0)           mid = (j + j + t) / 2 - 1;         else           mid = (j + j + t) / 2;         if (mid < j)           q[j][j + t] = 1;         else           q[j][j + t] = q[j][mid] + 1;         ans[q[j][j + t]]++;       }     }   }   int main() {     scanf( %s , s);     len = strlen(s);     memset(dp, 0, sizeof(dp)), memset(ans, 0, sizeof(ans)),         memset(q, 0, sizeof(q));     init();     solve();     for (int i = len - 1; i >= 1; i--) ans[i] += ans[i + 1];     for (int i = 1; i <= len; i++) {       if (i == 1)         printf( %d , ans[i]);       else         printf(  %d , ans[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return x * f;   }   int n, a, b, ans, ansa[1000000], ansb[1000000], cnta, cntb;   bool flag[1000000];   bool check(int k) {     int w = a;     cnta = cntb = 0;     for (int i = 1; i <= k; i++)       if (w >= i)         ansa[++cnta] = i, w -= i;       else         break;     ansa[cnta + 1] = k + 1;     for (int i = cnta; i >= 1; i--) {       if (!w) break;       while (w && ansa[i] + 1 < ansa[i + 1]) ansa[i]++, w--;     }     if (b >= 1ll * k * (k + 1) / 2 - (a - w))       return 1;     else       return 0;   }   int main() {     a = read(), b = read();     n = sqrt((a + b) * 2ll) + 2;     int l = 0, r = n;     while (l <= r) {       int mid = l + r >> 1;       if (check(mid))         ans = mid, l = mid + 1;       else         r = mid - 1;     }     int w = a;     cnta = cntb = 0;     for (int i = 1; i <= ans; i++)       if (w >= i)         ansa[++cnta] = i, w -= i;       else         break;     ansa[cnta + 1] = ans + 1;     for (int i = cnta; i >= 1; i--) {       if (!w) break;       while (w && ansa[i] + 1 < ansa[i + 1]) ansa[i]++, w--;     }     printf( %d n , cnta);     for (int i = 1; i <= cnta; i++) printf( %d  , ansa[i]), flag[ansa[i]] = 1;     cout << endl;     printf( %d n , ans - cnta);     for (int i = 1; i <= ans; i++)       if (!flag[i]) printf( %d  , i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2010;   int n, ans;   double x[maxn], y[maxn];   int main() {     scanf( %d , &n);     for (int i = 1, a, b, c; i <= n; i++) {       scanf( %d %d %d , &a, &b, &c);       x[i] = 1.0 * a * c / (a * a + b * b);       y[i] = 1.0 * b * c / (a * a + b * b);     }     for (int i = 1; i <= n; i++) {       vector<double> V;       int cnt = 0;       for (int j = i + 1; j <= n; j++) {         if (abs(x[i] - x[j]) > 1e-12)           V.push_back((y[i] - y[j]) / (x[i] - x[j]));         else if (abs(y[i] - y[j]) < 1e-12)           cnt++;         else           V.push_back(1e18);       }       ans += cnt * (n - i - cnt);       sort(V.begin(), V.end());       for (int j = 0, k; j < V.size(); j = k) {         for (k = j; k < V.size() && abs(V[j] - V[k]) < 1e-12; k++)           ;         ans += (k - j) * (k - j - 1) / 2;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   int map[55][55];   int to[55][55][4][2];   int rx[] = {0, -1, 0, 1};   int ry[] = {1, 0, -1, 0};   struct node {     int x, y, dp, cp;   };   int main() {     memset(map, 0, sizeof(map));     int n, m, step, i, j;     char str[55];     node now;     now.x = 1, now.y = 1;     now.dp = 0, now.cp = 1;     scanf( %d %d , &n, &step);     scanf( %s , str + 1);     m = strlen(str + 1);     for (i = 1; i <= m; i++) map[1][i] = str[i] -  0 ;     for (i = 2; i <= n; i++) {       for (j = 1; j <= m; j++) scanf( %1d , &map[i][j]);     }     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         if (map[i][j] == 0) continue;         for (int dir = 0; dir < 4; dir++) {           int x = i;           int y = j;           while (1) {             x += rx[dir];             y += ry[dir];             if (map[x][y] != map[i][j]) {               x -= rx[dir];               y -= ry[dir];               break;             }           }           to[i][j][dir][0] = x;           to[i][j][dir][1] = y;         }       }     for (i = 0; i < step; i++) {       int x = to[now.x][now.y][now.dp][0];       int y = to[now.x][now.y][now.dp][1];       now.x = x, now.y = y;       now.x = to[x][y][(now.dp + now.cp + 4) % 4][0];       now.y = to[x][y][(now.dp + now.cp + 4) % 4][1];       x = now.x + rx[now.dp];       y = now.y + ry[now.dp];       if (map[x][y]) {         now.x = x, now.y = y;       } else {         if (now.cp == 1) {           now.cp = -1;         } else {           now.cp = 1;           now.dp = (now.dp - 1 + 4) % 4;         }       }     }     printf( %d n , map[now.x][now.y]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool si[1000007];   int x0 = 1000007;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int x2;     cin >> x2;     si[0] = si[1] = false;     for (int i = 2; i < 1000007; i++) {       si[i] = true;     }     for (int i = 2; i < 1000007; i++) {       if (si[i]) {         for (int j = i * 2; j < 1000007; j += i) {           si[j] = false;         }       }     }     int lp = 0;     for (int i = 2; i <= sqrt(x2); i++) {       if (x2 % i == 0) {         if (si[i]) lp = max(lp, i);         if (si[x2 / i]) lp = max(lp, x2 / i);       }     }     for (int x1 = (x2 / lp - 1) * lp + 1; x1 <= x2; x1++) {       for (int i = 2; i <= sqrt(x1); i++) {         if (x1 % i == 0) {           if (si[i]) {             if (((x1 / i - 1) * i + 1) >= 3) x0 = min(x0, (x1 / i - 1) * i + 1);           }           if (si[x1 / i]) {             if (((i - 1) * (x1 / i) + 1) >= 3)               x0 = min(x0, (i - 1) * (x1 / i) + 1);           }         }       }     }     cout << x0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     int n;     cin >> s;     n = s.size();     s = s +  b ;     for (int i = 0; i < n; i++) {       cout << (s[i] != s[i + 1] ? 1 : 0) <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     vector<int> a(N);     for (int i = 0; i < N; ++i) {       scanf( %d , &a[i]);     }     sort(a.begin(), a.end());     int res = 0;     for (int i = 0; i <= N; ++i) {       if (a[i] == a[i + 1]) {         ++res;         ++i;       }     }     cout << res / 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool bi[12][12];   int main() {     int a, b, c, d, e, x, y, z, n, k, N, M;     scanf( %d %d , &N, &M);     scanf( %d %d , &z, &k);     for (a = 0; a < z; a++) {       scanf( %d %d , &x, &y);       bi[x][y] = true;     }     z = 0;     for (a = 1; a <= N; a++) {       for (b = 1; b <= M; b++) {         for (c = a; c <= N; c++) {           for (d = b; d <= M; d++) {             e = 0;             for (x = a; x <= c; x++) {               for (y = b; y <= d; y++)                 if (bi[x][y]) e++;             }             if (e >= k) z++;           }         }       }     }     cout << z << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int mx = 0, n;     cin >> n;     vector<long int> vec;     for (int i = 0; i < n; i++) {       long int x;       cin >> x;       vec.push_back(x);     }     if (vec.size() == 1) {       cout <<  1  << endl;       return 0;     }     for (int i = 0; i < n; i++) {       long int len = 1, temp = vec[i];       for (int j = i + 1; j < n; j++) {         if (vec[j] >= temp) {           temp = vec[j];           len++;         } else {           break;         }       }       mx = max(mx, len);     }     cout << mx << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = ((res % p) * (x % p)) % p;       y = y >> 1;       x = ((x % p) * (x % p)) % p;     }     return res % p;   }   long long raichu(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = ((res) * (x));       y = y >> 1;       x = ((x) * (x));     }     return res;   }   bool isprime(long long n) {     if (n < 2)       return false;     else if (n == 2)       return true;     else if (n % 2 == 0)       return false;     else {       long long z = sqrt(n);       for (int i = 0; i < z - 1; i++)         if (n % (i + 2) == 0) return false;       return true;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tests = 1, Tests;     Tests = tests;     while (tests--) {       int n;       long long A;       cin >> n >> A;       vector<int> d(n);       for (int i = 0; i < n; i++) cin >> d[i];       long long sum = 0;       for (int i = 0; i < n; i++) sum += d[i];       for (int i = 0; i < n; i++) {         long long mi = 1, ma = d[i];         long long left = A - (sum - d[i]);         if (left > 1) {           mi = left;         }         left = A - (n - 1);         if (left < d[i]) {           ma = left;         }         cout << d[i] - (ma - mi + 1) <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     scanf( %d%d%d , &a, &b, &c);     for (int i = 1, _b = a; i <= _b; i++) {       int j = a / i;       if (b % i == 0 && c % j == 0 && b / i == c / j) {         printf( %d n , 4 * (i + j + b / i));         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tt = 1;     while (tt--) {       int n;       cin >> n;       int a[n - 1];       cout <<  ? 2 3  << endl << endl;       int m;       cin >> m;       for (int i = 0; i < n - 1; i++) {         cout <<  ?   << 1 <<     << i + 2 << endl << endl;         cin >> a[i];       }       int b[n];       for (int i = 2; i < n; i++) b[i] = a[i - 1] - a[i - 2];       b[1] = m - b[2];       b[0] = a[0] - b[1];       cout <<  !  ;       for (int i = 0; i < n; i++) cout << b[i] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100 + 5;   double p[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     sort(p + 1, p + n + 1);     reverse(p + 1, p + n + 1);     double one = 0, none = 1;     for (int i = 1; i <= n; i++) {       double nw = one * (1 - p[i]) + p[i] * none;       if (nw > one) {         one = nw;         none *= (1 - p[i]);       } else         break;     }     cout << setprecision(9) << one << endl;   }
#include <bits/stdc++.h>   using namespace std;   long a[200001];   long b[200001];   long n;   int main() {     cin >> n;     int k = 1;     for (int i = 1; i <= n; i++) {       cin >> a[k];       if (a[k] != 0) k++;     }     k = 1;     for (int i = 1; i <= n; i++) {       cin >> b[k];       if (b[k] != 0) k++;     }     long j = 1;     while (b[1] != a[j]) {       j++;     }     for (int i = 2; i <= n - 1; i++) {       j++;       if (j == n) j = 1;       if (b[i] != a[j]) {         cout <<  No  << endl;         return 0;       }     }     cout <<  Yes  << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const int MAX = 1e6 + 5;   const long long MOD = 1000000007;   struct state {     int len, link, cnt;     int nx[26];   } st[MAX << 1];   int id, last, cur;   vector<int> v[MAX];   inline void sa_init() {     st[0].link = -1;     memset(st[0].nx, 0, sizeof st[0].nx);     id = last = st[0].cnt = 0;   }   inline void sa_extend(int c) {     int clone;     st[last].nx[c] = cur = ++id;     st[cur].len = st[last].len + 1;     v[st[cur].len].push_back(cur);     st[cur].cnt = 1;     int p = last;     while (1) {       if ((p = st[p].link) == -1) {         st[cur].link = 0;         break;       }       if (st[p].nx[c]) {         int q = st[p].nx[c];         if (st[p].len + 1 == st[q].len)           st[cur].link = q;         else {           clone = ++id;           st[clone] = st[q];           st[clone].cnt = 0;           st[clone].len = st[p].len + 1;           v[st[clone].len].push_back(clone);           st[q].link = st[cur].link = clone;           while (p != -1 && st[p].nx[c] == q) {             st[p].nx[c] = clone;             p = st[p].link;           }         }         break;       } else         st[p].nx[c] = cur;     }     last = cur;     return;   }   inline int lcs(string &s, string &t) {     sa_init();     for (char c : s) sa_extend(c -  a );     int best = 0, len = 0;     cur = 0;     for (char c : t) {       c -=  a ;       while (cur && !st[cur].nx[c]) cur = st[cur].link, len = st[cur].len;       if (st[cur].nx[c]) {         cur = st[cur].nx[c];         best = max(best, ++len);       }     }     return best;   }   bool vis[MAX << 1];   vector<int> del;   inline int solve(string &s) {     int n = s.size(), ans = 0, len = 0;     del.clear();     s += s;     cur = 0;     for (char c : s) {       c -=  a ;       while (cur && !st[cur].nx[c]) cur = st[cur].link, len = st[cur].len;       if (st[cur].nx[c]) {         cur = st[cur].nx[c], ++len;         if (len == n) {           if (!vis[cur]) ans += st[cur].cnt, vis[cur] = 1, del.push_back(cur);           --len;           if (len == st[st[cur].link].len) cur = st[cur].link;         }       }     }     for (int i : del) vis[i] = 0;     return ans;   }   string s;   int q;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     sa_init();     cin >> s;     for (char c : s) sa_extend(c -  a );     for (int i = s.size(); i >= 1; --i)       for (int j : v[i]) st[st[j].link].cnt += st[j].cnt;     cin >> q;     while (q--) {       cin >> s;       cout << solve(s) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int n;   const int MAXN = 2e5;   pair<ll, int> arr[MAXN];   ll sum[MAXN];   ll ans = 1e18;   void init() { ans = 1e18; }   void input() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i].first;     }     for (int j = 0; j < n; j++) {       cin >> arr[j].second;     }     sort(arr, arr + n);   }   void make_sum() {     sum[0] = arr[0].second;     for (int i = 1; i < n; i++) {       sum[i] = sum[i - 1] + arr[i].second;     }     ans = sum[n - 1];   }   void solve() {     for (int i = 0; i < n; i++) {       ans = min(ans, max(arr[i].first, sum[n - 1] - sum[i]));       if (ans == 3) {       }     }   }   void output() { cout << ans << endl; }   int main() {     int number_of_testcases = 1;     cin >> number_of_testcases;     while (number_of_testcases--) {       init();       input();       make_sum();       solve();       output();     }     return 0;   }