malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 5;   int c[N][26], fa[N], l[N], sz[N], np = 1, cnt = 1;   int a[N], b[N];   int q, len, vi[N];   char s[N];   void expend(int x) {     int p = np;     np = ++cnt;     l[np] = l[p] + 1;     sz[np] = 1;     for (; p && !c[p][x]; p = fa[p]) c[p][x] = np;     if (!p) {       fa[np] = 1;       return;     }     int q = c[p][x];     if (l[q] == l[p] + 1) {       fa[np] = q;       return;     }     int nq = ++cnt;     l[nq] = l[p] + 1;     memcpy(c[nq], c[q], 104);     fa[nq] = fa[q], fa[q] = fa[np] = nq;     for (; c[p][x] == q; p = fa[p]) c[p][x] = nq;   }   void init() {     for (int i = 1; i <= cnt; ++i) ++b[l[i]];     for (int i = 1; i <= len; ++i) b[i] += b[i - 1];     for (int i = cnt; i; --i) a[b[l[i]]--] = i;     for (int i = cnt; i; --i) sz[fa[a[i]]] += sz[a[i]];   }   int walk() {     int re = 0, u = 1, cur = 0;     for (int i = 0; i < (len << 1); ++i) {       int x = s[i] - 97;       if (c[u][x])         ++cur, u = c[u][x];       else {         while (u && !c[u][x]) u = fa[u];         if (u)           cur = l[u] + 1, u = c[u][x];         else           cur = 0, u = 1;       }       if (i >= len && cur >= len) {         int p = u;         while (p && !(len >= l[fa[p]] + 1 && len <= l[p])) p = fa[p];         if (!p) p = 1;         if (vi[p] != q + 1) vi[p] = q + 1, re += sz[p];       }     }     return re;   }   int main() {     scanf( %s%d , s, &q), len = strlen(s);     for (int i = 0; i < len; ++i) expend(s[i] - 97);     init();     while (q--) {       scanf( %s , s), len = strlen(s);       memcpy(s + len, s, len);       printf( %d n , walk());     }   }
#include <bits/stdc++.h>   using namespace std;   int k;   bool primes[200000][100];   int okay[5000000];   int okayN;   int nLeft[1000];   bool isPrime[1000];   bool used[5000000];   vector<int> ans;   bool compare(int a, int b) {     if (nLeft[a] > nLeft[b]) return 1;     if (nLeft[a] < nLeft[b]) return 0;     return (a < b);   }   int main() {     scanf( %d , &k);     okayN = 1;     okay[0] = 1;     isPrime[1] = 0;     for (int p = 2; true; ++p) {       bool prime = 1;       for (int i = 2; i * i <= p; ++i) {         if (p % i == 0) prime = 0;       }       if (!prime) {         isPrime[p] = 0;         continue;       }       isPrime[p] = 1;       for (int i = okayN - 1; i >= 0; --i) {         int j = okay[i] * p;         while (j <= 2 * k * k) {           for (int m = 2; m < p; ++m) primes[okayN][m] = primes[i][m];           primes[okayN][p] = 1;           okay[okayN++] = j;           j *= p;         }       }       for (int i = 2; i <= p; ++i) nLeft[i] = (k + 1) / 2;       int need[1000];       int needN = 0;       for (int i = 2; i <= p; ++i)         if (isPrime[i]) need[needN++] = i;       for (int i = 0; i < okayN; ++i) used[i] = 0;       bool ok = 1;       bool anybad = 0;       ans.clear();       while (ans.size() < k) {         int best = 0;         for (int i = 1; i < okayN; ++i) {           if (used[i]) continue;           for (int j = 0; j < needN; ++j) {             if (primes[i][need[j]] && !primes[best][need[j]]) {               best = i;               break;             }             if (!primes[i][need[j]] && primes[best][need[j]]) {               break;             }           }         }         ans.push_back(okay[best]);         if (used[best]) {           ok = 0;           break;         }         used[best] = 1;         anybad = 0;         for (int j = 0; j < needN; ++j) {           if (nLeft[need[j]]) anybad = 1;           if (primes[best][need[j]] && nLeft[need[j]]) --nLeft[need[j]];         }         sort(need, need + needN, compare);       }       if (ok && !anybad) {         for (int i = 0; i < ans.size(); ++i) printf( %d  , ans[i]);         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int inf = 0x7fffffff / 2;   int n, m;   int fa[maxn];   int vis[maxn];   struct edge {     int u;     int v;     int w;   } e[maxn];   struct ex {     int mi;     int mx;     int sum;   } ex[maxn];   int father(int x) {     if (x != fa[x]) fa[x] = father(fa[x]);     return fa[x];   }   void join(int x, int y) {     ex[father(y)].mi = min(ex[father(y)].mi, ex[father(x)].mi);     ex[father(y)].mx = max(ex[father(y)].mx, ex[father(x)].mx);     ex[father(y)].sum += ex[father(x)].sum;     fa[father(x)] = father(y);   }   int judge_node(int x) {     x = father(x);     int mi = ex[x].mi;     int mx = ex[x].mx;     int sum = ex[x].sum;     if (mi == -inf) return 1;     mi = ((mi - 1) * mi) / 2;     mx = ((mx + 1) * mx) / 2;     if ((mx - mi) != sum)       return 1;     else       return 0;   }   void init(int u, int v) {     ex[u].sum = u;     ex[v].sum = v;     ex[u].mx = u;     ex[u].mi = u;     ex[v].mx = v;     ex[v].mi = v;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       fa[i] = i;       ex[i].mi = inf;       ex[i].mx = -inf;       ex[i].sum = 0;     }     for (int i = 1; i <= m; i++) {       cin >> e[i].u >> e[i].v;       init(e[i].u, e[i].v);     }     for (int i = 1; i <= m; i++) {       if (father(e[i].u) != father(e[i].v)) {         join(e[i].u, e[i].v);       }     }     int ans = 0;     int mxx = -inf, last;     for (int i = 1; i <= n; i++) {       if (judge_node(i) && vis[father(i)] == 0) {         int l = ex[father(i)].mi;         int r = ex[father(i)].mx;         for (int j = l; j < r; j++) {           if (father(j) != father(i)) {             join(i, j);             ans++;             last = j;           }           l = ex[father(i)].mi;           r = ex[father(i)].mx;         }         vis[father(last)] = 1;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7, INF = 0x3f3f3f3f;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long qpow(long long a, long long n) {     long long r = 1 % P;     for (a %= P; n; a = a * a % P, n >>= 1)       if (n & 1) r = r * a % P;     return r;   }   long long inv(long long first) {     return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;   }   inline int rd() {     int first = 0;     char p = getchar();     while (p <  0  || p >  9 ) p = getchar();     while (p >=  0  && p <=  9 ) first = first * 10 + p -  0 , p = getchar();     return first;   }   const int N = 5e3 + 10;   int n, a, b, k;   int dp[N][N], s[N];   int main() {     scanf( %d%d%d%d , &n, &a, &b, &k);     dp[0][a] = 1;     int ans = 0;     for (int i = 0; i <= k; ++i) {       for (int first = 1; first <= n; ++first) {         int &r = dp[i][first];         if (i) (r += dp[i][first - 1]) %= P;         if (!r) continue;         if (i == k) (ans += r) %= P;         int w = abs(first - b);         if (w == 1) continue;         (dp[i + 1][max(first - w + 1, 0)] += r) %= P;         (dp[i + 1][first] -= r) %= P;         (dp[i + 1][first + 1] += r) %= P;         (dp[i + 1][min(first + w, n + 1)] -= r) %= P;       }     }     if (ans < 0) ans += P;     printf( %d n , ans);   }
#include <bits/stdc++.h>   namespace FastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   template <class T>   inline bool read(T& x) {     bool sign = 0;     char ch = nc();     x = 0;     for (; blank(ch); ch = nc())       ;     if (IOerror) return false;     if (ch ==  - ) sign = 1, ch = nc();     for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ;     if (sign) x = -x;     return true;   }   template <class T, class... U>   bool read(T& h, U&... t) {     return read(h) && read(t...);   }   };  // namespace FastIO   using namespace std;   using namespace FastIO;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int INF = 0x3f3f3f3f;   const int N = 2e5 + 10;   const int mod = 1e9 + 7;   vector<long long> e[N];   long long dis[N][2], siz[N][2], n, ans, w[N];   void dfs(long long u, long long fa) {     siz[u][1] = 1;     dis[u][1] = (w[u] + mod) % mod;     for (auto v : e[u]) {       if (v == fa) continue;       dfs(v, u);       ans =           (ans + dis[u][0] * siz[v][1] % mod + dis[v][1] * siz[u][0] % mod) % mod;       ans =           (ans + dis[u][1] * siz[v][0] % mod + dis[v][0] * siz[u][1] % mod) % mod;       siz[u][0] += siz[v][1];       siz[u][1] += siz[v][0];       dis[u][0] = (dis[u][0] + dis[v][1] - w[u] * siz[v][1] % mod + mod) % mod;       dis[u][1] = (dis[u][1] + dis[v][0] + w[u] * siz[v][0] % mod + mod) % mod;     }   }   signed main() {     read(n);     for (long long i = 1; i <= n; i++) read(w[i]);     for (long long i = 1; i < n; i++) {       long long u, v;       read(u, v);       e[u].push_back(v);       e[v].push_back(u);     }     dfs(1, 1);     ans *= 2;     ans %= mod;     for (long long i = 1; i <= n; i++) ans = (ans + w[i] + mod) % mod;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct cell {     long long mx, pref, suf, total;   } cell;   int tam[55], vet[300000];   long long sum[55], preffix[55], suffix[55], best[55], v[300000];   long long getMax(int n) {     long long ret = -1000000000000000000LL, aux = 0LL;     for (int i = 0; i < n; i++) {       aux += v[i];       ret = max(ret, aux);       if (aux < 0) aux = 0LL;     }     return ret;   }   cell solve(int b, int e) {     cell r;     if (b == e) {       r.mx = best[vet[b]];       r.total = sum[vet[b]];       r.pref = preffix[vet[b]];       r.suf = suffix[vet[b]];       return r;     }     int m = (b + e) / 2;     cell p1, p2;     p1 = solve(b, m);     p2 = solve(m + 1, e);     r.mx = max(max(p1.mx, p2.mx), p1.suf + p2.pref);     r.total = p1.total + p2.total;     r.pref = max(p1.pref, p1.total + p2.pref);     r.suf = max(p2.suf, p1.suf + p2.total);     return r;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> tam[i];       for (int j = 0; j < tam[i]; j++) {         cin >> v[j];       }       best[i] = getMax(tam[i]);       sum[i] = 0LL;       preffix[i] = suffix[i] = -1000000000000000000LL;       for (int j = 0; j < tam[i]; j++) {         sum[i] += v[j];         preffix[i] = max(preffix[i], sum[i]);       }       sum[i] = 0LL;       for (int j = tam[i] - 1; j >= 0; j--) {         sum[i] += v[j];         suffix[i] = max(suffix[i], sum[i]);       }     }     for (int i = 0; i < m; i++) {       cin >> vet[i];       vet[i]--;     }     cell ans = solve(0, m - 1);     cout << ans.mx << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1);   inline int sgn(double x) {     if (x < -eps)       return -1;     else if (x > eps)       return 1;     else       return 0;   }   struct Point {     double x, y;     Point(double _x = 0.0, double _y = 0.0) : x(_x), y(_y) {}     Point operator+(const Point &b) const { return Point(x + b.x, y + b.y); }     Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }     double operator*(const Point &b) const { return (x * b.x + y * b.y); }     double operator^(const Point &b) const { return (x * b.y - y * b.x); }     Point operator*(double b) { return Point(x * b, y * b); }     bool operator<(const Point &b) const {       if (sgn(x - b.x) == 0)         return sgn(y - b.y) <= 0;       else         return sgn(x - b.x) < 0;     }     bool operator==(const Point &b) const {       return sgn(x - b.x) == 0 && sgn(y - b.y) == 0;     }     Point rot(double ang) {       return Point(x * cos(ang) - y * sin(ang), x * sin(ang) + y * cos(ang));     }     Point rot(double g1, double g2) {       return Point(x * g2 - y * g1, x * g1 + y * g2);     }     double norm() { return sqrt(x * x + y * y); }     Point unit() {       double ll = norm();       return Point(x / ll, y / ll);     }   };   Point f[2005], p[2005];   bool vis[2005];   double d[2005];   int main() {     int n, m, ans = 0, i, j;     Point o = Point(0, 0);     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %lf%lf , &f[i].x, &f[i].y);       o = o + f[i];     }     o = o * (1.0 / n);     for (i = 0; i < n; i++) {       if (vis[i]) continue;       for (j = i; j < n; j++) {         if (f[i] + f[j] == o * 2.0) {           vis[i] = vis[j] = 1;           break;         }       }     }     for (i = j = 0; i < n; i++) {       if (!vis[i]) f[j++] = f[i] - o;     }     if (!j) return puts( -1 ), 0;     n = j;     for (i = m = 0; i < n; i++) {       Point u = f[0] + f[i];       Point v = Point(-u.y, u.x);       for (j = 0; j < n; j++) d[j] = f[j] * v;       sort(d, d + n);       for (j = 0; j < n; j++)         if (sgn(d[j] + d[n - 1 - j])) break;       if (j == n) {         v = v.unit();         for (j = 0; j < m; j++)           if (!sgn(p[j] ^ v)) break;         if (j == m) {           ans++;           p[m++] = v;         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long MOD = 1e9 + 7;   const long long mod = 998244353;   const long long mxN = 1e6;   void fileio() {}   vector<long long> v[mxN];   vector<long long> vis(mxN);   long long nd;   void dfs(long long x, long long p) {     vis[x] = 1;     for (auto i : v[x]) {       if (i == p) continue;       if (!vis[i])         dfs(i, x);       else         nd = x;     }   }   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     ;     for (long long i = 0; i < n; i++) {       v[i + 1].push_back(a[i]);       v[a[i]].push_back(i + 1);     }     vector<long long> v;     for (long long i = 1; i < n + 1; i++) {       if (vis[i]) continue;       nd = i;       dfs(i, -1);       v.push_back(nd);     }     long long ans = v.size() - 1;     long long root = -1;     for (long long i = 0; i < v.size(); i++) {       if (a[v[i] - 1] == v[i]) {         root = v[i];         break;       }     }     if (root == -1) {       ans++;       a[v[0] - 1] = v[0];       root = v[0];     }     for (long long i = 0; i < v.size(); i++) a[v[i] - 1] = root;     cout << ans <<   n ;     for (long long i = 0; i < a.size(); i++) cout << a[i] <<    ;     cout <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     fileio();     long long tc = 1;     while (tc--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long dx[4] = {-1, 1, 0, 0};   const long long dy[4] = {0, 0, -1, 1};   const long long MAX = 5e3 + 5;   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long n, m, ans, k, Q;   string second;   bool pal[MAX][MAX];   long long cnt[MAX][MAX];   void solve() {     for (int i = 0; i < n; ++i) pal[i][i] = cnt[i][i] = true;     for (int i = 0; i < n - 1; ++i) {       if (second[i] == second[i + 1]) pal[i][i + 1] = true, cnt[i][i + 1] = 1;       cnt[i][i + 1] += 2;     }     for (int len = 3; len <= n; ++len)       for (int i = 0; i < n - len + 1; ++i) {         int j = i + len - 1;         if (second[i] == second[j] && pal[i + 1][j - 1])           pal[i][j] = true;         else           pal[i][j] = false;         cnt[i][j] = pal[i][j] + cnt[i][j - 1] + cnt[i + 1][j] - cnt[i + 1][j - 1];       }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> second;     n = second.length();     solve();     cin >> Q;     while (Q--) {       int lo, hi;       cin >> lo >> hi;       --lo;       --hi;       cout << cnt[lo][hi] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int count = 0;       int n, m;       cin >> n >> m;       char a[n][m];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> a[i][j];         }       }       for (int i = 0; i < n - 1; i++) {         if (a[i][m - 1] !=  D ) {           count++;         }       }       for (int i = 0; i < m - 1; i++) {         if (a[n - 1][i] !=  R ) {           count++;         }       }       cout << count << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, m, A[12][N], q;   struct node {     int ans, lrt[12], rrt[12];     void trans(int u, int v) {       ans--;       for (int i = 1; i <= n; i++) {         if (lrt[i] == u) lrt[i] = v;         if (rrt[i] == u) rrt[i] = v;       }     }   } t[N << 2];   node _merge(node a, node b, int l, int r) {     node ret;     ret.ans = a.ans + b.ans;     for (int i = 1; i <= n; i++) ret.lrt[i] = a.lrt[i], ret.rrt[i] = b.rrt[i];     for (int i = 1; i <= n; i++) {       if (A[i][l] == A[i][r] && a.rrt[i] != b.lrt[i]) {         ret.trans(a.rrt[i], b.lrt[i]);         a.trans(a.rrt[i], b.lrt[i]);       }     }     return ret;   }   void build(int u, int l, int r) {     if (l == r) {       t[u].ans = n;       for (int i = 1; i <= n; i++) t[u].lrt[i] = t[u].rrt[i] = (l - 1) * n + i;       for (int i = 1; i <= n; i++)         if (A[i][l] == A[i - 1][l]) t[u].trans(t[u].lrt[i], t[u].lrt[i - 1]);       return;     }     int mid = (l + r) / 2;     build(u << 1, l, mid);     build(u << 1 | 1, mid + 1, r);     t[u] = _merge(t[u << 1], t[u << 1 | 1], mid, mid + 1);   }   node query(int u, int l, int r, int L, int R) {     if (l == L && r == R) return t[u];     int mid = (l + r) / 2;     if (R <= mid)       return query(u << 1, l, mid, L, R);     else if (L > mid)       return query(u << 1 | 1, mid + 1, r, L, R);     else       return _merge(query(u << 1, l, mid, L, mid),                     query(u << 1 | 1, mid + 1, r, mid + 1, R), mid, mid + 1);   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &A[i][j]);     build(1, 1, m);     while (q--) {       int l, r;       scanf( %d%d , &l, &r);       printf( %d n , query(1, 1, m, l, r).ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n, l[N], r[N], cnt[4 * N], one[4 * N];   vector<int> g;   map<int, int> mp;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> l[i] >> r[i];       g.push_back(l[i] - 1);       g.push_back(l[i]);       g.push_back(r[i]);       g.push_back(r[i] + 1);     }     sort(g.begin(), g.end());     for (int i = 0, cnt = 0; i < g.size(); ++i) {       if (!i || g[i] != g[i - 1]) cnt++;       mp[g[i]] = cnt;     }     for (int i = 1; i <= n; ++i) {       cnt[mp[l[i]]]++;       cnt[mp[r[i] + 1]]--;     }     for (int i = 1; i <= 4 * n; ++i) {       cnt[i] += cnt[i - 1];       if (cnt[i] == 1) {         one[i] = 1;       }       one[i] += one[i - 1];     }     for (int i = 1; i <= n; ++i) {       if (one[mp[r[i]]] == one[mp[l[i] - 1]]) {         cout << i <<   n ;         return 0;       }     }     cout <<  -1 n ;   }
#include <bits/stdc++.h>   using namespace std;   template <class temp>   inline void Rd(temp &p) {     p = 0;     char c;     while (c = getchar(), c < 48)       ;     do p = p * 10 + (c & 15);     while (c = getchar(), c > 47);   }   int pow(int n, int m) {     int ans = 1;     while (m) {       if (m & 1) ans = 1ll * ans * n % 1000000007;       m >>= 1;       n = 1ll * n * n % 1000000007;     }     return ans;   }   int head[100005], tot = 0;   struct eg {     int v, col, nxt;   } E[100005 << 1];   void add_edge(int u, int v, int w) {     E[++tot] = (eg){v, w, head[u]};     head[u] = tot;     E[++tot] = (eg){u, w, head[v]};     head[v] = tot;   }   int col[100005];   bool dfs(int u) {     for (int j = head[u]; j; j = E[j].nxt) {       int v = E[j].v, c = E[j].col;       if (!~col[v]) {         col[v] = col[u] ^ c ^ 1;         if (!dfs(v)) return false;       } else {         if ((col[u] ^ c ^ 1) != col[v]) return false;       }     }     return true;   }   int main() {     int n, m;     Rd(n), Rd(m);     for (int i = 1; i <= m; i++) {       int u, v, w;       Rd(u), Rd(v), Rd(w);       add_edge(u, v, w);     }     memset(col, -1, sizeof(col));     int sz = 0;     for (int i = 1; i <= n; i++)       if (!~col[i]) {         col[i] = 0;         if (!dfs(i)) {           puts( 0 );           return 0;         }         ++sz;       }     printf( %d n , pow(2, sz - 1));   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6;   const long long LINF = 1e18;   long long int n, cnt = 0, ans = 0, a, b, c, d, cmp[ohara], cmpp, m, h, w, x, y,                    sum[ohara], pos;   int dy[] = {1, 0, -1, 0};   int dx[] = {0, 1, 0, -1};   string alph( abcdefghijklmnopqrstuvwxyz ), s;   bool fl = true;   struct edge {     int to, cost;   };   int main(void) {     cin.tie(0);     ios::sync_with_stdio(false);     cin >> n >> c;     for (long long int(i) = 0; (i) < (int)(n); (i)++) {       cin >> a >> b;       if (a > b) {         pos = b;         b = a;         a = pos;       }       sum[a]++;       sum[b + 1]--;     }     for (long long int i = (1); i < (9999); i++) {       sum[i] += sum[i - 1];     }     for (long long int(i) = 0; (i) < (int)(9999); (i)++) {       if (sum[i] == n) {         cmp[cnt] = i;         cnt++;         fl = false;       }     }     if (fl) {       cout << (-1) << endl;       return 0;     }     ans = INF;     for (long long int(i) = 0; (i) < (int)(cnt); (i)++) {       ans = min(ans, max(cmp[i], c) - min(cmp[i], c));     }     cout << (ans) << endl;     return 0;   }
# include <bits/stdc++.h>   using namespace std;            int main(){    ios::sync_with_stdio(false);    int t;    cin>>t;    while(t--){     int n,m;     cin>>n>>m;     int ans=0;     int a[101]={0};     for(int i=0; i<n;i++){      int x;      cin>>x;      a[x]=1;     }     for(int i=0;i<m;i++){      int x;      cin>>x;      if(a[x]==1)       ans++;     }     cout<<ans<<  n ;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k, ans, last, d, x, y, a, b;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   void exgcd(long long a, long long b, long long& d, long long& x, long long& y) {     if (!b) {       x = 1, y = 0, d = a;     } else {       exgcd(b, a % b, d, y, x);       y -= (a / b) * x;     }   }   void check(long long x0, long long y0) {     exgcd(a, b, d, x, y);     if ((y0 - x0) % d != 0) return;     long long tmp = abs(b / d);     x *= (y0 - x0) / d;     x = (x % tmp + tmp) % tmp;     long long xx = x0 + 2 * n * x;     if (xx < 0 || xx >= last) return;     ans = min(ans, xx);   }   int main() {     cin >> n >> m >> k;     a = 2 * n, b = -2 * m;     while (k--) {       long long xx, yy;       cin >> xx >> yy;       ans = 1e18;       last = n / gcd(n, m) * m;       check(xx, yy);       check(-xx, yy);       check(xx, -yy);       check(-xx, -yy);       if (ans == 1e18)         cout << -1 << endl;       else         cout << ans << endl;     }   }