malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, k, trie[100100][27], sz = 1, ok[2][100100];   char s[100100];   void add() {     int v = 0;     for (int i = 0; s[i] !=   0 ; i++) {       if (trie[v][s[i] -  a ] == 0) trie[v][s[i] -  a ] = sz++;       v = trie[v][s[i] -  a ];     }   }   void calc(int v, bool bo, int temp[30]) {     int arr[5];     for (int i = 0; i < 5; i++) arr[i] = 0;     for (int i = 0; i < 26; i++) {       if (temp[i] == -1) continue;       if (temp[i] == 0) {         ok[bo][v] = 0;         break;       }       if (temp[i] == 1) {         if (arr[2]) {           ok[bo][v] = 0;           break;         }       }       if (temp[i] == 2) {         if (arr[1]) {           ok[bo][v] = 0;           break;         }       }       arr[temp[i]]++;     }     if (ok[bo][v] != 0)       ok[bo][v] = (arr[3] && !arr[1] && !arr[2] ? 3 : (arr[1] ? 1 : 2));   }   int dfs(int v, bool st, bool bo) {     int cnt = 0, temp[26];     for (int i = 0; i < 26; i++) temp[i] = -1;     for (int i = 0; i < 26; i++) {       if (!trie[v][i]) continue;       cnt++;       temp[i] = dfs(trie[v][i], !st, bo);       if (temp[i] == 1)         ok[bo][v] = (ok[bo][v] < 2 ? 1 : 3);       else if (temp[i] == 2)         ok[bo][v] = (ok[bo][v] == 2 || ok[bo][v] == 0 ? 2 : 3);       else if (temp[i] == 3)         ok[bo][v] = 3;     }     if (cnt > 1 && !st && !bo) calc(v, bo, temp);     if (cnt > 1 && st && bo) calc(v, bo, temp);     if (cnt == 0) ok[bo][v] = (st ? 2 : 1);     return ok[bo][v];   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %s , &s);       add();     }     dfs(0, 1, 0);     dfs(0, 1, 1);     if (ok[0][0] == 3)       printf( First n );     else if (ok[0][0] == 1) {       if (k % 2)         printf( First n );       else         printf( Second n );     } else if (ok[0][0] == 2)       printf( Second n );     else {       if (ok[1][0] == 3)         printf( Second n );       else if (ok[1][0] == 1) {         if (k % 2)           printf( First n );         else           printf( Second n );       } else if (ok[1][0] == 2)         printf( Second n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int t, id, n, m, x, y, k, c, p, dif, ans, sum, pre, rem, cur, tmp, tot, r, l, u,       d, xx, yy;   int a[N], vis[N], f[N], b[N], cu[N];   vector<int> v, adj[N];   bool fl, ok;   int dp[N];   int mem[N];   int sol(int i = n) {     int &ret = mem[i];     if (~ret) return ret;     if (!i) return ret = 0;     ret = sol(i - 1) + 20;     int B90 = upper_bound(a + 1, a + n + 1, a[i] - 90) - (a + 1);     ret = min(ret, sol(B90) + 50);     int Bday = upper_bound(a + 1, a + n + 1, a[i] - 1440) - (a + 1);     ret = min(ret, sol(Bday) + 120);     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= (int)n; ++i) scanf( %d , &a[i]);     memset(mem, -1, sizeof mem);     ;     sol();     for (int i = 1; i <= (int)n; ++i) printf( %d n , sol(i) - sol(i - 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   char maz[505][505];   int dp[10][505][505];   inline void cm(int& x) {     if (x >= mod) x -= mod;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %s , maz[i] + 1);     int up = (n + m - 1) / 2;     if (maz[1][1] != maz[n][m]) {       puts( 0 );       return 0;     }     dp[0][1][m] = 1;     for (int i = 0; i < up; ++i) {       int ni = (i + 1) & 1, li = i & 1;       memset(dp[ni], 0, sizeof(dp[ni]));       for (int j = 1; j <= m; ++j) {         int y1 = i + 2 - j;         if (y1 < 1 || y1 > n) continue;         for (int k = m; k >= 1; --k) {           int y2 = n + m - i - k;           if (y2 < 1 || y2 > n || maz[y1][j] != maz[y2][k]) continue;           if (y1 < n && y2 > 1 && maz[y1 + 1][j] == maz[y2 - 1][k])             dp[ni][j][k] += dp[li][j][k];           if (y1 < n && k > 1 && maz[y1 + 1][j] == maz[y2][k - 1])             dp[ni][j][k - 1] += dp[li][j][k];           if (j < m && y2 > 1 && maz[y1][j + 1] == maz[y2 - 1][k])             dp[ni][j + 1][k] += dp[li][j][k];           if (j < m && k > 1 && maz[y1][j + 1] == maz[y2][k - 1])             dp[ni][j + 1][k - 1] += dp[li][j][k];           cm(dp[ni][j][k]);           cm(dp[ni][j][k - 1]);           cm(dp[ni][j + 1][k]);           cm(dp[ni][j + 1][k - 1]);         }       }     }     int ans = 0;     if ((n + m - 1) % 2) {       for (int i = 1; i <= n; ++i) {         ans += dp[up & 1][up + 2 - i][up + 2 - i];         cm(ans);       }     } else {       up--;       for (int i = 1; i <= n; ++i) {         ans += dp[up & 1][up + 2 - i][up + 3 - i];         cm(ans);         ans += dp[up & 1][up + 2 - i][up + 2 - i];         cm(ans);       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   void task();   int main() {     task();     return 0;   }   const int N = 2e5 + 10;   const long long int MOD = (long long int)1e9 + 7;   const int INF = 0x3f3f3f3f;   const long long int LINF = (long long int)4e18 + 100;   const int BUF_SIZE = (int)1e6 + 10;   const double PI = acos(-1);   pair<int, int> a[N];   double u[N], ad[N], bd[N];   long long int sq_dist(long long int x1, long long int y1, long long int x2,                         long long int y2) {     return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);   }   double dist(long long int x1, long long int y1, long long int x2,               long long int y2) {     return sqrt(sq_dist(x1, y1, x2, y2));   }   double dp[N][2][2];   void task() {     int ai, aj, bi, bj, ui, uj;     cin >> ai >> aj >> bi >> bj >> ui >> uj;     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;     }     for (int i = 0; i < n; ++i) {       u[i] = dist(ui, uj, a[i].first, a[i].second);       (void(1));       ;     }     for (int i = 0; i < n; ++i) {       ad[i] = dist(ai, aj, a[i].first, a[i].second) + u[i];       (void(1));       ;     }     for (int i = 0; i < n; ++i) {       bd[i] = dist(bi, bj, a[i].first, a[i].second) + u[i];       (void(1));       ;     }     fill(dp[0][0], dp[0][0] + N * 2 * 2, LINF);     dp[0][1][1] = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < 2; ++j) {         for (int k = 0; k < 2; ++k) {           (void(1));           ;           if (j == 1) {             dp[i + 1][j - 1][k] = min(dp[i][j][k] + ad[i], dp[i + 1][j - 1][k]);           }           if (k == 1) {             dp[i + 1][j][k - 1] = min(dp[i][j][k] + bd[i], dp[i + 1][j][k - 1]);           }           dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k] + 2 * u[i]);         }       }     }     double ans = LINF;     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < 2; ++j)         if (!(i == 1 && j == 1)) {           (void(1));           ;           ans = min(ans, dp[n][i][j]);         }     }     cout << fixed << setprecision(12) << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int f = 1;       int s = 0;       vector<int> A;       for (int i = 0; i < n; i++) {         int a;         cin >> a;         A.push_back(a);       }       if (A.size() == 1) {         cout <<  First  << endl;         continue;       }       if (n == 2) {         if (A[0] != 1) {           cout <<  First  << endl;           continue;         } else {           cout <<  Second  << endl;           continue;         }       }       for (int i = 0; i < n - 2; i++) {         if (A[i] != 1 && A[i + 1] != 1) {           if (f == 1) {             f = 1;             s = 0;           } else {             s = 1;             f = 0;           }         } else if (A[i] != 1 && A[i + 1] == 1) {           int count = 0;           int j = i + 1;           while (A[j] == 1 && j <= n - 2) {             count++;             j++;           }           if (count % 2 == 1) {             if (f == 1) {               s = 1;               f = 0;             } else {               f = 1;               s = 0;             }           } else {             if (f == 1) {               f = 1;               s = 0;             } else {               s = 1;               f = 0;             }           }         } else if (A[i] == 1) {           if (f == 1) {             s = 1;             f = 0;           } else {             f = 1;             s = 0;           }         }       }       if (A[n - 2] != 1 && f == 1) {         cout <<  First  << endl;         continue;       } else if (A[n - 2] == 1 && f == 1) {         cout <<  Second  << endl;         continue;       } else if (A[n - 2] != 1 && s == 1) {         cout <<  Second  << endl;         continue;       } else if (A[n - 2] == 1 && s == 1) {         cout <<  First  << endl;         continue;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 500100;   multiset<pair<long long, long long> > intervals;   long long n, k;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < k; i++) intervals.insert(make_pair(0, i));     long long s, d;     for (int i = 0; i < n; i++) {       cin >> s >> d;       auto x = intervals.begin();       long long stx = (*x).first;       long long idx = (*x).second;       if (stx < s) stx = s;       stx += d;       cout << stx <<   n ;       intervals.erase(x);       intervals.insert(make_pair(stx, idx));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y;   };   vector<node> q;   int n, m, sum[2020][2020];   char g[2020][2020];   void init() {     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (g[i][j] ==  w ) q.push_back((node){i, j});     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (g[i][j] ==  w ) sum[i][j] = 1;     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (j - 1 >= 0) sum[i][j] = sum[i][j - 1] + sum[i][j];     for (int i = 0; i < (m); i++)       for (int j = 0; j < (n); j++)         if (j - 1 >= 0) sum[j][i] = sum[j - 1][i] + sum[j][i];   }   bool cmpx(node a, node b) { return a.x < b.x; }   bool cmpy(node a, node b) { return a.y < b.y; }   int getlen() {     int res = -1;     sort(q.begin(), q.end(), cmpx);     res = max(res, abs(q[0].x - q[q.size() - 1].x) + 1);     sort(q.begin(), q.end(), cmpy);     res = max(res, abs(q[0].y - q[q.size() - 1].y) + 1);     return res;   }   int getarea(int x1, int y1, int x2, int y2) {     if (x1 > x2 || y1 > y2) return 0;     int res = sum[x2][y2];     if (x1 - 1 >= 0) res -= sum[x1 - 1][y2];     if (y1 - 1 >= 0) res -= sum[x2][y1 - 1];     if (x1 - 1 >= 0 && y1 - 1 >= 0) res += sum[x1 - 1][y1 - 1];     return res;   }   bool check(int x, int y, int len) {     int x2 = x - len + 1;     int y2 = y - len + 1;     int in = getarea(x2 + 1, y2 + 1, x - 1, y - 1);     int out = getarea(0, 0, n - 1, m - 1) - getarea(x2, y2, x, y);     if (in || out)       return false;     else       return true;   }   void filling(int x, int y, int x2, int y2) {     for (int i = x; i <= x2; i++)       for (int j = y; j <= y2; j++)         if (i == x || i == x2 || j == y || j == y2)           g[i][j] = (g[i][j] ==  . ) ?  +  :  w ;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (n); i++) scanf( %s , g[i]);     init();     int len = getlen();     bool flg = 0;     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (i + 1 >= len && j + 1 >= len) {           if (flg) break;           if (check(i, j, len)) {             flg = true;             filling(i - len + 1, j - len + 1, i, j);             break;           }         }     if (flg)       for (int i = 0; i < (n); i++) printf( %s n , g[i]);     else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   void maximize(T &x, U y) {     if (x < y) x = y;   }   template <class T, class U>   void minimize(T &x, U y) {     if (x > y) x = y;   }   template <class T>   T Abs(T x) {     return (x < (T)0 ? -x : x);   }   template <class T>   T safe_sqrt(T x) {     return sqrt(max((T)0, x));   }   template <class T, class U, class V>   T addmod(T x, U k, V mod) {     return ((x + k) % mod + mod) % mod;   }   template <class T, class U, class V>   T submod(T x, U k, V mod) {     return ((x - k) % mod + mod) % mod;   }   template <class T, class U, class V>   T mulmod(T x, U k, V mod) {     return (int64_t)x * k % mod;   }   namespace task {   int64_t dp[11][100][1200];   int b;   int64_t l, r;   vector<int> digits;   vector<int> trans(int64_t x, int b) {     vector<int> vec;     while (x > 0) vec.push_back(x % b), x /= b;     return vec;   }   int64_t calc(int base, int idx, int mask, bool flag) {     if (idx == -1) return (mask == 0);     if (~dp[base][idx][mask] and flag) return dp[base][idx][mask];     int64_t ret = 0;     int k = flag ? b - 1 : digits[idx];     for (int i = 0; i <= k; ++i)       ret += calc(base, idx - 1, mask ^ ((1LL) << (i)), flag | (i < k));     if (flag) dp[base][idx][mask] = ret;     return ret;   }   int64_t f(int64_t x) {     if (!x) return 0ll;     digits.clear();     digits = trans(x, b);     int64_t ret = 0;     for (int i = 0; i < ((digits).size()); ++i) {       int up = (i == ((digits).size()) - 1 ? digits[i] : b - 1);       for (int j = 1; j <= up; ++j)         ret +=             calc(b, i - 1, ((1LL) << (j)), (i < ((digits).size()) - 1 or j < up));     }     return ret;   }   void solve() {     int q;     scanf( %d , &q);     memset(dp, -1ll, sizeof(dp));     while (q--) {       scanf( %d%I64d%I64d , &b, &l, &r);       int64_t x = f(r);       int64_t y = f(l - 1);       int64_t ans = f(r) - f(l - 1);       printf( %I64d n , ans);     }   }   }  // namespace task   int main(void) { task::solve(); }
#include <bits/stdc++.h>   using namespace std;   int n, a[1050];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int tens = a[0];     set<int> answer;     for (int rem = 0; rem < 10000000; rem++) {       double fuel = tens * 10 + static_cast<double>(rem) / 1000000;       double addend = fuel;       bool isValid = true;       for (int i = 0; isValid and i < n; i++) {         fuel -= (a[i] - (i == 0 ? 0 : a[i - 1])) * 10;         if (fuel < 0 or fuel >= 10 - 1e-6) {           isValid = false;         }         fuel += addend;       }       if (isValid) {         answer.insert(static_cast<int>(fuel) / 10 + a[n - 1]);       }     }     if (answer.size() > 1)       cout <<  not unique  << endl;     else       cout <<  unique  << endl << *answer.begin() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)2e5 + 10;   vector<pair<int, int> > a, b;   vector<int> L;   int n, m, q[MAXN], id[MAXN], Tohka[MAXN], l[MAXN], r[MAXN], t[MAXN], fa[MAXN],       T[MAXN];   bool cmp(int first, int second) { return q[first] < q[second]; }   bool cmp1(int first, int second) { return t[first] < t[second]; }   int Getp(int a) { return lower_bound(L.begin(), L.end(), a) - L.begin(); }   int getf(int first) {     if (fa[first] == first) return first;     fa[first] = getf(fa[first]);     return fa[first];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &l[i], &r[i], &t[i]);       L.push_back(l[i]), L.push_back(r[i]);       id[i] = i;     }     sort(L.begin(), L.end());     L.erase(unique(L.begin(), L.end()), L.end());     for (int i = 0; i < ((int)(L).size()); ++i) fa[i] = i;     sort(id + 1, id + m + 1, cmp1);     memset(T, -1, sizeof(T));     for (int i = 1; i <= m; ++i) {       int tl = Getp(l[id[i]]), tr = Getp(r[id[i]]), tT = t[id[i]];       for (tl = getf(tl); tl < tr; T[tl] = tT, fa[tl] = tl + 1, tl = getf(tl))         ;     }     for (int i = 0; i + 1 < ((int)(L).size()); ++i) {       int l = L[i], r = L[i + 1], t = T[i];       if (T[i] == -1) continue;       a.push_back(make_pair(t - r, 1)), a.push_back(make_pair(t - l, -1));       b.push_back(make_pair(t - r, -(t - r))),           b.push_back(make_pair(t - l, (t - r)));       b.push_back(make_pair(t - l, (r - l)));     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     for (int i = 1; i <= n; ++i) scanf( %d , &q[i]), id[i] = i;     sort(id + 1, id + n + 1, cmp);     long long s1 = 0, s2 = 0;     for (int i = 1, p1 = 0, p2 = 0; i <= n; ++i) {       for (; p1 < ((int)(a).size()) && a[p1].first <= q[id[i]];            s1 += a[p1].second, ++p1)         ;       for (; p2 < ((int)(b).size()) && b[p2].first <= q[id[i]];            s2 += b[p2].second, ++p2)         ;       Tohka[id[i]] = s1 * q[id[i]] + s2;     }     for (int i = 1; i <= n; ++i) printf( %d n , Tohka[i]);     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int n, i;     cin >> n;     long long int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     if (n == 1) {       cout << a[0];       return 0;     }     sort(a, a + n);     long long int sum = 0;     if (a[0] >= 0) {       sum = -1 * a[0];       for (i = 1; i < n; i++) {         sum += a[i];       }     } else if (a[n - 1] < 0) {       sum = a[n - 1];       for (i = 0; i < n - 1; i++) {         sum -= a[i];       }     } else {       for (i = 0; i < n; i++) {         if (a[i] < 0) {           sum -= a[i];         } else {           sum += a[i];         }       }     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 6;   const long long M = 1e9 + 7;   const double eps = 1e-7;   int a[N];   int Int() {     int x;     scanf( %d , &x);     return x;   }   long long Lnt() {     long long x;     scanf( %I64d , &x);     return x;   }   long long Bigmod(long long A, long long B, long long C) {     if (B == 0LL) return 1LL;     long long x = Bigmod(A, B / 2LL, C);     x = (x * x) % C;     if (B % 2 == 1) x = (x * A) % C;     return x;   }   struct mar {     int i, j, c, d;   } cr[N];   bool cmp(mar a, mar b) {     if (a.i == b.i) return a.j < b.j;     return a.i < b.i;   }   bool Cmp(int a, int b) { return a > b; }   void print(int n) { printf( %d n , n); }   void Print(long long n) { printf( %I64d n , n); }   void debug(int n) { printf( %d  , n); }   int main() {     int x1 = Int(), x2 = Int(), x3 = Int(), x4 = Int(), x5 = Int(), x6 = Int();     int c = x3 + x5;     int d = max(x4, x6);     if (x1 > x2) swap(x1, x2);     if ((x1 >= c && x2 >= d) or (x2 >= c && x1 >= d)) return puts( YES ), 0;     c = x3 + x6;     d = max(x4, x5);     if ((x1 >= c && x2 >= d) or (x1 >= d and x2 >= c)) return puts( YES ), 0;     c = x4 + x5;     d = max(x3, x6);     if ((x1 >= c && x2 >= d) or (x1 >= d and x2 >= c)) return puts( YES ), 0;     c = x4 + x6;     d = max(x3, x5);     if ((x1 >= c && x2 >= d) or (x1 >= d and x2 >= c)) return puts( YES ), 0;     return puts( NO );   }
#include <bits/stdc++.h>   using namespace std;   long long int a[2005];   long long int cnt[2005];   long long int b[2005];   long long int vis[2005];   vector<long long int> v;   vector<long long int> vv;   vector<long long int> ans;   long long int prime[2005];   bool pr[2005];   set<char> st;   priority_queue<long long int> bob;   priority_queue<long long int> ali;   priority_queue<long long int> bth;   queue<long long int> q;   map<long long int, long long int> mp;   long long int taken[105];   map<long long int, long long int>::iterator it;   map<long long int, vector<long long int> > ck;   string ss, tt;   long long int pos[205];   long long int afs[205];   long long int pre[2005];   long long int aa[2005];   long long int cs[27];   long long int ct[27];   long long int power(long long int k, long long int i) {     long long int res = 1;     for (long long int j = 1; j <= i; j++) {       res = res * k;     }     return res;   }   int main() {     long long int n, i, j, k, t, m;     cin >> t;     long long int minis;     long long int res;     long long int x, y;     long long int pp;     string fg;     long long int l, r;     long long int h;     long long int p, q;     string tt;     while (t--) {       v.clear();       cin >> n;       cin >> ss >> tt;       string fg;       long long int kk = n;       res = 0;       for (i = n - 1; i >= 0; i--) {         if (ss[i] == tt[i]) {           kk--;           continue;         } else {           if (ss[0] == tt[i]) {             res = res + 1;             v.push_back(1);             if (ss[0] ==  0 )               ss[0] =  1 ;             else               ss[0] =  0 ;           }           fg.clear();           for (j = 0; j <= i; j++) {             if (ss[j] ==  0 )               fg.push_back( 1 );             else               fg.push_back( 0 );           }           reverse(fg.begin(), fg.end());           res = res + 1;           v.push_back(kk);           for (j = 0; j <= i; j++) {             ss[j] = fg[j];           }         }         kk--;       }       cout << res <<    ;       for (i = 0; i < v.size(); i++) cout << v[i] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = (int)int(s.size());     int num = (s[n - 1] -  0 ) + 10 * (s[n - 2] -  0 );     if (num % 4 == 0)       cout << 4;     else       cout << 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void dfs(long long a, long long b, char A, char B) {     if (a == 1 && b == 1) return;     if (a < b) swap(a, b), swap(A, B);     printf( %I64d%c , (a - 1) / b, A);     dfs(a - (a - 1) / b * b, b, A, B);   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     long long a, b;     cin >> a >> b;     if (gcd(a, b) != 1) {       puts( Impossible );       return 0;     }     dfs(a, b,  A ,  B );     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int q, ans;   char s[300010];   set<int> len, hs[300010];   int p[300010], v[300010];   int main() {     int i, l, op;     for (i = 1, p[0] = 1; i <= 300000; ++i)       p[i] = 1LL * p[i - 1] * 27 % 1000000007;     scanf( %d , &q);     while (q--) {       scanf( %d%s , &op, s + 1);       l = strlen(s + 1);       for (i = 1, v[0] = 0; i <= l; ++i)         v[i] = (1LL * v[i - 1] * 27 + s[i] -  a  + 1) % 1000000007;       if (op == 1) {         len.insert(l);         hs[l].insert(v[l]);       } else if (op == 2)         hs[l].erase(v[l]);       else {         ans = 0;         for (auto it = len.begin(); it != len.end(); it++)           for (i = *it; i <= l; i++)             ans += (hs[*it].find((v[i] - 1LL * v[i - *it] * p[*it] % 1000000007 +                                   1000000007) %                                  1000000007) != hs[*it].end());         printf( %d n , ans);         fflush(stdout);       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   const long long int INF = 2e18;   int nex[20000][35];   int at[35];   int main() {     string f, s;     cin >> f >> s;     memset(nex, -1, sizeof nex);     memset(at, -1, sizeof at);     for (int i = 0; i < f.size(); i++) {       int he = f[i] -  a ;       if (at[he] == -1) {         at[he] = i;       }     }     for (int i = f.size() - 1; i >= 0; i--) {       for (int j = 0; j < 35; j++) {         nex[i][j] = at[j];       }       at[f[i] -  a ] = i;     }     int now = (f[0] == s[0] ? 0 : nex[0][s[0] -  a ]);     int cur = 0;     int cnt = 1;     while (cur < s.size()) {       if (now == -1) {         cout << -1;         return 0;       }       cur++;       if (cur == s.size()) break;       int gogo = nex[now][s[cur] -  a ];       if (gogo == -1) {         cout << -1;         return 0;       }       if (gogo <= now) {         cnt++;       }       now = gogo;     }     cout << cnt;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> dis(n + 1, n), cnt(n + 1, -1);     while (m--) {       int a, b;       cin >> a >> b;       ++cnt[a];       dis[a] = min(dis[a], a > b ? b - a + n : b - a);     }     for (int i = 1; i <= n; ++i) {       int res = 0;       for (int j = 1; j <= n; ++j)         if (~cnt[j])           res = max(res, (i > j ? j - i + n : j - i) + cnt[j] * n + dis[j]);       cout << res <<    ;     }     cout << endl;   }