malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int arr[10][10];   bool CheckArr(const string& s) {     const int n = s.length();     for (int a = 0; a < (10); ++a) {       if (arr[a][0] == 0) continue;       char c = s[arr[a][0] - 1];       for (int i = 0; i < (10); ++i) {         if (arr[a][i] == 0) break;         int idx = arr[a][i] - 1;         if (c != s[idx]) return false;       }     }     for (int i = 0; i < 10; ++i) {       if (arr[i][0] == 0) continue;       for (int j = i + 1; j < 10; ++j) {         if (arr[j][0] == 0) continue;         int idx1 = arr[i][0] - 1;         int idx2 = arr[j][0] - 1;         if (s[idx1] == s[idx2]) return false;       }     }     return true;   }   bool Check(const string& s1, const string& s2) {     const int n = s1.length();     if (n != s2.length()) return false;     for (int i = 0; i < (n); ++i) {       if (s1[i] ==  ? ) continue;       if (s1[i] >=  0  && s1[i] <=  9  && s1[i] == s2[i]) continue;       if (s1[i] >=  A  && s1[i] <=  J ) continue;       return false;     }     return true;   }   int main() {     string s;     cin >> s;     const int n = s.length();     if (n > 5) {       cout <<  :(  << endl;       return 0;     }     for (int i = 0; i < (n); ++i)       if (s[i] >=  A  && s[i] <=  J ) {         int alphaIdx = s[i] -  A ;         int posIdx = 0;         while (arr[alphaIdx][posIdx] != 0) ++posIdx;         arr[alphaIdx][posIdx] = i + 1;       }     int ans = 0;     for (int i = 1; i <= 99999; ++i) {       char str[6];       sprintf(str,  %d , i);       string s2(str);       if (Check(s, s2) && CheckArr(s2)) ++ans;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, i = 1, s, p, q;     cin >> x >> y;     s = x % 10;     q = s;     p = s;     while (p % 10 != 0 || p != y) {       if (p % 10 == 0 || p == y) {         break;       }       i++;       q = q + s;       p = q % 10;     }     cout << i;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long SIZE = 100000;   const int INF = 0x3f3f3f3f;   const long long ll_INF = 0x3f3f3f3f3f3f3f3f;   const long double PI = acos(-1);   const long long MAXN = numeric_limits<long long>::max();   const long long MAX = 2000000;   void disp(vector<long long> v) {     for (auto u : v) cout << u <<    ;     cout <<   n ;   }   void solve() {     long long l, r, x = 0, y = 1, temp, ans = 0;     cin >> l >> r;     y = 1;     while (y <= r) {       temp = y;       if (temp >= l && temp <= r) ans++;       while (temp <= r) {         temp *= 2;         if (temp >= l && temp <= r) ans++;       }       y *= 3;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( -ffloat-store )   using namespace std;   clock_t time_p = clock();   void aryanc403() {}   const long long int INF = 0xFFFFFFFFFFFFFFFL;   long long int seed;   mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());   inline long long int rnd(long long int l = 0, long long int r = INF) {     return uniform_int_distribution<long long int>(l, r)(rng);   }   class CMP {    public:     bool operator()(pair<long long int, long long int> a,                     pair<long long int, long long int> b) {       return !(a.first < b.first || (a.first == b.first && a.second <= b.second));     }   };   void add(map<long long int, long long int> &m, long long int x,            long long int cnt = 1) {     auto jt = m.find(x);     if (jt == m.end())       m.insert({x, cnt});     else       jt->second += cnt;   }   void del(map<long long int, long long int> &m, long long int x,            long long int cnt = 1) {     auto jt = m.find(x);     if (jt->second <= cnt)       m.erase(jt);     else       jt->second -= cnt;   }   bool cmp(const pair<long long int, long long int> &a,            const pair<long long int, long long int> &b) {     return a.first < b.first || (a.first == b.first && a.second < b.second);   }   const long long int mod = 1000000007L;   long long int T, n, i, j, k, in, cnt, l, r, u, v, x, y;   long long int m;   string s, t, a, b;   bool fl;   vector<vector<long long int> > dp, bb;   long long int solve(long long int n, long long int m) {     long long int &ans = dp[n + 1][m + 1];     if (ans != -1) return ans;     ans = INF;     if (n != -1) {       long long int cur = solve(n - 1, m) + 1;       if (cur < INF) ans = min(ans, bb[cur][a[n] -  a ]);     }     if (m != -1) {       long long int cur = solve(n, m - 1) + 1;       if (cur < INF) ans = min(ans, bb[cur][b[m] -  a ]);     }     return ans;   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> T;     while (T--) {       cin >> s >> t;       s =  #  + s;       fl = false;       bb.clear();       bb.resize((int)(s).size() + 5, vector<long long int>(26, INF));       for (i = ((int)(s).size() - 1); i >= (1); --i) {         assert(i + 1 < (int)(bb).size());         bb[i] = bb[i + 1];         bb[i][s[i] -  a ] = i;       }       for (long long int l = 1; l <= (int)(t).size(); ++l) {         a = t.substr(0, l);         b = t.substr(l);         n = (int)(a).size();         m = (int)(b).size();         dp.clear();         dp.resize(n + 2, vector<long long int>(m + 2, -1));         dp[0][0] = 0;         if (solve(n - 1, m - 1) < (int)(s).size()) {           fl = true;           break;         }       }       cout << (fl ?  YES  :  NO ) <<   n ;     }     aryanc403();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline char get(void) {     static char buf[100000], *S = buf, *T = buf;     if (S == T) {       T = (S = buf) + fread(buf, 1, 100000, stdin);       if (T == S) return EOF;     }     return *S++;   }   inline void read(int& x) {     static char c;     x = 0;     for (c = get(); c <  0  || c >  9 ; c = get())       ;     for (; c >=  0  && c <=  9 ; c = get()) x = x * 10 + c -  0 ;   }   const int M = 500 * 1000 + 10;   const int up = 300000 + 10;   const int mod = 998244353;   int n;   int cnt[M] = {0};   bool vs[M] = {0};   int dp[M] = {0};   int fac[100];   int tp;   int num[100];   int C[8][M] = {0};   void init() {     C[0][0] = 1;     for (int i = 1; i < up; ++i) {       C[0][i] = 1;       for (int j = 1; j < 8; ++j) C[j][i] = (C[j - 1][i - 1] + C[j][i - 1]) % mod;     }   }   void dfs(int c, int al) {     if (c == tp) {       ++cnt[al];       return;     }     for (int i = 0; i < num[c] + 1; ++i) {       dfs(c + 1, al);       al *= fac[c];     }   }   void add(int a) {     tp = 0;     for (int i = 2; i * i <= a; ++i) {       if (0 == a % i) {         fac[tp] = i;         num[tp] = 0;         while (a % i == 0) ++num[tp], a /= i;         ++tp;       }     }     if (1 != a) {       fac[tp] = a;       num[tp++] = 1;     }     dfs(0, 1);   }   bool solve(int x) {     for (int t = up; t; --t) {       dp[t] = C[x][cnt[t]];       for (int i = 2; i * t < up; ++i) dp[t] = (dp[t] - dp[i * t] + mod) % mod;     }     return dp[1] > 0;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     init();     cin >> n;     int a;     for (int i = 0; i < n; ++i) {       cin >> a;       if (vs[a]) continue;       vs[a] = 1;       add(a);     }     bool fg = 1;     if (vs[1]) {       fg = 0;       cout << 1 << endl;     }     for (int i = 2; i < 8; ++i) {       if (!fg) break;       if (solve(i)) {         fg = 0;         cout << i << endl;         break;       }     }     if (fg) cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)2e18;   const int N = 1005;   char s[N];   int lcp[N][N];   vector<pair<int, int>> segs;   bool cmp(pair<int, int> a, pair<int, int> b) {     int alen = a.second - a.first;     int blen = b.second - b.first;     int clen = min(alen, blen);     int com = lcp[a.first][b.first];     if (com < clen) return s[a.first + com] < s[b.first + com];     return alen < blen;   }   int n, m;   int mn[N];   long long dp[N][N];   void sadd(long long &a, long long b) {     a += b;     if (a >= INF) a = INF;   }   long long getCntGEQ(int id) {     for (int i = 0; i < n; i++) mn[i] = n + 1;     for (int i = id; i < (int)segs.size(); i++)       mn[segs[i].first] = min(mn[segs[i].first], segs[i].second);     memset(dp, 0, sizeof dp);     dp[0][0] = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j <= m; j++) {         long long cur = dp[i][j];         if (i != 0) sadd(dp[i + 1][j], cur);         sadd(dp[mn[i]][j + 1], cur);       }     return dp[n][m];   }   void printStr(pair<int, int> p) {     int l = p.first, r = p.second;     for (int i = l; i < r; i++) printf( %c , s[i]);     printf(  n );   }   int main(int, char **) {     long long k;     scanf( %d%d%lld , &n, &m, &k);     scanf( %s , s);     for (int i = n - 1; i >= 0; i--)       for (int j = n - 1; j >= 0; j--)         if (s[i] == s[j]) lcp[i][j] = 1 + lcp[i + 1][j + 1];     for (int i = 0; i < n; i++)       for (int j = i + 1; j <= n; j++) segs.emplace_back(i, j);     sort(segs.begin(), segs.end(), cmp);     int lb = -1, rb = (int)segs.size();     while (rb - lb > 1) {       int mb = (lb + rb) / 2;       long long cur = getCntGEQ(mb);       if (cur >= k)         lb = mb;       else         rb = mb;     }     printStr(segs[lb]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int32_t INFint = 1e9;   const long long INFll = 1e18;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n];       for (long long i = 0; i < n; i++) cin >> arr[i];       ;       sort(arr, arr + n);       long long ans = arr[0] * arr[n - 1];       long long fact[100000];       long long index = 0;       for (long long i = 2; i <= sqrt(ans); i++) {         if (ans % i == 0) {           fact[index] = i;           index++;           if (i != ans / i) {             fact[index] = ans / i;             index++;           }         }       }       sort(fact, fact + index);       if (index != n) {         cout << -1 <<   n ;       } else {         long long flag = 0;         for (long long i = 0; i < n; i++) {           if (fact[i] != arr[i]) {             flag = 1;             break;           }         }         ans = flag ? -1 : ans;         cout << ans <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     map<pair<string, string>, int> map_count;     vector<int> cost_list;     int n, a, b, k, f;     string s, t, prv =   ;     cin >> n >> a >> b >> k >> f;     for (int cost, i = 0; i < n; i++) {       cin >> s >> t;       if (s == prv) {         cost = b;       } else {         cost = a;       }       prv = t;       if (s > t) {         swap(s, t);       }       map_count[make_pair(s, t)] += cost;     }     for (auto& pkv : map_count) {       cost_list.push_back(pkv.second);     }     sort(cost_list.begin(), cost_list.end(), greater<int>());     int res = 0;     for (int i = 0; i < cost_list.size(); i++) {       if (i < k && cost_list[i] > f) {         res += f;       } else {         res += cost_list[i];       }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> compos;   int complement_component(vector<vector<int>> &g) {     int n = g.size(), ans = 0;     set<int> S;     for (int i = 0; i < n; ++i) S.insert(i);     while (S.size()) {       ++ans;       int theCompo = 0;       queue<int> q;       q.push(*S.begin());       S.erase(S.begin());       compos.push_back(vector<int>{});       while (q.size()) {         int u = q.front();         q.pop();         compos.back().push_back(u);         if (g[u].size()) {           while (S.size() and *S.begin() < g[u][0]) {             q.push(*S.begin());             S.erase(S.begin());           }           int it = 0;           while (S.size() and it < g[u].size()) {             auto cur = S.upper_bound(g[u][it]);             while (cur != S.end() and                    (it + 1 == g[u].size() or *cur < g[u][it + 1])) {               q.push(*cur), S.erase(cur);               cur = S.upper_bound(g[u][it]);             }             ++it;           }         } else {           compos.back() = vector<int>(n);           iota(compos.back().begin(), compos.back().end(), 0);           return 1;         }       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int N, M, u, v;     cin >> N >> M;     vector<vector<int>> g(N);     while (M--) {       cin >> u >> v, --u, --v;       g[u].push_back(v), g[v].push_back(u);     }     for (int i = 0; i < N; ++i) sort(g[i].begin(), g[i].end());     cout << complement_component(g) <<   n ;     sort(compos.begin(), compos.end());     for (auto &compo : compos) {       cout << compo.size() <<    ;       for (int i = 0; i < compo.size(); ++i)         cout << compo[i] + 1 <<    n [i == compo.size() - 1];     }   }
#include <bits/stdc++.h>   using namespace std;   long long int n;   vector<long long int> a, b;   struct segmentTree {     vector<long long int> t;     segmentTree() { t.resize(4 * n); }     void add(long long int ind, long long int x, long long int v = 0,              long long int tl = 0, long long int tr = n) {       if (tr - tl == 1)         t[v] += x;       else {         long long int mid = (tl + tr) / 2;         if (ind >= mid)           add(ind, x, 2 * v + 2, mid, tr);         else           add(ind, x, 2 * v + 1, tl, mid);         t[v] = t[2 * v + 1] + t[2 * v + 2];       }     }     long long int getK(long long int k, long long int v = 0, long long int tl = 0,                        long long int tr = n) {       if (tr - tl == 1)         return tl;       else {         long long int mid = (tl + tr) / 2;         if (t[2 * v + 1] >= k)           return getK(k, 2 * v + 1, tl, mid);         else           return getK(k - t[2 * v + 1], 2 * v + 2, mid, tr);       }     }   };   struct query {     long long int k, p, ind;     query(long long int k = 0, long long int p = 0, long long int ind = 0)         : k(k), p(p), ind(ind) {}   };   signed main() {     cin >> n;     a.resize(n);     b.resize(n);     iota(b.begin(), b.end(), 0);     for (long long int i = 0; i < n; ++i) cin >> a[i];     sort(b.begin(), b.end(), [](long long int i, long long int j) {       return a[i] > a[j] || (a[i] == a[j] && i < j);     });     long long int q;     cin >> q;     vector<long long int> ans(q);     vector<query> queries;     for (long long int i = 0; i < q; ++i) {       long long int k, p;       cin >> k >> p;       queries.emplace_back(k, p, i);     }     sort(queries.begin(), queries.end(),          [](const query& a, const query& b) { return a.k < b.k; });     long long int last = 0;     segmentTree t;     for (auto ev : queries) {       while (last < ev.k) t.add(b[last++], 1);       long long int ind = t.getK(ev.p);       ans[ev.ind] = a[ind];     }     for (auto i : ans) cout << i <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 1e18;   long long k, n, c;   string s;   long long p[26][26];   long long f[105][105][26];   char x, y;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s >> k >> n;     for (long long i = 1; i <= n; i++) {       cin >> x >> y >> c;       p[x -  a ][y -  a ] = c;     }     s =  *  + s;     for (long long i = 0; i < s.size(); i++)       for (long long j = 0; j <= k; j++)         for (long long v = 0; v < 26; v++) f[i][j][v] = -MAX;     for (long long i = 0; i < 26; i++) {       if (i == s[1] -  a )         f[1][0][i] = 0;       else         f[1][1][i] = 0;     }     for (long long i = 2; i < s.size(); i++) {       for (long long j = 0; j <= min(i - 1, k); j++) {         for (long long v = 0; v < 26; v++) {           for (long long u = 0; u < 26; u++) {             long long ok = (s[i] -  a  != v);             f[i][j + ok][v] = max(f[i][j + ok][v], f[i - 1][j][u] + p[u][v]);           }         }       }     }     long long ans = -MAX;     for (long long i = 0; i <= k; i++)       for (long long j = 0; j < 26; j++) ans = max(f[s.size() - 1][i][j], ans);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, mx, a[100][100], dp[100][100], me[100], inf = -1e15;   int sub(int a, int b) { return (((a - b) % k) + k); }   signed main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     memset(dp, -1, sizeof dp);     dp[0][0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         for (int u = min(m / 2, j); u >= 1; u--) {           for (int t = 0; t < k; t++) {             int x = sub(t, a[i][j]) % k;             if (dp[u - 1][x] != -1)               dp[u][t] = max(dp[u][t], dp[u - 1][x] + a[i][j]);           }         }       }       for (int u = 1; u <= m / 2; u++) {         for (int t = 0; t < k; t++) {           dp[0][t] = max(dp[0][t], dp[u][t]);           if (n != i) dp[u][t] = -1;         }       }     }     int mx = 0;     for (int i = 0; i <= m / 2; i++) mx = max(mx, dp[i][0]);     cout << mx <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, f[10] = {0}, x, i;     long long ans, z;     scanf( %lld , &n);     scanf( %lld , &m);     for (i = 0; i < n; i++) {       scanf( %lld , &x);       f[x - 1]++;     }     ans = (n * (n - 1)) / 2;     for (i = 0; i < m; i++) {       z = (f[i] * (f[i] - 1)) / 2;       ans -= z;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   bool IsPrime(int n) {     if (n == 1) return false;     for (int d = 2; d * d <= n; d++) {       if (n % d == 0) return false;     }     return true;   }   int main() {     int n;     cin >> n;     int count = 0;     while (n > 0) {       int j = 0;       int k = n;       int amx = INT_MIN;       while (k > 0) {         j = k % 10;         k = k / 10;         amx = max(amx, j);       }       n -= amx;       count++;     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353, N = 1e6 + 5;   long long fact[N], d[N];   long long f(int x) {     if (x == 0) return 1;     if (fact[x] != 0) return fact[x];     return fact[x] = (x * f(x - 1)) % MOD;   }   int main() {     d[1] = 1;     for (int i = 2; i < N; i++) {       d[i] = (1ll * i * (f(i - 1) - 1 + d[i - 1])) % MOD;     }     int n;     cin >> n;     cout << d[n];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmin(T &a, T b) {     a = min(a, b);   }   template <typename T>   void chkmax(T &a, T b) {     a = max(a, b);   }   inline int fread(void) {     int ret = 0, op = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) op = -1;     for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) -  0  + ch;     return ret * op;   }   const int MAXN = 2e5 + 10;   const int MAXM = +10;   int n, m, a[MAXN], c[MAXN];   struct rec {     int t, r;     bool operator<(const rec &b) const { return r < b.r; }   } s[MAXN];   int top;   inline void init(void) {     n = fread(), m = fread();     for (int i = 1; i <= n; ++i) a[i] = fread(), c[i] = a[i];   }   int lt, rt;   inline void work(void) {     rec now;     top = 0;     for (int i = 1; i <= m; ++i) {       now.t = fread(), now.r = fread();       while (top && s[top] < now) --top;       s[++top] = now;     }     sort(c + 1, c + s[1].r + 1);     lt = 1;     rt = s[1].r;     ++top;     s[top].r = 0;     for (int i = 2; i <= top; ++i) {       if (s[i - 1].t == 1) {         for (int j = s[i - 1].r; j > s[i].r; --j) a[j] = c[rt--];       } else {         for (int j = s[i - 1].r; j > s[i].r; --j) a[j] = c[lt++];       }     }     for (int i = 1; i <= n; ++i) printf( %d  , a[i]);   }   int main() {     init();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(const pair<long long int, long long int> &a,            const pair<long long int, long long int> &b) {     return a.second < b.second;   }   int main() {     long long int n, k, ai, bi, total = 0, ans = 0;     vector<long long int> a;     vector<pair<long long int, long long int> > ab;     map<long long int, long long int> jobs;     scanf( %lld %lld , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %lld , &ai), a.push_back(ai), jobs[ai]++;       if (jobs[ai] == 1) total++;     }     for (int i = 0; i < n; i++)       scanf( %lld , &bi), ab.push_back(make_pair(a[i], bi));     sort(ab.begin(), ab.end(), cmp);     total = k - total;     for (int i = 0; i < n; i++) {       if (jobs[ab[i].first] > 1 && total > 0) {         ans += ab[i].second;         total--;         jobs[ab[i].first]--;       }     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[101][101];   int main() {     cin >> n >> m;     if (n == 1 && m == 1)       cout <<  1 ;     else if (n == 2 && m == 2)       cout <<  -1 ;     else if ((n == 1 && m <= 3) || (m == 1 && n <= 3))       cout <<  -1 ;     else {       int k = n * m;       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j) {           if (i % 2 && !(j % 2)) {             a[i][j] = k;             --k;           }           if (!(i % 2) && j % 2) {             a[i][j] = k;             --k;           }         }       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j) {           if (!(i % 2) && !(j % 2)) {             a[i][j] = k;             --k;           }           if ((i % 2) && (j % 2)) {             a[i][j] = k;             --k;           }         }       for (int i = 0; i < n; ++i) {         for (int j = 0; j < m; ++j) cout << a[i][j] <<    ;         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     scanf( %d n , &n);     string a, b;     getline(cin, a);     getline(cin, b);     int q(0);     map<pair<char, char>, int> SET;     map<char, int> have;     for (int i(0), _l((int)(n)-1); i <= _l; ++i) {       if (a[i] != b[i]) {         ++q;         SET[make_pair(a[i], b[i])] = i;         have[a[i]] = i;       }     }     int delta(0);     pair<int, int> ans(-2, -2);     for (int i(0), _l((int)(n)-1); i <= _l; ++i) {       if (a[i] != b[i]) {         if (have.count(b[i]) && delta == 0)           delta = 1, ans = make_pair(i, have[b[i]]);         if (SET.count(make_pair(b[i], a[i])))           delta = 2, ans = make_pair(i, SET[make_pair(b[i], a[i])]);       }     }     cout << q - delta << endl;     cout << ans.first + 1 <<     << ans.second + 1 << endl;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200005], b[200005];   int nx[500005];   int n, m;   void getnext() {     nx[0] = -1;     int j = 0, k = -1;     while (j < m) {       if (k == -1 || b[j] == b[k])         nx[++j] = ++k;       else         k = nx[k];     }   }   int KMP() {     int ret = 0;     int i = 0, j = 0;     for (i = 0; i < n; i++) {       while (j > 0 && a[i] != b[j]) j = nx[j];       if (a[i] == b[j]) j++;       if (j == m) {         ret++;         j = nx[j];       }     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i != 0) a[i - 1] = a[i] - a[i - 1];     }     for (int i = 0; i < m; i++) {       cin >> b[i];       if (i != 0) b[i - 1] = b[i] - b[i - 1];     }     if (m == 1) {       cout << n << endl;       return 0;     }     n--;     m--;     getnext();     cout << KMP() << endl;     return 0;   }