malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, h, k, i, j, s2, H[2][3000], H2[2][3000], s, a, x, y, z, l[2], top;   vector<pair<int, int> > v[2];   int main() {     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> x >> y >> z;       v[x].push_back(make_pair(z, y));     }     h = m;     sort(v[0].begin(), v[0].end());     sort(v[1].begin(), v[1].end());     l[0] = v[0].size();     l[1] = v[1].size();     while (1) {       a = 0;       for (i = l[k] - 1; i >= 0; i--)         if (v[k][i].second <= m && !H[k][i]) {           s++;           H[k][i] = 1;           m += v[k][i].first;           a = 1;           break;         }       if (!a) break;       k = !k;     }     m = h;     k = 1;     while (1) {       a = 0;       for (i = l[k] - 1; i >= 0; i--)         if (v[k][i].second <= m && !H2[k][i]) {           s2++;           H2[k][i] = 1;           m += v[k][i].first;           a = 1;           break;         }       if (!a) break;       k = !k;     }     cout << max(s, s2);   }
#include <bits/stdc++.h>   using namespace std;   bool adj[200][200];   int bfs(int source, int dest) {     bool vis[200];     for (int i = 0; i < 200; i++) vis[i] = 0;     queue<pair<int, int> > qe;     qe.push({source, 0});     while (!qe.empty()) {       int node = qe.front().first;       int d = qe.front().second;       qe.pop();       if (node == dest) return d;       vis[node] = 1;       for (int i = 0; i < 200; i++) {         if (adj[node][i] and !vis[i]) qe.push({i, d + 1});       }     }     return INT_MAX;   }   int main() {     int n;     cin >> n;     vector<long long> arr;     while (n--) {       long long x;       cin >> x;       if (x != 0) arr.push_back(x);     }     n = arr.size();     if (n > 128) {       cout << 3 << endl;       return 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (arr[i] & arr[j]) adj[i][j] = 1;       }     }     int min_cycle = INT_MAX;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (adj[i][j]) {           adj[i][j] = 0;           adj[j][i] = 0;           int m = bfs(i, j);           min_cycle = min(m, min_cycle);           adj[i][j] = 1;           adj[j][i] = 1;         }       }     }     if (min_cycle > 10000000)       cout << -1 << endl;     else       cout << min_cycle + 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int is[1010];   int main() {     int n;     scanf( %d , &n);     int x = 0;     for (int i = (0); i < (n); ++i)       for (int j = (0); j < (n); ++j) {         int v;         scanf( %d , &v);         if ((i == j) && (v == 1)) x ^= 1;       }     int q;     scanf( %d , &q);     for (int i = (0); i < (q); ++i) {       int t;       scanf( %d , &t);       if (t < 3) {         x ^= 1;         int v;         scanf( %d , &v);       } else         printf( %d , x);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 840;   long long arr[9], W, ans;   long long dp[7890];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> W;     for (int i = 1; i < 9; ++i) {       cin >> arr[i];     }     if (W > 840) {       for (int i = 1; i < 9; ++i) {         long long lef = max(arr[i] - 840 / i, (long long)0);         long long g = (W - 840 - ans) / i;         g = min(g, lef);         if (g < 0) continue;         ans += g * i;         arr[i] -= g;       }     }     dp[0] = 1;     for (int i = 1; i < 9; ++i) {       for (int j = 0; j < min(arr[i], (long long)840 / i); ++j) {         for (int k = 6789; k >= i; --k) {           if (dp[k - i]) dp[k] = 1;         }       }     }     for (int k = 6789;; --k) {       if (dp[k] && ans + k <= W) {         cout << ans + k <<   n ;         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a[n * n];     for (int i = 1; i <= n * n; ++i) a[i - 1] = i;     if (k == 1) {       long long sum = 0;       for (int i = 0; i < n; ++i) {         sum += n * i + 1;       }       cout << sum << endl;       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n - 1; ++j) {           printf( %d  , a[i * n + j]);         }         printf( %d n , a[i * n + n - 1]);       }       return 0;     }     vector<int> v[n];     k--;     for (int i = 0; i < k * n; ++i) {       v[i % k].push_back(i + 1);     }     for (int i = k * n; i < n * n; ++i) {       v[(i - k * n) % (n - k) + k].push_back(i + 1);     }     long long sum = 0;     for (int i = 0; i < n; ++i) {       sum += v[k][i];     }     cout << sum << endl;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n - 1; ++j) {         printf( %d  , v[j][i]);       }       printf( %d n , v[n - 1][i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f[5010][5010], ans[5010][5010];   int n, q;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &f[i][i]);       ans[i][i] = f[i][i];     }     for (int i = 1; i < n; i++)       for (int j = 1; j <= n - i + 1; j++)         f[j][j + i] = f[j][j + i - 1] ^ f[j + 1][j + i],                  ans[j][j + i] =                      max(f[j][j + i], max(ans[j][j + i - 1], ans[j + 1][j + i]));     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       printf( %d n , ans[l][r]);     }   }
#include <bits/stdc++.h>   using namespace std;   int a[1003][1003];   int cost[43][1003][1003];   vector<vector<pair<int, int>>> COL(43);   int n, m, k;   int di1[4] = {0, 1, 0, -1};   int di2[4] = {1, 0, -1, 0};   void bfs(int col) {     vector<bool> vis(43, 0);     queue<pair<int, int>> q;     for (int i = 0; i < COL[col].size(); i++) {       cost[col][COL[col][i].first][COL[col][i].second] = 0;       q.push({COL[col][i].first, COL[col][i].second});     }     while (!q.empty()) {       int x = q.front().first;       int y = q.front().second;       q.pop();       if (!vis[a[x][y]]) {         vis[a[x][y]] = 1;         for (int i = 0; i < COL[a[x][y]].size(); i++) {           int nx = COL[a[x][y]][i].first;           int ny = COL[a[x][y]][i].second;           if (cost[col][nx][ny] == -1) {             cost[col][nx][ny] = 1 + cost[col][x][y];             q.push({nx, ny});           }         }       }       for (int i = 0; i < 4; i++) {         int nx = x + di1[i];         int ny = y + di2[i];         if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && cost[col][nx][ny] == -1) {           cost[col][nx][ny] = 1 + cost[col][x][y];           q.push({nx, ny});         }       }     }   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         COL[a[i][j]].push_back({i, j});       }     }     memset(cost, -1, sizeof(cost));     for (int i = 1; i <= k; i++) {       bfs(i);     }     int q;     cin >> q;     while (q--) {       int sx, sy, ex, ey;       cin >> sx >> sy >> ex >> ey;       int ans = abs(ex - sx) + abs(ey - sy);       for (int i = 1; i <= k; i++) {         ans = min(ans, 1 + cost[i][sx][sy] + cost[i][ex][ey]);       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   int sz0[400000];   vector<int> g[400000];   vector<int> c0[400000];   int centroid;   int sz[400000];   vector<int> cs[400000];   int ans[400000];   void dfs0(int x) {     sz0[x] = 1;     for (int y : g[x]) {       if (sz0[y] == 0) {         c0[x].push_back(y);         dfs0(y);         sz0[x] += sz0[y];       }     }   }   int findc(int x) {     for (int y : c0[x]) {       if (sz0[y] > n / 2) {         return findc(y);       }     }     return x;   }   void dfs1(int x) {     sz[x] = 1;     for (int y : g[x]) {       if (sz[y] == 0) {         cs[x].push_back(y);         dfs1(y);         sz[x] += sz[y];       }     }   }   bool cmp(int a, int b) { return sz[a] > sz[b]; }   void dfs2(int x, int s, int m) {     if (s - m <= n / 2) ans[x] = 1;     for (int y : cs[x]) {       int ss = s + sz[x] - sz[y];       dfs2(y, ss, m);     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       g[a].push_back(b);       g[b].push_back(a);     }     dfs0(0);     centroid = findc(0);     dfs1(centroid);     ans[centroid] = 1;     if (cs[centroid].size() == 1) {       assert(n <= 2);       ans[0] = ans[1] = 1;     } else {       vector<int>& c = cs[centroid];       sort(c.begin(), c.end(), cmp);       dfs2(c[0], sz[centroid] - sz[c[0]], sz[c[1]]);       for (int i = 1; i < c.size(); i++)         dfs2(c[i], sz[centroid] - sz[c[i]], sz[c[0]]);       if (sz[c[0]] * 2 == n)         for (int i = 0; i < n; i++) ans[i] = 1;     }     for (int i = 0; i < n; i++) printf( %d  , ans[i]);     putchar(  n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a = min(k, 26) + 97;     vector<char> b;     for (int i = 97; i < a; i++) {       b.push_back((char)i);     }     string key =   ;     for (int i = 0; i < b.size(); i++) key += b[i];     int c = n - k, j = 0;     while (true) {       key += b[j];       j++;       if (j > b.size() - 1) j = 0;       c--;       if (c <= 0) break;     }     if (key.size() > n) {       key.erase(key.size() - 1, 1);     }     cout << key;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string itoa(int x) {     string s =   ;     char c;     if (x < 0) x *= -1, s +=  - ;     while (x) {       c = x % 10 + 48;       s += c;       x /= 10;     }     if (s[0] ==  - )       reverse(s.begin() + 1, s.end());     else       reverse(s.begin(), s.end());     if (s ==   ) s +=  0 ;     return s;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     priority_queue<int, vector<int>, greater<int> > pq;     int n;     cin >> n;     string s, t, c;     int x;     vector<string> ans;     while (n--) {       cin >> s;       if (s !=  removeMin ) {         cin >> x;         if (s ==  insert ) {           pq.push(x);           t =  insert  , c = itoa(x), t += c;           ans.push_back(t);         } else {           while (!pq.empty() && pq.top() < x) {             t =  removeMin ;             ans.push_back(t);             pq.pop();           }           if (pq.empty() || pq.top() > x)             t =  insert  , c = itoa(x), t += c, ans.push_back(t), pq.push(x);           t =  getMin  , c = itoa(x), t += c;           ans.push_back(t);         }       } else {         if (pq.empty()) t =  insert 0 , ans.push_back(t), pq.push(0);         t =  removeMin , ans.push_back(t), pq.pop();       }     }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int getValue(vector<int> &ai, int n, int sum) {     int val = 0;     int mval = ai[ai.size() - 1];     for (int i = 1; i <= mval; i++) {       if (n * i >= sum) {         val = i;         break;       }     }     return val;   }   int main() {     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int n;       vector<int> ai;       scanf( %d , &n);       int sum = 0;       for (int j = 0; j < n; j++) {         int temp;         scanf( %d , &temp);         ai.push_back(temp);         sum += temp;       }       sort(ai.begin(), ai.end());       int ret = getValue(ai, n, sum);       printf( %d n , ret);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000 * 100 + 3;   int n, a[N];   void input() {     cin >> n;     for (int i = 0; i + 1 < n; i++) cin >> a[i];   }   void solve() {     sort(a, a + n - 1);     for (int i = 0; i + 1 < n; i++)       if (a[i] != i + 1) cout << i + 1 << endl, exit(0);     cout << n << endl;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     input(), solve();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   inline long long input() {     long long n;     cin >> n;     return n;   }   string base2(long long n) {     string a =   ;     while (n >= 2) {       a += (char)(n % 2 +  0 );       n /= 2;     }     a += (char)(n +  0 );     reverse((a).begin(), (a).end());     return a;   }   const int MAXN = 1e6 + 10;   const int MOD = 1e9 + 7;   const int MOD2 = 998244353;   const long long INF = 8e18;   long long pw(long long a, long long b, long long mod) {     return (!b ? 1                : (b & 1 ? (a * pw(a * a % mod, b / 2, mod)) % mod                         : pw(a * a % mod, b / 2, mod)));   }   int n, m, mark[MAXN], king[MAXN], par[MAXN], sz[MAXN];   vector<pair<int, int> > G[MAXN];   vector<int> M;   long long dis[MAXN];   pair<long long, pair<long long, long long> > E[MAXN];   vector<pair<long long, pair<long long, long long> > > E2;   int GET(int x) { return ((x == par[x]) ? x : par[x] = GET(par[x])); }   bool unify(int x, int y) {     int v = GET(x), u = GET(y);     if (v == u) return 0;     if (sz[u] > sz[v]) {       swap(u, v);     }     par[u] = v;     sz[v] += sz[u];     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (int i = 1; i <= n; i++) dis[i] = 1e18, sz[i] = 1, par[i] = i;     for (int i = 1; i <= m; i++) {       int a, b, c;       cin >> a >> b >> c;       G[a].push_back(make_pair(b, c));       G[b].push_back(make_pair(a, c));       E[i] = make_pair(c, make_pair(a, b));     }     set<pair<long long, long long> > st;     int k;     cin >> k;     for (int i = 1; i <= k; i++) {       int a;       cin >> a;       M.push_back(a);       king[a] = a;       st.insert(make_pair(0, a));       dis[a] = 0;     }     while (!st.empty()) {       pair<long long, long long> cu = *st.begin();       st.erase(st.begin());       int v = cu.second;       if (mark[v]) {         continue;       }       mark[v] = 1;       for (auto y : G[v]) {         long long u = y.first, cost = y.second;         if (dis[u] > dis[v] + cost) {           king[u] = king[v];           dis[u] = dis[v] + cost;           st.insert(make_pair(dis[u], u));         }       }     }     for (int i = 1; i <= m; i++) {       long long v = E[i].second.first, u = E[i].second.second, cost = E[i].first;       if (king[u] != king[v]) {         E2.push_back(             make_pair(dis[v] + dis[u] + cost, make_pair(king[u], king[v])));       }     }     sort((E2).begin(), (E2).end());     long long MST = 0;     for (auto x : E2) {       long long u = x.second.first, v = x.second.second, cost = x.first;       if (unify(v, u)) {         MST += cost;       }     }     set<long long> second;     for (auto x : M) {       second.insert(GET(x));     }     if ((int)second.size() > 1) {       return cout << 1e18, 0;     }     cout << MST + dis[1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, p[50];   int ask(int second) {     cout << second <<   n ;     fflush(stdout);     cin >> second;     return second;   }   int main() {     cin >> m >> n;     for (int i = 0; i < n; i++) {       p[i] = ask(1);       if (p[i] == 0) {         cout << 1 <<   n ;         exit(0);       }     }     int l = 1, r = m, t = 0;     while (l <= r) {       int m = (l + r) / 2;       int tmp = ask(m) * p[t];       if (tmp == 0) {         cout << tmp <<   n ;         exit(0);       }       if (tmp == -1)         r = m - 1;       else         l = m + 1;       t = (t + 1) % n;     }   }
#include <bits/stdc++.h>   using namespace std;   string s;   long long int dp[510][501];   long long int solve(long long int l, long long int r) {     if (dp[l][r] != -1) {       return dp[l][r];     }     if (l > r) return 0;     long long int a = 1 + solve(l + 1, r);     for (long long int i = l + 1; i <= r; i++) {       if (s[i] != s[l]) continue;       a = min(a, solve(l + 1, i - 1) + solve(i, r));     }     dp[l][r] = a;     return a;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, i;     cin >> n;     cin >> s;     memset(dp, -1, sizeof dp);     cout << solve(0, s.size() - 1);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     t = 1;     while (t--) {       long long n, a[1001];       cin >> n;       for (int i = 0; i <= n - 1; i++) {         cin >> a[i];       }       sort(a, a + n);       if (a[0] == 1)         cout << -1;       else         cout << 1;     }     cerr <<  Time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 3.141592653589793;   const int INF = 2000000000;   const int mod = 1000000007;   const int N = 100000000;   const int base = 10;   vector<int> read(string s) {     vector<int> a;     for (int i = (int)s.length(); i > 0; i -= 1)       if (i < 1)         a.push_back(atoi(s.substr(0, i).c_str()));       else         a.push_back(atoi(s.substr(i - 1, 1).c_str()));     return a;   }   vector<int> add(vector<int> a, vector<int> b) {     int carry = 0;     for (size_t i = 0; i < max(a.size(), b.size()) || carry; ++i) {       if (i == a.size()) a.push_back(0);       a[i] += carry + (i < b.size() ? b[i] : 0);       carry = a[i] >= base;       if (carry) a[i] -= base;     }     return a;   }   vector<int> mul(vector<int> a, int b) {     int carry = 0;     for (size_t i = 0; i < a.size() || carry; ++i) {       if (i == a.size()) a.push_back(0);       long long cur = carry + a[i] * 1ll * b;       a[i] = int(cur % base);       carry = int(cur / base);     }     while (a.size() > 1 && a.back() == 0) a.pop_back();     return a;   }   vector<int> c;   vector<int> a[100005], b[100005];   vector<bool> f;   vector<bool> f1;   int main() {     vector<int> queue;     int n, x, y, m;     cin >> n >> m;     for (int(i) = (0); (i) < (n); (i)++) {       cin >> x;       c.push_back(x);     }     for (int(i) = (0); (i) < (m); (i)++) {       cin >> x >> y;       x--;       y--;       a[x].push_back(y);       b[y].push_back(x);     }     for (int(i) = (0); (i) < (c.size()); (i)++)       if (c[i] == 1) {         queue.push_back(i);         f.push_back(true);       } else {         f.push_back(false);       }     for (int(i) = (0); (i) < (queue.size()); (i)++) {       for (int(j) = (0); (j) < (a[queue[i]].size()); (j)++) {         if (f[a[queue[i]][j]]) continue;         queue.push_back(a[queue[i]][j]);         f[a[queue[i]][j]] = true;       }     }     queue.clear();     for (int(i) = (0); (i) < (c.size()); (i)++)       if (c[i] == 2) {         queue.push_back(i);         f1.push_back(true);       } else {         f1.push_back(false);       }     for (int(i) = (0); (i) < (queue.size()); (i)++) {       for (int(j) = (0); (j) < (b[queue[i]].size()); (j)++) {         if (f1[b[queue[i]][j]]) continue;         f1[b[queue[i]][j]] = true;         if (c[b[queue[i]][j]] == 1) continue;         queue.push_back(b[queue[i]][j]);       }     }     for (int(i) = (0); (i) < (n); (i)++)       if (f[i] && f1[i]) {         cout << 1 << endl;       } else {         cout << 0 << endl;       }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int MOD = 1000000007;   const int UNDEF = -1;   const int INF = 1 << 30;   template <typename T>   inline bool chkmax(T &aa, T bb) {     return aa < bb ? aa = bb, true : false;   }   template <typename T>   inline bool chkmin(T &aa, T bb) {     return aa > bb ? aa = bb, true : false;   }   int rint() {     int x;     scanf( %d , &x);     return x;   }   long long rlong() {     long long x;     scanf( %lld , &x);     return x;   }   const int mn = (5e5) + 4;   long long c[mn];   map<long long, vector<pair<int, int> > > sig2e;   map<int, vector<int> > h;   set<int> seen;   int cnt = 0;   void dfs(int x) {     seen.insert(x);     for (auto &y : h[x]) {       if (seen.find(y) == seen.end()) {         --cnt;         dfs(y);       }     }   }   int ptwo[mn];   int main() {     int n = rint(), m = rint(), k = rint();     ptwo[0] = 1;     for (int i = 1; i < mn; i++) {       ptwo[i] = ptwo[i - 1] * 2;       if (ptwo[i] >= MOD) ptwo[i] -= MOD;     }     for (int x = 1; x <= n; x++) c[x] = rlong();     for (int i = 0; i < m; i++) {       int x = rint(), y = rint();       long long sig = c[x] ^ c[y];       sig2e[sig].push_back(make_pair(x, y));     }     int rem = (ptwo[k] - (int)sig2e.size() + MOD) % MOD;     int ans = (rem * (long long)ptwo[n]) % MOD;     for (auto &sigve : sig2e) {       auto &ve = sigve.second;       h.clear();       seen.clear();       for (auto &e : ve) {         int x = e.first, y = e.second;         h[x].push_back(y);         h[y].push_back(x);       }       cnt = n;       for (auto &e : ve) {         int x = e.first, y = e.second;         if (seen.find(x) == seen.end()) dfs(x);         if (seen.find(y) == seen.end()) dfs(y);       }       ans += ptwo[cnt];       if (ans >= MOD) ans -= MOD;     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   const long long mod = 1000000007;   const long long Inf = 1e9;   using namespace std;   long long a, b, d, k, t;   double f(long long x) {     double res = 0;     res = (double)x * (double)a +           (double)(max(x / k - (x % k == 0 ? 1 : 0), (long long)0)) * (double)t +           (double)(d - x) * (double)b;     return res;   }   int main() {     scanf( %I64d%I64d%I64d%I64d%I64d , &d, &k, &a, &b, &t);     long long l = 1, r = d;     double ans = 1e18;     while (r - l > 2000000) {       long long x1 = l + (r - l) / 3;       long long x2 = r - (r - l) / 3;       if (f(x1) > f(x2))         l = x1;       else if (f(x1) < f(x2))         r = x2;       else {         l = x1;         r = x2;       }     }     for (long long i = l; i <= r; ++i) {       ans = min(ans, f(i));     }     printf( %0.lf , ans);     return 0;   }
#include <bits/stdc++.h>   static int solve();   using ll = long long;   int main(int argc, char* argv[]) {     int tc = 1;     scanf( %d , &tc);     while (tc--) solve();     return 0;   }   static constexpr int MOD = 998244353;   static int solve() {     int n, x, y;     scanf( %d %d %d , &n, &x, &y);     int sum = x + y;     int min_pos, max_pos;     if (sum == n + n) {       min_pos = n;       max_pos = n;     } else if (sum <= n) {       min_pos = 1;       max_pos = sum - 1;     } else {       min_pos = sum - n + 1;       max_pos = n;     }     printf( %d %d n , min_pos, max_pos);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int power(int x, int y, int mod) {     int ret = 1;     for (; y; y >>= 1) {       if (y & 1) ret = 1LL * ret * x % mod;       x = 1LL * x * x % mod;     }     return ret;   }   int n, m;   char s[N], t[N];   vector<int> primes = {       3,   5,   7,   11,  13,  17,  19,  23,  29,  31,  37,  41,  43,  47,  53,       59,  61,  67,  71,  73,  79,  83,  89,  97,  101, 103, 107, 109, 113, 127,       131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,       211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271};   int P[60][300];   bool isPrime(int n) {     for (int i = 2; i * i <= n; ++i)       if (n % i == 0) return false;     return true;   }   int main() {     scanf( %d %d , &n, &m);     scanf( %s , s);     scanf( %s , t);     for (int i = 0; i < primes.size(); ++i) {       int p = primes[i];       for (int j = 0; j < n; ++j) {         P[i][j % p] += s[j] - t[j];       }     }     for (int p = m;; ++p) {       if (!isPrime(p)) continue;       for (int i = 0; i < primes.size(); ++i) {         int d = primes[i];         if (d >= p) break;         if ((p - 1) % d > 0) continue;         int r = -1;         do {           r = rand() % (p - 1) + 1;         } while ((r = power(r, (p - 1) / d, p)) == 1);         for (int k = 0, rr = 1; k < d; ++k) {           rr = 1LL * rr * r % p;           int sum = 0, mul = 1;           for (int j = 0; j < d; ++j) {             sum = (1LL * P[i][j] * mul + sum) % p;             mul = (1LL * mul * rr) % p;           }           if (sum == 0) return 0 * printf( %d %d n , p, rr);         }       }     }     return 0;   }