malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void read(long long &x) { scanf( %lld , &x); }   const long long N = 1000005;   struct city {     long long cnt, id;     bool operator<(const city b) const { return cnt < b.cnt; }   } a[N];   struct que {     long long x, id;     bool operator<(const que b) const { return x < b.x; }   } qq[N];   long long up[N], ans[N];   long long n, m, q;   struct node {     long long l, r, val;     long long cnt, sz, rnd;   } tr[N];   long long tot, rt;   void update(long long rt) {     tr[rt].sz = tr[tr[rt].l].sz + tr[tr[rt].r].sz + tr[rt].cnt;   }   void lturn(long long &rt) {     long long tmp = tr[rt].r;     tr[rt].r = tr[tmp].l;     tr[tmp].l = rt;     tr[tmp].sz = tr[rt].sz;     update(rt);     rt = tmp;   }   void rturn(long long &rt) {     long long tmp = tr[rt].l;     tr[rt].l = tr[tmp].r;     tr[tmp].r = rt;     tr[tmp].sz = tr[rt].sz;     update(rt);     rt = tmp;   }   void Insert(long long &rt, long long x) {     if (!rt) {       rt = ++tot;       tr[rt].sz = tr[rt].cnt = 1;       tr[rt].val = x, tr[rt].rnd = rand();       return;     }     tr[rt].sz++;     if (tr[rt].val == x)       tr[rt].cnt++;     else if (tr[rt].val < x) {       Insert(tr[rt].r, x);       if (tr[tr[rt].r].rnd < tr[rt].rnd) lturn(rt);     } else {       Insert(tr[rt].l, x);       if (tr[tr[rt].l].rnd < tr[rt].rnd) rturn(rt);     }   }   void Delete(long long &rt, long long x) {     if (!rt) return;     if (tr[rt].val == x) {       if (tr[rt].cnt > 1)         tr[rt].cnt--, tr[rt].sz--;       else {         if (tr[rt].l * tr[rt].r == 0)           rt = tr[rt].l + tr[rt].r;         else if (tr[tr[rt].l].rnd < tr[tr[rt].r].rnd)           rturn(rt), Delete(rt, x);         else           lturn(rt), Delete(rt, x);       }     } else if (tr[rt].val < x)       tr[rt].sz--, Delete(tr[rt].r, x);     else       tr[rt].sz--, Delete(tr[rt].l, x);   }   long long findnum(long long rt, long long x) {     if (!rt) return -1;     if (x <= tr[tr[rt].l].sz) return findnum(tr[rt].l, x);     x -= tr[tr[rt].l].sz;     if (x <= tr[rt].cnt) return tr[rt].val;     x -= tr[rt].cnt;     return findnum(tr[rt].r, x);   }   void doit() {     long long kind = 0;     for (long long _ = 1; _ <= q; _++) {       while (kind < m && up[kind] < qq[_].x) {         kind++;         Insert(rt, a[kind].id);       }       long long dis = qq[_].x - up[kind - 1];       dis = (dis - 1) % kind + 1;       ans[qq[_].id] = findnum(rt, dis);     }   }   signed main() {     read(n), read(m), read(q);     for (long long i = 1; i <= m; i++) a[i].id = i;     for (long long i = 1; i <= n; i++) {       long long x;       scanf( %d , &x);       a[x].cnt++;     }     sort(a + 1, a + m + 1);     for (long long i = 1; i <= m; i++) {       up[i] = (long long)i * (a[i + 1].cnt - a[i].cnt);       up[i] += up[i - 1];     }     for (long long _ = 1; _ <= q; _++) {       long long x;       scanf( %lld , &x);       x -= n;       qq[_] = (que){x, _};     }     sort(qq + 1, qq + q + 1);     doit();     for (long long i = 1; i <= q; i++) printf( %lld n , ans[i]);   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   template <class T1, class T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &p) {     os <<  {  << p.first <<  ,  << p.second <<  } ;     return os;   }   const int N = 3e5 + 5;   const int oo = 1e9 + 7;   const int LOGN = 30;   long long bigmod(long long a, long long p, long long m) {     long long res = 1;     long long x = a;     while (p) {       if (p & 1) {         res = (res * x) % m;       }       x = (x * x) % m;       p = p >> 1;     }     return res;   }   int basis[N][LOGN];   void insert_vec(int t, int x) {     for (int i = LOGN - 1; i >= 0; i--) basis[t][i] = basis[t - 1][i];     for (int i = LOGN - 1; i >= 0; i--) {       if ((x >> i) & 1) {         if (!basis[t][i]) {           basis[t][i] = x;           return;         } else {           x ^= basis[t][i];         }       }     }   }   int ans(int t, int x) {     int tot = t;     for (int i = LOGN - 1; i >= 0; i--) {       if (basis[t][i]) {         tot--;         if ((x >> i) & 1) x ^= basis[t][i];       } else {         if ((x >> i) & 1) return 0;       }     }     return bigmod(2, tot, oo);   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, q;     cin >> n >> q;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       insert_vec(i, x);     }     while (q--) {       int l, x;       cin >> l >> x;       cout << ans(l, x) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1LL << 61;   const long long mod = 1000000007;   const int maxn = 404;   bitset<maxn> cb[30][maxn];   bitset<maxn> ans[maxn];   bitset<maxn> shift(bitset<maxn> b, int len, int sh);   int main() {     std::ios::sync_with_stdio(false);     int i = 0, j = 0, k = 0;     int n, m, c, r;     scanf( %d%d , &n, &m);     getchar();     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         char ch = getchar();         cb[ch -  a ][i][j] = true;       }       getchar();     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         ans[i][j] = true;       }     }     scanf( %d%d , &r, &c);     getchar();     for (i = 0; i < r; i++) {       for (j = 0; j < c; j++) {         char ch = getchar();         if (ch ==  ? ) continue;         int shiftx = ((-i) % n + n) % n;         int shifty = j % m;         for (k = 0; k < n; k++) {           int nk = k + shiftx;           if (nk >= n) nk -= n;           ans[nk] &= shift(cb[ch -  a ][k], m, shifty);         }       }       getchar();     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         printf( %d , ans[i][j] ? 1 : 0);       }       puts(  );     }     return 0;   }   bitset<maxn> shift(bitset<maxn> b, int len, int sh) {     return (b >> sh) | (b << (len - sh));   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)3e5 + 10;   struct node {     int nxt, to;   } edg[maxn * 2];   int head[maxn], num;   int f[maxn], n, a[maxn];   void add(int a, int b) {     edg[++num].to = b;     edg[num].nxt = head[a];     head[a] = num;   }   int k = 0;   void dfs(int root) {     if (head[root] == 0) {       f[root] = 1;       k++;       return;     }     if (a[root] == 1) f[root] = 1e7;     int t = head[root];     while (t != 0) {       dfs(edg[t].to);       if (a[root] == 1) {         f[root] = min(f[root], f[edg[t].to]);       } else {         f[root] += f[edg[t].to];       }       t = edg[t].nxt;     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 2; i <= n; i++) {       int fat;       cin >> fat;       add(fat, i);     }     dfs(1);     cout << k + 1 - f[1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b, k, tt;   int tree1[800000], tree2[800000];   void updata1(int L, int R, int ro, int x, int v) {     if (x < L || x > R) return;     if (L == R && L == x) {       tree1[ro] = min(v + tree1[ro], b);       return;     }     int Mid = (L + R) / 2;     updata1(L, Mid, ro * 2, x, v);     updata1(Mid + 1, R, ro * 2 + 1, x, v);     tree1[ro] = tree1[ro * 2] + tree1[ro * 2 + 1];   }   void updata2(int L, int R, int ro, int x, int v) {     if (x < L || x > R) return;     if (L == R && L == x) {       tree2[ro] = min(v + tree2[ro], a);       return;     }     int Mid = (L + R) / 2;     updata2(L, Mid, ro * 2, x, v);     updata2(Mid + 1, R, ro * 2 + 1, x, v);     tree2[ro] = tree2[ro * 2] + tree2[ro * 2 + 1];   }   int quary1(int ro, int L, int R, int l, int r) {     if (r < L || l > R) return 0;     if (l <= L && R <= r) return tree1[ro];     int Mid = (L + R) / 2;     int x1 = quary1(ro * 2, L, Mid, l, r),         x2 = quary1(ro * 2 + 1, Mid + 1, R, l, r);     return x1 + x2;   }   int quary2(int ro, int L, int R, int l, int r) {     if (r < L || l > R) return 0;     if (l <= L && R <= r) return tree2[ro];     int Mid = (L + R) / 2;     int x1 = quary2(ro * 2, L, Mid, l, r),         x2 = quary2(ro * 2 + 1, Mid + 1, R, l, r);     return x1 + x2;   }   int main() {     scanf( %d%d%d%d%d , &n, &k, &a, &b, &tt);     for (int i = 1; i <= tt; i++) {       int a1, b1, c1;       scanf( %d , &a1);       if (a1 == 1) {         scanf( %d%d , &b1, &c1);         updata1(1, n, 1, b1, c1);         updata2(1, n, 1, b1, c1);       } else if (a1 == 2) {         scanf( %d , &b1);         printf( %d n , quary1(1, 1, n, 1, b1 - 1) + quary2(1, 1, n, b1 + k, n));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fa2[200007], fb2[200007];   bool f(int i, int j, long long y) {     long long x1, x2;     if ((y - fb2[i]) % fa2[i] == 0) {       x1 = (y - fb2[i]) / fa2[i];     } else       x1 = (y - fb2[i]) / fa2[i] + 1;     if ((y - fb2[j]) % fa2[j] == 0) {       x2 = (y - fb2[j]) / fa2[j];     } else       x2 = (y - fb2[j]) / fa2[j] + 1;     if (x1 == x2) {       return (x1 * fa2[i] + fb2[i]) <= (x2 * fa2[j] + fb2[j]);     }     return x1 > x2;   }   long long fcheck2(int i1, int i2, int i3) {     return (fa2[i2] - fa2[i1]) * (fb2[i3] - fb2[i2]) >=            (fb2[i2] - fb2[i1]) * (fa2[i3] - fa2[i2]);   }   long long f2(int i, long long x) { return fa2[i] * x + fb2[i]; }   long long ff(int i, long long y) {     long long x1, x2;     if ((y - fb2[i]) % fa2[i] == 0) {       x1 = (y - fb2[i]) / fa2[i];     } else       x1 = (y - fb2[i]) / fa2[i] + 1;     return x1;   }   struct Factory {     long long v, c;     bool operator<(const Factory &p) const {       if (c == p.c) return v > p.v;       return c < p.c;     }   } a[200007];   long long dpt[200007];   long long dpm[200007];   int dep[200007];   int dep2[200007];   int n;   long long s;   void solve() {     int l = 0, l2 = 0, r2 = 1;     fa2[0] = a[0].v;     fb2[0] = 0;     dep2[0] = 0;     for (int i = 0; i < n - 1; i++) {       while (l + 1 < r2 && f(dep2[l], dep2[l + 1], a[i + 1].c)) l++;       dpt[i + 1] = ff(dep2[l], a[i + 1].c);       while (l2 + 1 < r2 &&              f2(dep2[l2], dpt[i + 1]) < f2(dep2[l2 + 1], dpt[i + 1]))         l2++;       dpm[i + 1] = f2(dep2[l2], dpt[i + 1]) - a[i + 1].c;       fa2[i + 1] = a[i + 1].v;       fb2[i + 1] = dpm[i + 1] - a[i + 1].v * dpt[i + 1];       while (l2 + 1 < r2 && fcheck2(dep2[r2 - 2], dep2[r2 - 1], i + 1)) r2--;       dep2[r2++] = i + 1;     }   }   int main() {     scanf( %d%I64d , &n, &s);     for (int i = 0; i < n; i++) scanf( %I64d%I64d , &a[i].v, &a[i].c);     a[n].c = s;     a[n].v = 2000000000;     n++;     sort(a, a + n);     for (int i = 0; i < n; i++) {     }     int cnt = 0;     for (int i = 1; i < n; i++) {       if (a[i].v > a[cnt].v) {         cnt++;         a[cnt] = a[i];       }     }     cnt++;     n = cnt;     dpt[0] = 0;     dpm[0] = 0;     solve();     for (int i = 0; i < n; i++) {       if (a[i].c == s) {         printf( %I64d n , dpt[i]);         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, a, b, x, y, z, ans, g[3010 * 3010], h[3010][3010],       f[3010][3010];   deque<long long> q, zr;   int main() {     scanf( %lld%lld%lld%lld%lld%lld%lld%lld , &n, &m, &a, &b, g, &x, &y, &z);     for (int i = 1; i <= n * m; i++) g[i] = (g[i - 1] * x + y) % z;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) h[i][j] = g[(i - 1) * m + j - 1];     for (int i = 1; i <= n; i++) {       q = zr;       for (int j = 1; j <= m; j++) {         while (!q.empty() && h[i][q.back()] >= h[i][j]) q.pop_back();         while (!q.empty() && q.front() + b - 1 < j) q.pop_front();         q.push_back(j), f[i][j] = h[i][q.front()];       }     }     for (long long j = 1; j <= m; j++) {       while (!q.empty()) q.pop_front();       for (long long i = 1; i <= n; i++) {         while (!q.empty() && f[q.back()][j] >= f[i][j]) q.pop_back();         if (!q.empty() && q.front() + a - 1 < i) q.pop_front();         q.push_back(i);         if (i >= a && j >= b) ans += f[q.front()][j];       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pie = 3.14159265358979323846;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     double d, h, v, e, t = 0;     cin >> d >> h >> v >> e;     if (v <= (pie * (d / 2) * (d / 2) * e)) {       cout <<  NO n ;     } else {       t = (pie * (d / 2) * (d / 2) * h) / (v - (pie * (d / 2) * (d / 2) * e));       if (t <= 10000) {         cout <<  YES n  << fixed << setprecision(15) << t <<   n ;       } else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 35;   const int N = 2e5;   const long long mod = 1e7;   const double eps = 1e-6;   int a[MAX];   long long n;   long long ans;   pair<long long, long long> ch(long long x) {     long long x2 = n - x;     long long s = x;     s += (x2 * (x2 - 1)) / 2;     if (((s + 1) / 2) >= x) {       pair<long long, long long> k;       k.first = 1;       k.second = min(x * 2, s);       return k;     } else       return {0, 0};   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     int t;     cin >> t;     while (t--) {       ans = 0;       cin >> n;       if (n == 1) {         cout <<  0 n ;         continue;       }       long long l = 0;       long long r = n - 1;       while (l <= r) {         long long mid = (l + r) / 2;         if (ch(mid).first) {           ans = max(ans, ch(mid).second);           l = mid + 1;         } else           r = mid - 1;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     static int r, sign;     static char c;     r = 0, sign = 1;     do c = getchar();     while (c !=  -  && (c <  0  || c >  9 ));     if (c ==  - ) sign = -1, c = getchar();     while (c >=  0  && c <=  9 ) r = r * 10 + (int)(c -  0 ), c = getchar();     return sign * r;   }   template <typename T>   inline void print(T *a, int n) {     for (int i = 1; i < n; ++i) cout << a[i] <<    ;     cout << a[n] << endl;   }   struct inedge {     int a, b, w;     inline bool operator<(const inedge &x) const { return w < x.w; }   } ie[100000 + 1], p[100000 + 1];   struct edge {     int next, node;   } e[100000 << 1 | 1];   int head[100000 + 1], tot = 0;   inline void addedge(int a, int b) {     e[++tot].next = head[a];     head[a] = tot, e[tot].node = b;   }   int n, m, a[100000 + 1];   int f[100000 + 1], size[100000 + 1];   int find(int x) {     if (f[x] == x) return x;     int fa = f[x];     f[x] = find(fa);     return f[x];   }   void fusion(int a, int b) {     a = find(a), b = find(b);     f[a] = b, size[b] += size[a];   }   int main(int argc, char *argv[]) {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     for (int i = 1; i <= m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       ie[i].a = x, ie[i].b = y, ie[i].w = min(a[x], a[y]);     }     sort(ie + 1, ie + m + 1);     for (int i = 1; i <= n; ++i) f[i] = i;     int cnt = 0;     for (int i = m; i > 0; --i)       if (find(ie[i].a) != find(ie[i].b)) {         f[find(ie[i].a)] = find(ie[i].b);         addedge(ie[i].a, ie[i].b);         addedge(ie[i].b, ie[i].a);         p[++cnt] = ie[i];       }     long long ans = 0LL;     for (int i = 1; i <= n; ++i) f[i] = i, size[i] = 1;     for (int i = 1; i <= cnt; ++i) {       ans += (long long)p[i].w * size[find(p[i].a)] * size[find(p[i].b)];       fusion(p[i].a, p[i].b);     }     cout << fixed << setprecision(10) << (double)ans * 2LL / n / (n - 1) << endl;     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   const int dy[] = {-1, 1, 0, 0};   const int dx[] = {0, 0, -1, 1};   int n, m;   string s[1010];   int L[1010][1010];   int R[1010][1010];   int U[1010][1010];   int D[1010][1010];   int usedX[1010][1010], usedY[1010][1010];   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     cout << fixed << setprecision(10);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> s[i];     }     for (int i = 0; i < n; i++) {       L[i][0] = s[i][0] ==  * ;       for (int j = 1; j < m; j++) {         if (s[i][j] ==  . )           L[i][j] = 0;         else           L[i][j] = L[i][j - 1] + 1;       }       R[i][m - 1] = s[i][m - 1] ==  * ;       for (int j = m - 2; j >= 0; j--) {         if (s[i][j] ==  . )           R[i][j] = 0;         else           R[i][j] += R[i][j + 1] + 1;       }     }     for (int j = 0; j < m; j++) {       U[0][j] = s[0][j] ==  * ;       for (int i = 1; i < n; i++) {         if (s[i][j] ==  . )           U[i][j] = 0;         else           U[i][j] = U[i - 1][j] + 1;       }       D[n - 1][j] = s[n - 1][j] ==  * ;       for (int i = n - 2; i >= 0; i--) {         if (s[i][j] ==  . )           D[i][j] = 0;         else           D[i][j] += D[i + 1][j] + 1;       }     }     using P = tuple<int, int, int>;     vector<P> vs;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int mx = min({U[i][j], R[i][j], D[i][j], L[i][j]});         if (mx > 1) {           vs.emplace_back(i, j, mx - 1);           if (j - mx + 1 >= 0) usedX[i][j - mx + 1]++;           if (j + mx <= m) usedX[i][j + mx]--;           if (i - mx + 1 >= 0) usedY[i - mx + 1][j]++;           if (i + mx <= n) usedY[i + mx][j]--;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         usedX[i][j + 1] += usedX[i][j];       }     }     for (int j = 0; j < m; j++) {       for (int i = 0; i < n; i++) {         usedY[i + 1][j] += usedY[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] ==  *  && !(usedY[i][j] || usedX[i][j])) {           cout <<  -1  << endl;           return 0;         }       }     }     cout << vs.size() << endl;     for (auto v : vs) {       int y, x, p;       tie(y, x, p) = v;       cout << y + 1 <<     << x + 1 <<     << p << endl;     }     return 0;   }
#include <cstdio>   #include <cstdlib>   #include <cstring>   #include <cmath>   #include <ctime>   #include <iostream>   #include <algorithm>   #include <queue>   #include <map>   #include <set>   #include <vector>   #include <string>   #include <stack>   #include <numeric>   #include <cassert>      #define endl   n    #define sp          #define pb push_back   #define mp make_pair   #define ff first   #define ss second      using namespace std;      typedef long long ll;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;      const int maxn = 2e5+5;   set<pair<int,char>> adj[maxn];      int main(){              ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);       int n,m;cin>>n>>m;       set<pii> cift, samecift;       for(int q=0;q<m;q++){           char t;cin>>t;           if(t ==  + ){               int u,v;char c;cin>>u>>v>>c;               pair<int,char> p = {v,c};               adj[u].emplace(v,c);               auto it = adj[v].lower_bound({u,0});               if(it != adj[v].end() && it->ff == u){                   int setu = min(u,v);                   int setv = max(u,v);                   cift.emplace(setu,setv);                   if(it->ss == c){                       samecift.emplace(setu,setv);                   }               }           }           else if(t ==  - ){               int u,v;cin>>u>>v;               auto it = adj[u].lower_bound({v,0});               assert(it != adj[u].end());               adj[u].erase(it);               int setu = min(u,v);               int setv = max(u,v);               auto it2 = cift.find({setu,setv});               if(it2 != cift.end()){                   cift.erase(it2);                   it2 = samecift.find({setu,setv});                   if(it2 != samecift.end()){                       samecift.erase(it2);                   }               }           }           else{               int k;cin>>k;               if(k&1){                   if(cift.size()){                       cout <<  YES  << endl;                   }                   else                       cout <<  NO  << endl;               }               else{                   if(samecift.size()){                       cout <<  YES  << endl;                   }                   else{                       cout <<  NO  << endl;                   }               }                  }       }          }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 10;   int rd() {     int x = 0, w = 1;     char ch = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + (ch ^ 48);       ch = getchar();     }     return x * w;   }   int to[N], nt[N], hd[N], tot = 1;   void adde(int x, int y) { ++tot, to[tot] = y, nt[tot] = hd[x], hd[x] = tot; }   char cc[N];   int n, ans, f[N], g[N], s[N * 50], ch[N * 50][2], rt[N], tz;   void inst(int o, int x) {     s[o] = x;     int l = 1, r = n;     while (l < r) {       int mid = (l + r) >> 1;       if (x <= mid)         o = ch[o][0] = ++tz, r = mid;       else         o = ch[o][1] = ++tz, l = mid + 1;       s[o] = x;     }   }   int merg(int o1, int o2) {     if (!o1 || !o2) return o1 + o2;     int o = ++tz;     s[o] = max(s[o1], s[o2]);     ch[o][0] = merg(ch[o1][0], ch[o2][0]);     ch[o][1] = merg(ch[o1][1], ch[o2][1]);     return o;   }   int quer(int o, int l, int r, int ll, int rr) {     if (!o || ll > rr) return s[0];     if (ll <= l && r <= rr) return s[o];     int an = s[0], mid = (l + r) >> 1;     if (ll <= mid) an = max(an, quer(ch[o][0], l, mid, ll, rr));     if (rr > mid) an = max(an, quer(ch[o][1], mid + 1, r, ll, rr));     return an;   }   int fa[N], tn[N][26], len[N], la = 1, tt = 1;   void extd(int xx, int i) {     int np = ++tt, p = la;     len[np] = len[p] + 1, inst(rt[np] = ++tz, i), la = np;     while (p && !tn[p][xx]) tn[p][xx] = np, p = fa[p];     if (!p)       fa[np] = 1;     else {       int q = tn[p][xx];       if (len[q] == len[p] + 1)         fa[np] = q;       else {         int nq = ++tt;         fa[nq] = fa[q], len[nq] = len[p] + 1,         memcpy(tn[nq], tn[q], sizeof(int) * 26);         fa[np] = fa[q] = nq;         while (p && tn[p][xx] == q) tn[p][xx] = nq, p = fa[p];       }     }   }   void dfs1(int x) {     for (int i = hd[x]; i; i = nt[i]) {       int y = to[i];       dfs1(y), rt[x] = merg(rt[x], rt[y]);     }   }   void dfs2(int x) {     if (x > 1) {       if (fa[x] == 1 ||           quer(rt[g[x]], 1, n, s[rt[x]] - len[x] + len[g[x]], s[rt[x]] - 1) > 0)         ++f[x], g[x] = x;     }     ans = max(ans, f[x]);     for (int i = hd[x]; i; i = nt[i]) {       int y = to[i];       f[y] = f[x], g[y] = g[x], dfs2(y);     }   }   int main() {     n = rd(), scanf( %s , cc + 1);     s[0] = -(1 << 25);     for (int i = 1; i <= n; ++i) extd(cc[i] -  a , i);     for (int i = 2; i <= tt; ++i) adde(fa[i], i);     dfs1(1);     dfs2(1);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     int a[n];     for (int i = 0; i < (n); i++) cin >> a[i];     int b[n];     for (int i = 0; i < (n); i++) cin >> b[i];     set<int> rem;     int top = 0;     for (int i = 0; i < (n); i++) {       int curr = 0;       if (rem.find(b[i]) != rem.end()) {         cout << curr <<    ;         continue;       }       while (top < n) {         if (a[top + curr] != b[i]) {           rem.insert(a[top + curr]);           ++curr;         } else {           rem.insert(a[top + curr]);           break;         }       }       top += curr + 1;       cout << curr + 1 <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int a[5], maxx = -1, k;     for (int i = 0; i < 4; i++) {       scanf( %d , &a[i]);       if (maxx < a[i]) {         maxx = a[i];         k = i;       }     }     for (int i = 0; i < 4; i++) {       if (k == i) continue;       printf( %d  , maxx - a[i]);     }     printf(  n );   }