malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void solve();   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();       cout <<   n ;     }     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }   long long num(long long x, long long n, long long m) {     long long res = 0;     --x;     for (long long i = 1; i <= n; i++) res += min(x / i, m);     return res;   }   void solve() {     long long n, m;     cin >> n >> m;     long long k;     cin >> k;     long long l = 1;     long long r = n * m + 1;     while (l < r) {       long long x = (l + r) >> 1;       if (num(x, n, m) < k)         l = x + 1;       else         r = x;     }     cout << l - 1;     return;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[210000], pos[210000], Log2[210000];   int f[210000][21];   void init() {     for (int i = 1; i <= n; i++) f[i][0] = i;     for (int j = 1; (1 << j) <= n; j++)       for (int i = 1; i + (1 << j) - 1 <= n; i++)         if (a[f[i][j - 1]] > a[f[i + (1 << (j - 1))][j - 1]])           f[i][j] = f[i][j - 1];         else           f[i][j] = f[i + (1 << (j - 1))][j - 1];   }   int query(int l, int r) {     int k = Log2[r - l + 1];     if (a[f[l][k]] > a[f[r - (1 << k) + 1][k]])       return f[l][k];     else       return f[r - (1 << k) + 1][k];   }   int dfs(int l, int r) {     if (l >= r) return 0;     int k = query(l, r), ans = 0, v;     if (k - l <= r - k)       for (int i = l; i <= k; i++) {         v = a[k] - a[i];         if (pos[v] > k && pos[v] <= r) ans++;       }     else       for (int i = k + 1; i <= r; i++) {         v = a[k] - a[i];         if (pos[v] >= l && pos[v] <= k) ans++;       }     return ans + dfs(l, k - 1) + dfs(k + 1, r);   }   int main() {     scanf( %d , &n);     Log2[0] = -1;     for (int i = 1; i <= n; i++) Log2[i] = Log2[i >> 1] + 1;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       pos[a[i]] = i;     }     init();     printf( %d n , dfs(1, n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, f, k, ans, now;   int main() {     scanf( %d%d%d%d , &a, &b, &f, &k);     if (b < f) {       printf( -1 );       return 0;     }     now = b - f;     for (int i = 1; i <= k; i++) {       if (i % 2) {         if (b < (a - f) + (a - f) * (i != k)) return printf( -1 ), 0;         if (now < (a - f) + (a - f) * (i != k)) now = b, ans++;         now -= 2 * (a - f);       } else {         if (b < f + f * (i != k)) return printf( -1 ), 0;         if (now < f + f * (i != k)) now = b, ans++;         now -= 2 * f;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   #pragma GCC optimize(2)   using namespace std;   set<int> st;   set<pair<long long, int>> bus[200011];   map<long long, set<pair<int, int>>> q;   int n, k, m;   int main() {     int i;     scanf( %d%d%d , &n, &k, &m);     for (i = 1; i <= k; ++i) {       int xi;       scanf( %d , &xi);       st.insert(xi);       bus[xi].insert(make_pair(0, i));     }     while (m-- > 0) {       long long ti;       int a, b;       scanf( %I64d%d%d , &ti, &a, &b);       while (!q.empty()) {         auto iter = q.begin();         if (iter->first > ti) break;         for (auto p : iter->second) {           st.insert(p.first);           bus[p.first].insert(make_pair(iter->first, p.second));         }         q.erase(iter->first);       }       if (!st.empty()) {         auto iter = st.upper_bound(a);         pair<int, pair<long long, int>> car =             make_pair(1e6, make_pair(1e14, 1e6));         bool ok = false;         if (iter != st.end()) {           car.first = *iter;           car.second = *bus[car.first].begin();           ok = true;         }         if (iter != st.begin()) {           iter = prev(iter);           if (ok) {             int pos = *iter;             if ((abs(pos - a) < abs(car.first - a)) ||                 (abs(pos - a) == abs(car.first - a) &&                  car.second > *bus[pos].begin())) {               car.first = pos;               car.second = *bus[pos].begin();             }           } else {             car.first = *iter;             car.second = *bus[car.first].begin();           }         }         printf( %d %d n , car.second.second, abs(car.first - a));         bus[car.first].erase(car.second);         if (bus[car.first].empty()) st.erase(car.first);         long long finish = ti + abs(car.first - a) + abs(b - a);         q[finish].insert(make_pair(b, car.second.second));       } else {         long long t = q.begin()->first;         auto iter = q[t].upper_bound(make_pair(a, 0));         pair<int, int> car = make_pair(0, 0);         if (iter != q[t].end()) {           car = *iter;         }         if (iter != q[t].begin()) {           iter = prev(iter);           iter = q[t].upper_bound(make_pair(iter->first, 0));           if (car.first != 0) {             if ((abs(car.first - a) > abs(iter->first - a)) ||                 ((abs(car.first - a) == abs(iter->first - a)) &&                  car.second > iter->second)) {               car = *iter;             }           } else {             car = *iter;           }         }         printf( %d %I64d n , car.second, abs(t - ti) + abs(car.first - a));         q[t].erase(car);         if (q[t].empty()) q.erase(t);         q[t + abs(car.first - a) + abs(b - a)].insert(make_pair(b, car.second));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 10;   const long long mod = 1e9 + 7;   long long ans;   long long n, k;   long long a[maxn];   long long z;   long long inv[maxn];   long long fact[maxn];   long long pashm[maxn];   void in();   void solve();   long long pwr(long long, long long);   long long oof(long long, long long);   long long C(long long, long long);   void out();   int main() {     ios::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     in();     solve();     out();   }   void in() {     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> a[i];   }   void solve() {     fact[0] = 1;     for (long long i = 1; i < maxn; i++) fact[i] = fact[i - 1] * i % mod;     inv[maxn - 1] = pwr(fact[maxn - 1], -1);     for (long long i = maxn - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;     long long sum = 0;     for (long long i = 0; i < n; i++) sum = (sum + a[i]) % mod;     z = (oof(n, k) + oof(n - 1, k) * (n - 1) % mod) % mod;     ans = (ans + sum * z % mod) % mod;   }   long long oof(long long a, long long b) {     long long z = 0;     for (long long i = b; i >= 0; i--) {       long long Z = 1;       if ((b - i) % 2) Z *= -1;       z = (z + Z * pwr(i, a) % mod * C(b, i) % mod + mod) % mod;     }     z *= inv[b];     return z % mod;   }   long long pwr(long long a, long long b) {     if (b < 0) return pwr(a, b + mod - 1);     if (b == 0) return 1;     long long c = pwr(a, b / 2);     if (b % 2) return c * c % mod * a % mod;     return c * c % mod;   }   long long C(long long n, long long k) {     if (n == k) return 1;     if (k > n) return 0;     return fact[n] * inv[k] % mod * inv[n - k] % mod;   }   void out() { cout << ans; }
#include <bits/stdc++.h>   using namespace std;   constexpr int maxn = 3e5 + 10, inf = 0x3f3f3f3f;   int a[maxn], qtd[2 * maxn];   long long ans;   void solve(int l, int r) {     if (l == r) return (void)(++ans);     int m = (l + r) >> 1;     solve(l, m);     solve(m + 1, r);     int Mn = inf, Mx = 0;     for (int i = m, ptr = m + 1; i >= l; i--) {       bool trocou = 0;       if (a[i] > Mx || a[i] < Mn) trocou = 1;       Mx = max(Mx, a[i]);       Mn = min(Mn, a[i]);       for (; ptr <= r && a[ptr] < Mx && a[ptr] > Mn; ptr++)         ;       if (trocou && ptr > m + 1)         ans += ptr - i >= Mx - Mn + 1;       else if (ptr > m + 1)         ans += ptr - i == Mx - Mn + 1;     }     Mn = inf, Mx = 0;     for (int i = m + 1, ptr = m; i <= r; i++) {       bool trocou = 0;       if (a[i] > Mx || a[i] < Mn) trocou = 1;       Mx = max(Mx, a[i]);       Mn = min(Mn, a[i]);       for (; ptr >= l && a[ptr] < Mx && a[ptr] > Mn; ptr--)         ;       if (trocou && ptr < m)         ans += i - ptr >= Mx - Mn + 1;       else if (ptr < m)         ans += i - ptr == Mx - Mn + 1;     }     Mn = inf, Mx = 0;     int MnR1 = inf, MnR2 = inf, ptr_mx = m + 1, ptr_mn = m + 1;     for (int i = m; i >= l; i--) {       Mx = max(Mx, a[i]);       Mn = min(Mn, a[i]);       for (; ptr_mn <= r && a[ptr_mn] > Mn; ptr_mn++)         MnR1 = min(MnR1, a[ptr_mn]), qtd[MnR1 + ptr_mn]--;       for (; ptr_mx <= r && a[ptr_mx] < Mx; ptr_mx++)         MnR2 = min(MnR2, a[ptr_mx]), qtd[MnR2 + ptr_mx]++;       ans += max(0, qtd[Mx + i]);     }     for (; ptr_mn < ptr_mx; ptr_mn++)       MnR1 = min(MnR1, a[ptr_mn]), qtd[MnR1 + ptr_mn]--;     for (; ptr_mx < ptr_mn; ptr_mx++)       MnR2 = min(MnR2, a[ptr_mx]), qtd[MnR2 + ptr_mx]++;     Mn = inf, Mx = 0, ptr_mx = m + 1, ptr_mn = m + 1;     int MxR1 = 0, MxR2 = 0;     for (int i = m; i >= l; i--) {       Mx = max(Mx, a[i]);       Mn = min(Mn, a[i]);       for (; ptr_mn <= r && a[ptr_mn] > Mn; ptr_mn++)         MxR1 = max(MxR1, a[ptr_mn]), qtd[ptr_mn - MxR1 + maxn]++;       for (; ptr_mx <= r && a[ptr_mx] < Mx; ptr_mx++)         MxR2 = max(MxR2, a[ptr_mx]), qtd[ptr_mx - MxR2 + maxn]--;       ans += max(0, qtd[i - Mn + maxn]);     }     for (; ptr_mn < ptr_mx; ptr_mn++)       MxR1 = max(MxR1, a[ptr_mn]), qtd[ptr_mn - MxR1 + maxn]++;     for (; ptr_mx < ptr_mn; ptr_mx++)       MxR2 = max(MxR2, a[ptr_mx]), qtd[ptr_mx - MxR2 + maxn]--;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0, x, y; i < n; i++) scanf( %d %d , &x, &y), a[x] = y;     solve(1, n);     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int a[300005];   int b[300005];   int flag;   int main() {     int n, m;     cin >> n >> m;     int i = 0, j = 0;     for (i = 0; i < m; i++) {       cin >> a[i];       cin >> b[i];       j++;     }     int hh = a[0], ff = b[0];     int cc, fff;     int temp = 0;     for (int i = 0; i < m; i++) {       if (a[i] == hh || b[i] == ff || a[i] == ff || b[i] == hh)         continue;       else {         temp = 1;         cc = a[i];         fff = b[i];         break;       }     }     if (temp == 0) {       printf( YES );       return 0;     }     int sum = 0;     for (int i = 0; i < m; i++) {       if ((a[i] != hh && b[i] != hh) && (a[i] != cc && b[i] != cc)) sum++;     }     if (sum == 0) {       printf( YES );       return 0;     }     sum = 0;     for (int i = 0; i < m; i++) {       if ((a[i] != hh && b[i] != hh) && (a[i] != fff && b[i] != fff)) sum++;     }     if (sum == 0) {       printf( YES );       return 0;     }     sum = 0;     for (int i = 0; i < m; i++) {       if ((a[i] != ff && b[i] != ff) && (a[i] != cc && b[i] != cc)) sum++;     }     if (sum == 0) {       printf( YES );       return 0;     }     sum = 0;     for (int i = 0; i < m; i++) {       if ((a[i] != ff && b[i] != ff) && (a[i] != fff && b[i] != fff)) sum++;     }     if (sum == 0) {       printf( YES );       return 0;     }     if (sum != 0) printf( NO );   }
#include <bits/stdc++.h>   using namespace std;   bool SR(int &x) { return scanf( %d , &x) == 1; }   bool SR(long long &x) { return scanf( %lld , &x) == 1; }   bool SR(double &x) { return scanf( %lf , &x) == 1; }   bool SR(char *s) { return scanf( %s , s) == 1; }   bool RI() { return true; }   template <typename I, typename... T>   bool RI(I &x, T &...tail) {     return SR(x) && RI(tail...);   }   void SP(const int x) { printf( %d , x); }   void SP(const long long x) { printf( %lld , x); }   void SP(const double x) { printf( %.16lf , x); }   void SP(const char *s) { printf( %s , s); }   void PL() { puts(  ); }   template <typename I, typename... T>   void PL(const I x, const T... tail) {     SP(x);     if (sizeof...(tail)) putchar(   );     PL(tail...);   }   const int maxn = 3e5 + 5;   int n, m, k;   vector<int> edge[maxn];   vector<int> vol;   int src, tar;   void read() {     RI(n, m, k);     vol.resize(k);     for (int i = 0; i < int(k); i++) RI(vol[i]);     for (int i = (1); i <= int(m); i++) {       int a, b;       RI(a, b);       edge[a].push_back(n + i);       edge[n + i].push_back(a);       edge[b].push_back(n + i);       edge[n + i].push_back(b);     }     RI(src, tar);   }   struct Dsu {     int par[maxn];     void init() {       for (int i = (1); i <= int(n); i++) par[i] = i;     }     int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }     void merge(int a, int b) { par[find(a)] = find(b); }   } dsu;   void build() {     n += m;     dsu.init();     if (find((vol).begin(), (vol).end(), tar) == vol.end())       vol.push_back(tar), k++;   }   bitset<maxn> vis;   void sol() {     vector<int> prv, cur;     cur = vol;     for (int ans = (1); ans <= int(maxn); ans++) {       prv.swap(cur);       cur.clear();       for (auto u : prv)         if (!vis[u]) {           vis[u] = 1;           for (auto v : edge[u]) dsu.merge(u, v);           cur.insert(cur.end(), (edge[u]).begin(), (edge[u]).end());         }       if (dsu.find(src) == dsu.find(tar)) {         PL(ans);         return;       }     }     PL(-1);   }   int main() {     read();     build();     sol();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long n, m;     long long result = 0;     cin >> n >> m;     if (n > m) {       swap(n, m);     }     for (long long i = 1; i <= n; i++) {       if (i + m < 5) continue;       int r = 5 - (i % 5);       result++;       result += (m - r) / 5;     }     cout << result << endl;   }
#include <bits/stdc++.h>   using namespace std;   double C[55][55], dp[55][55][55];   int a[55], n, m;   double dfs(int i, int j, int k) {     if (dp[i][j][k] != -1.0) return dp[i][j][k];     double ret = 0;     for (int c = 0; c <= i; c++) {       int maxq = max(k, int((c + a[j] - 1) / a[j]));       ret += dfs(i - c, j - 1, maxq) * C[i][c] * pow(j - 1, i - c) / pow(j, i);     }     return dp[i][j][k] = ret;   }   int main() {     int i, j, k, maxq;     memset(C, 0, sizeof(C));     C[0][0] = 1;     for (i = 1; i <= 50; i++) {       C[i][0] = 1;       for (j = 1; j <= i; j++) {         C[i][j] = C[i - 1][j - 1] + C[i - 1][j];       }     }     while (cin >> n >> m) {       for (i = 1; i <= m; i++) scanf( %d , &a[i]);       for (i = 0; i <= 50; i++)         for (j = 0; j <= 50; j++)           for (k = 0; k <= 50; k++) dp[i][j][k] = -1.0;       for (i = 0; i <= n; i++) {         dp[0][0][i] = i;         for (k = 0; k <= 50; k++) dp[i][0][k] = 0;       }       printf( %.12f n , dfs(n, m, 0));     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 200005;   int visited[MAX];   int a[MAX], dis[MAX];   int n;   void bfs() {     queue<int> q;     int b;     visited[1] = 1;     dis[1] = 0;     q.push(1);     while (!q.empty()) {       b = q.front();       q.pop();       if (!visited[b + 1] && b + 1 <= n) {         visited[b + 1] = 1;         dis[b + 1] = dis[b] + 1;         q.push(b + 1);       }       if (!visited[b - 1] && b - 1 > 0) {         visited[b - 1] = 1;         dis[b - 1] = dis[b] + 1;         q.push(b - 1);       }       if (!visited[a[b]]) {         visited[a[b]] = 1;         dis[a[b]] = dis[b] + 1;         q.push(a[b]);       }     }   }   int main() {     while (cin >> n) {       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       memset(visited, 0, sizeof(visited));       bfs();       for (int i = 1; i <= n; i++) {         if (i == 1)           cout << dis[i];         else           cout <<     << dis[i];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long int gcd(long long int A, long long int B) {     if (!B) return A;     return gcd(B, A % B);   }   int main() {     int n;     string s;     cin >> n >> s;     vector<int> pbal(n + 2), sbal(n + 2);     vector<bool> pref(n + 1, 1), suff(n + 1, 1);     for (int i = 1; i <= n; i++) {       if (s[i - 1] ==  ( )         pbal[i]++;       else         pbal[i]--;       pbal[i] += pbal[i - 1];       if (pref[i - 1] && pbal[i] >= 0)         pref[i] = 1;       else         pref[i] = 0;     }     for (int i = n; i > 0; i--) {       if (s[i - 1] ==  ) )         sbal[i]--;       else         sbal[i]++;       sbal[i] += sbal[i + 1];       if (suff[i + 1] && sbal[i] <= 0)         suff[i] = 1;       else         suff[i] = 0;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (!pref[i - 1] || !suff[i + 1])         continue;       else {         if (s[i - 1] ==  ( ) {           if (pbal[i - 1] > 0 && pbal[i - 1] - 1 + sbal[i + 1] == 0) ans++;         } else {           if (sbal[i + 1] < 0 && pbal[i - 1] + 1 + sbal[i + 1] == 0) ans++;         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int level[10];   int loyal[10];   int n, A;   double calculate(int cur, int pass, int B, double rate) {     double sum;     if (cur == n) {       if (pass > n / 2) {         return rate;       } else         return rate * (double(A) / (double)(A + B));     }     sum = 0;     sum = sum + calculate(cur + 1, pass, B + level[cur],                           (rate * (double(100 - loyal[cur])) / 100.0));     sum = sum +           calculate(cur + 1, pass + 1, B, (rate * double(loyal[cur])) / 100.0);     return sum;   }   double dfs(int cur, int k) {     if (k == 0) {       return calculate(0, 0, 0, 1.0);     }     if (cur == n) return calculate(0, 0, 0, 1.0);     double a = 0.0;     double temp;     int ori = loyal[cur];     while (loyal[cur] <= 100 && k >= 0) {       temp = dfs(cur + 1, k);       if (temp > a) a = temp;       loyal[cur] = loyal[cur] + 10;       k--;     }     loyal[cur] = ori;     return a;   }   int main() {     int k, i;     scanf( %d%d%d , &n, &k, &A);     for (i = 0; i < n; i++) {       scanf( %d%d , &level[i], &loyal[i]);     }     printf( %.10lf n , dfs(0, k));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   struct edge {     int v, next;   } e[500100];   int head[100100], tot = 0;   void Add(int u, int v) {     e[tot].v = v;     e[tot].next = head[u];     head[u] = tot++;   }   int res[100100];   int deep[100100];   int vis[100100];   void DFS(int u) {     vis[u] = 1;     for (int i = head[u]; i != -1; i = e[i].next) {       int v = e[i].v;       if (deep[v] <= 2 && !vis[v]) DFS(v);     }   }   int main() {     memset((head), (-1), sizeof(head));     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       Add(u, v);       Add(v, u);       deep[u]++;       deep[v]++;     }     for (int i = 1; i <= n; i++) {       if (deep[i] == 1) DFS(i);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         for (int j = head[i]; j != -1; j = e[j].next) {           int v = e[j].v;           if (vis[v]) {             res[i] = min(res[i] + 1, 2);           }         }       }     }     for (int u = 1; u <= n; u++) {       if (!vis[u]) {         int cnt = 0;         for (int i = head[u]; i != -1; i = e[i].next) {           int v = e[i].v;           if (!vis[v] && deep[v] - res[v] > 1) cnt++;         }         if (cnt > 2) {           cout <<  No  << endl;           return 0;         }       }     }     cout <<  Yes  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   long long x, y, z, a, b, c, sum, ans, total, t, cnt, n, m, k, p, kase;   string s1, s2;   map<long long, long long> mp;   set<long long> s;   map<long long, long long>::iterator itr1, ptr1;   set<long long>::iterator itr, ptr;   int main() {     a += 100;     cin >> t;     while (t--) {       cin >> a >> b >> c;       if (a < c) {         cout << 1 <<    ;         if ((b * a) > c)           cout << b << endl;         else           cout <<  -1  << endl;       } else if (a == c) {         if (b != 1) {           cout <<  -1                 <<     << b << endl;         } else           cout <<  -1                 <<                    <<  -1  << endl;       } else {         cout <<  -1               <<     << b << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int num = 0;     bool f = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       f = (ch ==  - );       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       num = (num << 1) + (num << 3) + ch -  0 ;       ch = getchar();     }     return f ? -num : num;   }   int n, m;   int deg[111];   vector<int> vec[111];   int topsort() {     int res = 0, fl = 1;     queue<int> Q;     while (fl) {       fl = 0;       for (int i = 1; i <= n; i++)         if (deg[i] == 1) Q.push(i), fl = 1;       while (!Q.empty()) {         int u = Q.front();         Q.pop();         deg[u]--;         for (int v : vec[u]) deg[v]--;       }       if (fl) res++;     }     return res;   }   int main() {     n = read(), m = read();     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       deg[x]++, deg[y]++;       vec[x].push_back(y);       vec[y].push_back(x);     }     printf( %d n , topsort());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int AS = 26;   struct vertex {     int next[AS];     bool leaf = false;     multiset<int> st;     int mx = 0;     int p = -1;     int length = 0;     char pch;     int link = -1;     int elink = -1;     int go[AS];     vertex(int p = -1, char ch =  $ ) : p(p), pch(ch) {       fill(begin(next), end(next), -1);       fill(begin(go), end(go), -1);     }   };   vector<vertex> trie(1000000);   int cur_size = 1;   int addString(string const& s) {     int v = 0;     for (char ch : s) {       int c = ch -  a ;       if (trie[v].next[c] == -1) {         trie[v].next[c] = cur_size;         trie[cur_size].p = v;         trie[cur_size].pch = ch;         cur_size++;       }       v = trie[v].next[c];     }     trie[v].length = s.length();     trie[v].st.insert(0);     trie[v].leaf = true;     return v;   }   int go(int v, char ch);   int get_link(int v) {     if (trie[v].link == -1) {       if (v == 0 || trie[v].p == 0)         trie[v].link = 0;       else         trie[v].link = go(get_link(trie[v].p), trie[v].pch);     }     return trie[v].link;   }   int go(int v, char ch) {     int c = ch -  a ;     if (trie[v].go[c] == -1) {       if (trie[v].next[c] != -1)         trie[v].go[c] = trie[v].next[c];       else         trie[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);     }     return trie[v].go[c];   }   int tmp_ar[1000000];   void aho_dfs(int node) {     int v = node;     int i, j;     while (1) {       if (trie[v].elink == -1) {         i = 1;         tmp_ar[0] = v;         while (v = get_link(v)) {           if (trie[v].leaf) break;           if (trie[v].elink != -1) {             v = trie[v].elink;             break;           }           tmp_ar[i] = v;           i++;         }         for (j = 0; j < i; j++) trie[tmp_ar[j]].elink = v;       } else {         v = trie[v].elink;       }       if (v == 0) break;     }     for (i = 0; i < AS; i++) {       if (trie[node].next[i] != -1) {         aho_dfs(trie[node].next[i]);       }     }     return;   }   int data[1000000];   int susp[1000000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int n, m, i, id, vid, sus;     cin >> n >> m;     string s;     for (i = 0; i < n; i++) {       cin >> s;       data[i] = addString(s);     }     aho_dfs(0);     trie[0].mx = -1;     for (i = 0; i < m; i++) {       cin >> id;       if (id == 2) {         cin >> s;         int v = 0;         int tv;         int mx = -1;         for (char ch : s) {           v = go(v, ch);           if (trie[v].leaf)             tv = v;           else             tv = trie[v].elink;           do {             mx = max(mx, trie[tv].mx);             tv = trie[tv].elink;           } while (tv);         }         cout << mx <<   n ;       } else {         cin >> vid >> sus;         vid--;         trie[data[vid]].st.erase(trie[data[vid]].st.find(susp[vid]));         susp[vid] = sus;         trie[data[vid]].st.insert(sus);         trie[data[vid]].mx = *(--trie[data[vid]].st.end());       }     }   }