malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 10;   const int INF = 1e9 + 9;   const int B = 1e9 + 7;   int n, p[N];   set<pair<int, int> > s[N];   int d[N];   int main() {     scanf( %d , &n);     ++n;     for (int i = int(2); i <= int(n); ++i) {       scanf( %d , &p[i]);       d[i] = -1;       for (int x = i; x > 1; x = p[x]) {         int old = d[x];         s[p[x]].erase(pair<int, int>(d[x], x));         if (s[x].size() == 0)           d[x] = 0;         else {           d[x] = s[x].rbegin()->first;           if (s[x].size() > 1) {             auto it = s[x].rbegin();             ++it;             d[x] = max(d[x], it->first + 1);           }         }         s[p[x]].insert(pair<int, int>(d[x], x));         while (s[p[x]].size() > 2) s[p[x]].erase(s[p[x]].begin());         if (d[x] == old) break;       }       printf( %d  , s[1].rbegin()->first + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[100000];   int main() {     int m, n, j, k, l, t, ll;     bool is = false;     cin >> t;     cin >> s;     if (t < 5) {       cout <<  no  << endl;       return 0;     }     l = t / 5;     ll = t % 5;     for (j = 0; j < t && !is; j++)       for (k = 1; k < t && !is; k++)         if (j + 4 * k < t && s[j] ==  *  && s[j + 2 * k] ==  *  &&             s[j + k] ==  *  && s[j + 3 * k] ==  *  && s[j + 4 * k] ==  * ) {           is = true;         }     if (is)       cout <<  yes  << endl;     else       cout <<  no  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k, g[2010], a[100003], f[2010], ansn, sum1, sum2;   bool make[200];   int main() {     cin >> n >> m;     bool see = false;     for (int i = m; i > n; i--) {       for (int j = 2; j <= min((long long)100000, n) and !see; j++)         if (i % j == 0) {           see = true;         }       if (!see) return cout << i, 0;       see = false;     }     cout <<  -1 ;   }
#include <bits/stdc++.h>   using namespace std;   using INT = long long;   const int NN = 202020;   int a[NN], b[NN];   map<int, int> mp;   int main() {     int n, y;     cin >> n >> y;     for (int i = 1; i <= n; i++) cin >> a[i];     int m, yy;     cin >> m >> yy;     for (int i = 1; i <= m; i++) cin >> b[i];     int ans = 2;     for (int bt = 0; bt < 30; bt++) {       int d = (1 << bt);       mp.clear();       for (int i = 1; i <= n; i++) {         int ha = a[i] % (2 * d);         mp[ha]++;         ans = max(ans, mp[ha]);       }       for (int i = 1; i <= m; i++) {         int ha = (b[i] + d) % (2 * d);         mp[ha]++;         ans = max(ans, mp[ha]);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1);   const long long MOD = 1e9 + 7;   const long long INF = LLONG_MAX;   const long long SIZE = 100000;   void solve() {     long long n, s;     cin >> n >> s;     long long sum = 0, dig = 0, fir;     long long k = n;     vector<long long> v;     while (k != 0) {       long long rem = k % 10;       sum += rem;       fir = rem;       v.push_back(rem);       k /= 10;       dig++;     }     if (sum <= s) {       cout << 0 << endl;     } else {       reverse(v.begin(), v.end());       long long sum2 = 0, fin;       long long pos = -1;       for (long long i = 0; i < (long long)v.size(); i++) {         sum2 += v[i];         if (sum2 > s) {           pos = i;           break;         }       }       sum2 -= v[pos];       long long yup = -1;       for (long long i = pos - 1; i >= 0; i--) {         v[i] += 1;         sum2 += 1;         if (sum2 <= s) {           yup = i;           break;         }         sum2 -= v[i];       }       if (yup == -1) {         long long fin = pow(10, dig);         cout << fin - n << endl;       } else {         for (long long i = yup + 1; i < (long long)v.size(); i++) {           v[i] = 0;         }         long long fin = 0;         long long len = v.size() - 1;         for (long long i = 0; i < (long long)v.size(); i++) {           fin += v[i] * pow(10, len);           len--;         }         cout << fin - n << endl;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 1e5 + 5;   int n, a[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     sort(a, a + n);     for (int i = 0, eq = 0; i < n - 1; ++i) {       if (a[i] == a[i + 1]) {         if ((++eq) > 1 || (i > 0 && a[i] - 1 == a[i - 1]) || a[i] == 0) {           puts( cslnb );           return 0;         }       }     }     ll sum = 0;     for (int i = 0; i < n; ++i) sum += a[i] - i;     if ((sum & 1) == 0)       puts( cslnb );     else       puts( sjfnb );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int M, N, s, x, l, c;     vector<pair<int, int>> val;     vector<int> seq;     cin >> M;     for (int i = 0; i < M; i++) {       cin >> s;       if (s == 1) {         cin >> x;         val.push_back(make_pair(0, x));         if (seq.size() < 1e6) {           seq.push_back(x);         }       } else {         cin >> l >> c;         val.push_back(make_pair(l, c));         for (int j = 0; j < c; j++) {           if (seq.size() < 1e6) {             seq.insert(seq.end(), seq.begin(), seq.begin() + l);           } else {             break;           }         }       }     }     vector<long long> q;     long long v;     cin >> N;     for (int i = 0; i < N; i++) {       cin >> v;       q.push_back(--v);     }     vector<int> res(N, 0);     int i = 0;     long long cc = 0;     for (int j = 0; j < val.size() && i < N; j++) {       if (val[j].first == 0) {         if (cc++ == q[i]) {           res[i++] = val[j].second;         }       } else {         long long next = cc + ((long long)val[j].second) * val[j].first;         while (i < N && q[i] < next) {           v = (q[i] - cc) % val[j].first;           res[i] = seq[v];           i++;         }         cc += ((long long)val[j].second) * val[j].first;       }     }     cout << res[0];     for (int i = 1; i < N; i++) {       cout <<     << res[i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     vector<vector<int> > v(26);     for (int i = 0; i < n; i++) {       char a = s[i];       char k = a;       k++;       for (char j = k; j <=  z ; j++) {         int x = j -  a ;         if (v[x].size() > 0) {           cout <<  YES  << endl;           cout << v[x].back() + 1 <<     << i + 1 << endl;           return;         }       }       v[a -  a ].push_back(i);     }     cout <<  NO  << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tests = 1;     while (tests--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   long long int arr[200005];   pair<long long int, long long int> even[200005];   pair<long long int, long long int> odd[200005];   int main() {     long long int n;     cin >> n;     for (long long int i = 1; i <= n; i++) cin >> arr[i];     even[2] = make_pair(0, 2);     odd[2] = make_pair(abs(arr[2] - arr[1]), 1);     for (long long int i = 3; i <= n; i++) {       long long int preve = even[i - 1].first;       long long int prevel = even[i - 1].second;       long long int prevo = odd[i - 1].first;       long long int prevol = odd[i - 1].second;       if (i % 2 == 0) {         odd[i] = make_pair(prevo + abs(arr[i] - arr[i - 1]), prevol);         if (preve - abs(arr[i] - arr[i - 1]) <= 0)           even[i] = make_pair(0, i);         else           even[i] = make_pair(preve - abs(arr[i] - arr[i - 1]), prevel);       } else {         even[i] = make_pair(preve + abs(arr[i] - arr[i - 1]), prevel);         if (prevo - abs(arr[i] - arr[i - 1]) <= 0)           odd[i] = make_pair(0, i);         else           odd[i] = make_pair(prevo - abs(arr[i] - arr[i - 1]), prevol);       }     }     long long int m = 0;     for (long long int i = 1; i <= n; i++) {       m = max(m, max(even[i].first, odd[i].first));     }     cout << m << endl;   }
#include <bits/stdc++.h>   using namespace std;   std::mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   inline int sj(int n) {     unsigned long long x = rnd();     x = x << 32 | rnd();     return x % n + 1;   }   const int p = 998244353;   inline void inc(int &x, const int y) {     if ((x += y) >= p) x -= p;   }   inline void dec(int &x, const int y) {     if ((x -= y) < 0) x += p;   }   inline int ksm(int x, int y) {     int r = 1;     while (y) {       if (y & 1) r = (long long)r * x % p;       x = (long long)x * x % p;       y >>= 1;     }     return r;   }   priority_queue<int> ONLYYFORRCOPYY;   priority_queue<int, vector<int>, greater<int>> ONLYYFORRCOPYY__;   const int N = 1e6 + 2, M = 4e6 + 2;   struct Q {     int a, s;     bool operator<(const Q &o) const {       return max(a, s) < max(o.a, o.s) ||              max(a, s) == max(o.a, o.s) && (s < o.s || s == o.s && a < o.a);     }   };   Q a[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout << setiosflags(ios::fixed) << setprecision(15);     int n, d, i, ans = 0;     cin >> n >> d;     for (i = 1; i <= n; i++) cin >> a[i].s >> a[i].a;     sort(a + 1, a + n + 1);     for (i = 1; i <= n; i++)       if (d <= a[i].s) d = max(d, a[i].a), ++ans;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> g[100005];   vector<pair<pair<int, int>, int> > coord;   int visited[100005];   long long ans = 1;   const long long pmod = 1000000007;   long long expsize;   set<int> x, y;   bool cycle;   int mapback[100005];   long long qpmod(long long b, long long e) {     long long cur = b;     long long res = 1;     while (e) {       if (e % 2 == 1) {         res = res * cur % pmod;       }       e /= 2;       cur = cur * cur % pmod;     }     return res;   }   pair<pair<int, int>, int> m3(int a, int b, int c) {     pair<pair<int, int>, int> res;     res.first.first = a;     res.first.second = b;     res.second = c;     return res;   }   bool cmpx(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) {     if (x.first.first < y.first.first) return true;     if ((x.first.first == y.first.first) && (x.first.second < y.first.second))       return true;     return false;   }   bool cmpy(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) {     if (x.first.second < y.first.second) return true;     if ((x.first.second == y.first.second) && (x.first.first < y.first.first))       return true;     return false;   }   void dfs(int last, int cur) {     expsize++;     visited[cur] = 1;     x.insert(coord[mapback[cur]].first.first);     y.insert(coord[mapback[cur]].first.second);     int i;     for (i = 0; i < g[cur].size(); i++) {       if (g[cur][i] == last) continue;       if (visited[g[cur][i]]) {         cycle = true;         continue;       }       dfs(cur, g[cur][i]);     }   }   int main() {     scanf( %d , &n);     int i, j, k;     for (i = 0; i < n; i++) {       scanf( %d %d , &j, &k);       coord.push_back(m3(j, k, i));     }     sort(coord.begin(), coord.end(), cmpx);     for (i = 1; i < n; i++) {       if (coord[i].first.first == coord[i - 1].first.first) {         g[coord[i].second].push_back(coord[i - 1].second);         g[coord[i - 1].second].push_back(coord[i].second);       }     }     sort(coord.begin(), coord.end(), cmpy);     for (i = 1; i < n; i++) {       if (coord[i].first.second == coord[i - 1].first.second) {         g[coord[i].second].push_back(coord[i - 1].second);         g[coord[i - 1].second].push_back(coord[i].second);       }     }     for (i = 0; i < n; i++) {       mapback[coord[i].second] = i;     }     for (i = 0; i < n; i++) {       if (visited[i] == 0) {         x.clear();         y.clear();         cycle = false;         dfs(i, i);         expsize = x.size() + y.size();         if (cycle) {           ans = ans * qpmod(2, expsize) % pmod;         } else {           ans = ans * ((qpmod(2, expsize) + pmod - 1) % pmod) % pmod;         }       }     }     printf( %d n , (int)ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int incoming[110];   int outgoing[110];   int main(int argc, const char* argv[]) {     int n, m;     cin >> n >> m;     int a, b, c;     for (int i = 0; i < m; i++) {       cin >> a >> b >> c;       incoming[b] += c;       outgoing[a] += c;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (outgoing[i] - incoming[i] > 0) ans += outgoing[i] - incoming[i];     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, n, m, z, c;     string s;     cin >> s;     c = 0, z = 0;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  4 )         c++;       else if (s[i] ==  7 )         z++;     }     if (c == z && z == 0)       cout << -1 << endl;     else if (c >= z)       cout << 4 << endl;     else       cout << 7 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, INF = 1e9;   vector<int> g[N], r[N], out;   int cnt[N], ans = INF, sum = 0;   int dfs(int v, int par) {     for (int i = 0; i < g[v].size(); i++)       if (g[v][i] != par) cnt[v] += dfs(g[v][i], v);     for (int i = 0; i < r[v].size(); i++)       if (r[v][i] != par) cnt[v] += 1 + dfs(r[v][i], v);     return cnt[v];   }   void dfs2(int v, int par, int a, int b) {     for (int i = 0; i < g[v].size(); i++)       if (g[v][i] != par) dfs2(g[v][i], v, a + 1, b);     for (int i = 0; i < r[v].size(); i++)       if (r[v][i] != par) dfs2(r[v][i], v, a, b + 1);     int cur = sum - b + a;     if (cur < ans) {       ans = cur;       out.clear();       out.push_back(v + 1);     } else if (cur == ans)       out.push_back(v + 1);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       g[a].push_back(b);       r[b].push_back(a);     }     dfs(0, -1);     sum = cnt[0];     dfs2(0, -1, 0, 0);     cout << ans <<   n ;     sort(out.begin(), out.end());     for (int i = 0; i < out.size(); i++)       cout << out[i] <<    n [i == out.size() - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> E[1010000];   int n, m, T[1010000];   bool v[1010000];   void DFS(int a) {     v[a] = true;     int i;     for (i = 0; i < E[a].size(); i++) {       if (!v[E[a][i]]) DFS(E[a][i]);     }   }   long long Res;   int main() {     int i, a, b, ck = 0, cc = 0;     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       if (a == b) {         cc++;         T[a]++;       }       E[a].push_back(b);       E[b].push_back(a);     }     Res = 1ll * cc * (m - cc) + 1ll * cc * (cc - 1) / 2;     for (i = 1; i <= n; i++) {       if (!E[i].empty()) {         if (!v[i] && ck) {           printf( 0 n );           return 0;         }         ck = 1;         DFS(i);       }     }     for (i = 1; i <= n; i++) {       int t = E[i].size() - T[i] * 2;       Res += 1ll * t * (t - 1) / 2;     }     printf( %lld n , Res);   }
#include<bits/stdc++.h>   using namespace std;   #define ll long long   const int maxn = 3e3+5;   const int mod = 0x3f3f3f3f;   int n,d,q;      void solve(int n){    if(n>=10*d){     cout<< YES <<endl;     return;    }    for(int i=1;i<=9;i++){     if(n>=d*i&&(n-i*d)%10==0){      cout<< YES <<endl;      return;     }    }    cout<< NO <<endl;   }      int main(){    int t;    cin>>t;    while(t--){          cin>>q>>d;     for(int i=0;i<q;i++){      cin>>n;      solve(n);     }    }         return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 110, mod = 1e9 + 7;   const long long inf = 1e18;   long long a[maxn];   int b[maxn];   long long ans1, ans2, ans3;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int tot = 2; tot <= 2 * m; tot++) {       int pos = max(1, tot - m), pos2 = 0, pos3 = 0, mxp = -1,           lim = (tot + 1) / 2, cnt = 0;       for (int j = 0; j < n; j++) {         b[j] = a[j] % tot;       }       for (int j = 0; j < n; j++) {         cnt += (b[j] >= lim);         if (b[j] >= lim)           pos = max(pos, tot - b[j]);         else           pos = max(pos, b[j] + 1);         if (mxp == -1 || b[mxp] < b[j]) mxp = j;       }       for (int j = 0; j < n; j++) {         if (j != mxp) pos2 = max(pos2, (b[j] / 2) + 1);         pos3 = max(pos3, (b[j] / 2) + 1);       }       if (cnt & 1)         ans2 += max(0, tot - 2 * max(pos, pos2) + 1);       else         ans3 += max(0, tot - 2 * max(pos, pos3) + 1);     }     ans1 = (1ll * m * m - ans2 - ans3) >> 1;     return cout << ans1 <<     << ans1 <<     << ans2 <<     << ans3 << endl, 0;   }
#include <bits/stdc++.h>   using namespace std;   using lint = long long;   const int N = 200005;   const int MAX = 250;   int cnt[N * (MAX + 5)];   int pref[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     string s;     cin >> s;     int n = s.size();     lint ans = 0;     for (int i = 0; i < n; i++) {       pref[i + 1] = s[i] -  0 ;       pref[i + 1] += pref[i];     }     for (int k = 1; k <= MAX; k++) {       for (int i = 0; i <= n; i++) {         ans += cnt[k * pref[i] - i + n]++;       }       for (int i = 0; i <= n; i++) {         cnt[k * pref[i] - i + n]--;       }     }     vector<int> ones;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) {         ones.emplace_back(i + 1);       }     }     ones.emplace_back(n + 1);     int i = 0;     int num = (int)ones.size() - 1;     for (int l = 1; l <= n; l++) {       while (i < num && ones[i] < l) {         i++;       }       for (int j = i; j < num; j++) {         if ((j - i + 1) * MAX > n) {           break;         }         int high = (ones[j + 1] - l) / (j - i + 1);         int low = max(MAX, (ones[j] - l) / (j - i + 1));         ans += max(high - low, 0);       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100007];   int main() {     int n, kq;     cin >> n;     if (n == 1) {       cout << 1;       return 0;     }     kq = 2;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n - 2; ++i) {       int j = 0;       for (j = i + 2; j <= n; ++j)         if (a[j] != a[j - 1] + a[j - 2]) break;       kq = max(kq, j - i);       i = j - 2;     }     cout << kq;     return 0;   }
#include <bits/stdc++.h>   const long long maxn = 1e3 + 5;   const long long w = 1e8;   using namespace std;   int m, n, p, kq;   char a[maxn][maxn];   string s;   char dir[4] = { D ,  L ,  U ,  R };   int tdx, tdy;   int x, y;   inline void init() {     cin >> n >> m;     cin.ignore();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         if (a[i][j] ==  S ) {           x = j;           y = i;         }       }     cin >> s;     p = s.length();   }   inline void solve() {     sort(dir, dir + 4);     do {       tdx = x;       tdy = y;       for (int i = 0; i < p; i++) {         if (dir[s[i] - 48] ==  D ) tdy++;         if (dir[s[i] - 48] ==  U ) tdy--;         if (dir[s[i] - 48] ==  L ) tdx--;         if (dir[s[i] - 48] ==  R ) tdx++;         if (a[tdy][tdx] ==  #  || tdx < 1 || tdy < 1 || tdx > m || tdy > n) break;         if (a[tdy][tdx] ==  E ) {           kq++;           break;         }       }     } while (next_permutation(dir, dir + 4));     cout << kq;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a;     int N[2005], A[2005];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       N[i] = a;     }     for (int i = 0; i < n; i++) {       int cont = 0;       for (int j = 0; j < n; j++) {         if (i != j && N[i] < N[j]) cont++;       }       A[i] = 1 + cont;     }     for (int i = 0; i < n; i++) {       if (i != n - 1)         cout << A[i] <<    ;       else         cout << A[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2000 + 1, inf = 2e8 + 1;   int a, m, n;   bool d[N];   int p[N];   int dp[N];   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     cin >> a >> n >> m;     for (int i = 0; i < n; ++i) {       int l, r;       cin >> l >> r;       for (int i = l; i < r; ++i) d[i] = true;     }     for (int i = 0; i <= a; ++i) p[i] = inf;     for (int i = 0; i < m; ++i) {       int x, px;       cin >> x >> px;       p[x] = min(p[x], px);     }     for (int i = a - 1; i >= 0; --i) {       dp[i] = inf;       if (!d[i]) dp[i] = dp[i + 1];       if (p[i] != inf)         for (int j = i + 1; j <= a; ++j)           if (dp[j] != inf) dp[i] = min(dp[i], p[i] * (j - i) + dp[j]);     }     cout << (dp[0] == inf ? -1 : dp[0]) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   using ppi = pair<pii, int>;   char s[200100];   int rk[200100], sa[200100], ht[200100];   int mn[200100][22];   namespace SA {   int head[200100 * 2];   ppi pos[200100 * 2], buf[200100 << 1], tbuf[200100 << 1];   int nxt[200100 * 2];   void bucket_sort(int ok, int n) {     int i, u, j, deg, E, K;     for (i = E = K = 0; i < max(222, n + 10); i++) head[i] = -1;     for (i = 0; i < n; i++) {       if (ok)         u = pos[i].first.first + 1;       else         u = pos[i].first.second + 1;       buf[E] = pos[i];       nxt[E] = head[u];       head[u] = E++;     }     for (int i = 0; i < max(n + 10, 222); i++) {       for (deg = 0, j = head[i]; ~j; j = nxt[j]) {         tbuf[deg++] = buf[j];       }       while (deg) pos[K++] = tbuf[--deg];     }   }   void LCP(int n) {     for (int i = 1; i <= n; i++) mn[i][0] = ht[i];     for (int j = 1; j < 22; j++) {       for (int i = 1; i <= n; i++) {         mn[i][j] = min(mn[i][j - 1], mn[min(n, i + (1 << j - 1))][j - 1]);       }     }   }   void height(int n) {     int h = 0, i;     for (i = 0; i < n; i++) sa[rk[i]] = i;     for (i = 0; i < n; i++) {       if (rk[i] == 1) continue;       h = max(0, h - 1);       for (int j = sa[rk[i] - 1]; s[i + h] == s[j + h]; h++)         ;       ht[rk[i]] = h;     }   }   void buildSA(int n) {     int i, j, cnt, u;     for (i = 0; i < n; i++) rk[i] = s[i];     rk[n] = 0;     for (i = 0; i < 20; i++) {       for (j = 0; j < n; j++)         pos[j] = ppi(pii(rk[j], rk[min(n, j + (1 << i))]), j);       bucket_sort(0, n);       bucket_sort(1, n);       pos[n] = ppi(pii(-1, -1), -1);       for (cnt = j = 0; j < n; j++) {         rk[pos[j].second] = cnt + 1;         cnt += (pos[j].first != pos[j + 1].first);       }       if (cnt == n) break;     }     height(n);     LCP(n);   }   int calc(int u, int v) {     if (u == v) return 100000000;     u = rk[u], v = rk[v];     if (u > v) swap(u, v);     u++;     int l = 31 - __builtin_clz(v - u + 1);     return min(mn[u][l], mn[v - (1 << l) + 1][l]);   }   }  // namespace SA   using namespace SA;   using INT = long long;   char vst[200100];   int cnt[200100];   int main() {     int n;     cin >> n;     cin >> s;     cin >> vst;     reverse(s, s + n);     buildSA(n);     INT ans = 0;     for (int i = 1; i <= n; i++) {       int u = sa[i];       cnt[i] = cnt[i - 1];       u = n - sa[i] - 1;       if (vst[u] ==  0 ) {         ans = max(ans, (INT)n - sa[i]);         cnt[i]++;       }     }     for (int i = 2; i <= n; i++) {       int st = 0, ed = i;       while (st + 1 < ed) {         int md = (st + ed) >> 1;         if (calc(sa[md], sa[i]) >= ht[i])           ed = md;         else           st = md;       }       int l = ed;       st = i, ed = n + 1;       while (st + 1 < ed) {         int md = (st + ed) >> 1;         if (calc(sa[md], sa[i]) >= ht[i])           st = md;         else           ed = md;       }       int r = st;       ans = max(ans, (INT)ht[i] * (cnt[r] - cnt[l - 1]));     }     cout << ans << endl;     return 0;   }