malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100007;   int n, k;   int s[N];   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , s + i);     if (k >= n) {       printf( %d n , s[n - 1]);       return 0;     }     int maxi = 0;     while (n < 2 * k) {       maxi = max(s[--n], maxi);       k--;     }     for (int i = 0; i < k; i++) {       maxi = max(s[i] + s[n - i - 1], maxi);     }     printf( %d n , maxi);   }
#include <bits/stdc++.h>   using namespace std;   string s, s1;   int main() {     cin >> s;     cin >> s1;     reverse(s.begin(), s.end());     reverse(s1.begin(), s1.end());     while (!s.empty() && s[s.size() - 1] ==  0 ) s.pop_back();     while (!s1.empty() && s1[s1.size() - 1] ==  0 ) s1.pop_back();     if (s.size() > s1.size())       cout <<  > ;     else if (s1.size() > s.size())       cout <<  < ;     else {       int z = 0;       for (int i = s.size() - 1; i >= 0 && z == 0; i--)         if (s[i] > s1[i])           z = 1;         else if (s1[i] > s[i])           z = 2;       if (z == 1)         cout <<  > ;       else if (z == 2)         cout <<  < ;       else         cout <<  = ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 105, mod = 1e9 + 7;   int dp[N][N * N];   bool done[N][N * N];   int fact[N], inv[N];   int arr1[N];   int arr2[N];   int n, k;   long long m;   inline int add(int a, int b) {     int res = a + b;     if (res >= mod) res -= mod;     return res;   }   inline int mult(int a, int b) {     long long res = a * 1LL * b;     return res % mod;   }   int powmod(int a, long long b) {     int res = 1;     while (b) {       if (b & 1) {         res = mult(res, a);       }       a = mult(a, a);       b >>= 1;     }     return res;   }   int ncr(int n, int r) {     int res = fact[n];     res = mult(res, inv[r]);     res = mult(res, inv[n - r]);     return res;   }   int solve(int pos, int cnt) {     if (cnt < 0) return 0;     if (pos == n + 1) return (cnt == 0);     if (done[pos][cnt]) return dp[pos][cnt];     if ((n + 1 - pos) * n < cnt) return 0;     long long p = m / n;     bool b = (pos <= m % n);     if (b) {       for (int i = 0; i <= n; i++) {         dp[pos][cnt] = add(mult(solve(pos + 1, cnt - i), arr2[i]), dp[pos][cnt]);       }     } else {       for (int i = 0; i <= n; i++) {         dp[pos][cnt] = add(mult(solve(pos + 1, cnt - i), arr1[i]), dp[pos][cnt]);       }     }     done[pos][cnt] = true;     return dp[pos][cnt];   }   int main() {     scanf( %d %I64d %d , &n, &m, &k);     fact[0] = 1, inv[0] = 1;     long long p = m / n;     for (int i = 1; i < N; i++) {       fact[i] = mult(fact[i - 1], i);       inv[i] = powmod(fact[i], mod - 2);     }     for (int i = 0; i <= n; i++) {       arr1[i] = powmod(ncr(n, i), p);       arr2[i] = powmod(ncr(n, i), p + 1);     }     memset(dp, 0, sizeof(dp));     int ans = solve(1, k);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     int a[11], b[11];     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);     }     for (int i = 0; i < m; i++) {       scanf( %d , b + i);     }     sort(a, a + n);     sort(b, b + m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i] == b[j]) {           printf( %d n , a[i]);           return 0;         }       }     }     if (a[0] > b[0])       printf( %d%d n , b[0], a[0]);     else       printf( %d%d n , a[0], b[0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int in() {     int a;     scanf( %d , &a);     return a;   }   double din() {     double a;     scanf( %lf , &a);     return a;   }   int gcd(int a, int b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   const double eps = 1e-6;   int logbin(int a) {     a--;     int res = 1;     while (a) a >>= 1, res <<= 1;     return res;   }   int binpow(int a, int n) {     int res = 1;     while (n) {       if (n & 1) res *= a;       a *= a;       n >>= 1;     }     return res;   }   vector<vector<int> > g;   vector<char> u;   vector<int> p;   void dfs(int v) {     u[v] = 1;     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i];       if (!u[to]) {         p[to] = v;         dfs(to);       } else {         if (u[to] == 1) {           int vv = v;           while (p[vv] != to) {             u[vv] = 3;             vv = p[vv];           }         }       }     }     if (u[v] == 1) u[v] = 2;   }   int main() {     int n = in();     int m = in(), k = in();     vector<vector<pair<int, pair<int, int> > > > g(         n, vector<pair<int, pair<int, int> > >());     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       for (int j = 0; j < m; ++j) {         int u = in(), e = in(), h = in();         g[i].push_back(make_pair(u, make_pair(e, h)));       }     }     long long res = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (i == j) continue;         vector<pair<int, pair<int, int> > > s, t;         s = g[i];         t = g[j];         vector<int> c;         long long r = 0;         for (int y = 0; y < m; ++y) {           int nn = s[y].second.second;           for (int h = 0; h < nn; ++h) {             int buf = t[y].second.first - s[y].first;             if (buf > 0)               c.push_back(buf);             else               break;           }         }         sort((c).rbegin(), (c).rend());         for (int i = 0; i < min((int)c.size(), k); ++i) {           r += c[i];         }         res = max(res, r);       }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortinrev(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     return (a.first > b.first);   }   void solve() {     long long n;     cin >> n;     long long a[n];     map<long long, long long> mp;     for (long long i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]] = i;     }     long long p = 1;     long long end = n;     while (end != 0) {       long long k = mp[p];       for (long long i = k; i < end; i++) {         if (a[i] != p) {           cout <<  No                 <<   n ;           return;         }         p++;       }       end = k;     }     cout <<  Yes           <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> q;   int n;   void op(int i, int j) { q.push_back({i, j}); }   void f(int l, int r) {     if (l >= r) return;     int len = (r - l + 1);     if (len % 2 == 0) {       int m = (l + r) / 2;       f(l, m);       f(m + 1, r);       for (int j = 0; j < len / 2; j++) op(l + j, l + len / 2 + j);     } else {       r--;       int m = (l + r) / 2;       f(l, m);       f(m + 1, r);       for (int j = 0; j < len / 2; j++) op(l + j, l + len / 2 + j);       r++;       for (int j = l; j < r; j++) op(j, r);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     int k = log2(n);     k = (1 << k);     f(1, k);     f(n - k + 1, n);     cout << (int)q.size() <<   n ;     for (auto &it : q) cout << it.first <<     << it.second <<   n ;   }
#include <bits/stdc++.h>   long long n, i, k, j, t, b;   char a[2500];   bool s;   using namespace std;   int main() {     k = 0;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] ==  H ) k++;     }     b = n - k;     for (i = n + 1; i <= 2 * n; i++) a[i] = a[i - n];     for (i = 1; i <= 2 * n; i++)       if (i + k <= 2 * n) {         t = 0;         for (j = i; j < i + k; j++)           if (a[j] !=  H ) t++;         if (t < b) b = t;       }     cout << b << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, n, m, ans, x, l, r, tot, a[1000005], b[1000005], last[1000005],       to[1000005], Next[1000005], q[1000005], y;   inline void add(int x, int y) {     Next[++tot] = last[x];     last[x] = tot;     to[tot] = y;   }   inline bool check(int x) {     for (int i = 1; i <= n; i++) a[i] = b[i];     a[x]--;     int rr = r, ll = l;     q[++r] = x;     while (l < r) {       int k = q[++l];       for (int i = last[k]; i; i = Next[i]) {         a[to[i]]--;         if (!a[to[i]]) q[++r] = to[i];       }     }     if (r == n) return true;     r = rr, l = ll;     return false;   }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) scanf( %d%d , &x, &y), b[y]++, add(x, y);     for (i = 1; i <= n; i++)       if (b[i] == 0) q[++r] = i;     while (l < r) {       int k = q[++l];       for (int i = last[k]; i; i = Next[i]) {         b[to[i]]--;         if (!b[to[i]]) q[++r] = to[i];       }     }     if (r == n) return puts( YES ), 0;     for (i = 1; i <= n; i++) {       if (b[i] == 1) {         if (check(i)) return puts( YES ), 0;       }     }     puts( NO );   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v, ext;   long long f[20];   bool vis[20];   bool chck(long long j) {     while (j) {       if (j % 10 != 4 && j % 10 != 7) break;       j /= 10;     }     return j == 0;   }   int main() {     long long i, n, k, st, sum, j, pre, sz, ans;     f[0] = 1;     for (i = 1; i <= 13; i++) f[i] = f[i - 1] * i;     cin >> n >> k;     if (n <= 13 && k > f[n]) {       cout << -1 << endl;       return 0;     }     for (i = 1; f[i] < k; i++)       ;     st = n - i + 1;     sum = k;     for (j = 1; j <= i; j++) {       for (k = st; k <= n; k++) {         if (!vis[k - st]) {           if (sum - f[i - j] > 0) {             sum -= f[i - j];           } else {             ext.push_back(k);             vis[k - st] = 1;             break;           }         }       }     }     queue<long long> q;     q.push(4);     q.push(7);     v.push_back(4);     v.push_back(7);     while (!q.empty()) {       pre = q.front();       q.pop();       if (pre * 10 + 4 <= 5000000000LL) {         q.push(pre * 10 + 4);         q.push(pre * 10 + 7);         v.push_back(pre * 10 + 4);         v.push_back(pre * 10 + 7);       }     }     sz = v.size();     ans = 0;     for (i = 0; i < sz && v[i] < st; i++) ans++;     for (i = st; i <= n; i++) {       if (chck(i)) {         if (chck(ext[i - st])) ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   typedef struct val {     long int val, ind;   } va;   int cmp(const void *a, const void *b) {     va ka = *(va *)a;     va kb = *(va *)b;     if (ka.val > kb.val)       return -1;     else       return 1;   }   int a[2009][2009];   int main() {     va v[2009], ba[2009];     long int n, m, t1, t2, i, j, ans = 0;     scanf( %ld %ld , &n, &m);     for (i = 0; i < n; i++) {       scanf( %ld , &v[i].val);       v[i].ind = i + 1;       ba[i] = v[i];     }     for (i = 0; i < m; i++) {       scanf( %ld %ld , &t1, &t2);       a[t1][t2] = 1;       a[t2][t1] = 1;     }     qsort(v, n, sizeof(va), cmp);     for (i = 0; i < n; i++)       for (j = 1; j <= n; j++)         if (a[v[i].ind][j]) {           a[v[i].ind][j] = 0;           a[j][v[i].ind] = 0;           ans += ba[j - 1].val;         }     printf( %ld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[1000];   void quicksort(int l, int r) {     int b = l;     if (r - l < 1) {       return;     }     for (int i = l; i < r; ++i) {       if (A[i] < A[r]) {         swap(A[i], A[b]);         b = b + 1;       }     }     swap(A[r], A[b]);     quicksort(l, b - 1);     quicksort(b + 1, r);   }   int main() {     int r;     cin >> r;     for (int i = 0; i < r; ++i) {       cin >> A[i];     }     quicksort(0, r - 1);     if (r % 2 > 0) {       cout << A[(r / 2)];     } else {       cout << min(A[r / 2], A[r / 2 - 1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[105][200005];   int main() {     int n, k;     cin >> n >> k;     int a[n + 1], b[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     int off = 1000 * n;     for (int i = 0; i < 105; i++)       for (int j = 0; j < 200005; j++) dp[i][j] = -INT_MAX;     dp[0][off] = 0;     for (int curr = 1; curr <= n; curr++) {       int bl = a[curr] - b[curr] * k;       for (int bal = off; bal >= -off; bal--) {         dp[curr][bal + off] =             max(dp[curr - 1][bal + off], dp[curr - 1][bal - bl + off] + a[curr]);       }     }     cout << (dp[n][off] ? dp[n][off] : -1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s, t, x;   vector<int> lcp;   vector<bool> match;   constexpr int mxn = int(2e5) + 10;   int dp[mxn][3];   int pref[mxn];   const int mod = 1e9 + 7;   int ans(int start) {     if (dp[start][2] != -1) return dp[start][2];     if (start >= x.size()) return dp[start][0] = dp[start][1] = dp[start][2] = 0;     if (match[start]) {       dp[start][0] = dp[start][1] = 0;       int st = start + t.size() - 1;       int end = x.size() - 1;       int cnt = end - st + 1;       ans(st + 1);       dp[start][0] += cnt;       dp[start][0] %= mod;       dp[start][0] += pref[st + 1];       dp[start][0] %= mod;       dp[start][1] += ans(start + 1);       dp[start][1] %= mod;       dp[start][2] = (dp[start][0] + dp[start][1]) % mod;       pref[start] = pref[start + 1] + dp[start][2];       pref[start] %= mod;       return dp[start][2];     }     int curr = start;     while (curr < x.size() and not match[curr]) {       curr++;     }     ans(curr);     for (int i = curr - 1; i >= start; i--) {       dp[i][0] = dp[curr][0];       dp[i][1] = dp[i + 1][2];       dp[i][2] = dp[i][0] + dp[i][1];       dp[i][2] %= mod;       pref[i] = pref[i + 1] + dp[i][2];       pref[i] %= mod;     }     return dp[start][2];   }   void solve() {     cin >> s >> t;     x = t +  #  + s;     lcp = vector<int>(x.size());     match = vector<bool>(x.size());     lcp[0] = 0;     for (int i = 1; i < x.size(); i++) {       int j = lcp[i - 1];       while (j > 0 and x[j] != x[i]) j = lcp[j - 1];       if (x[j] == x[i]) j++;       lcp[i] = j;       if (lcp[i] == t.size()) {         match[i - t.size() + 1] = true;       }     }     cout << ans(t.size() + 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     memset(dp, -1, sizeof(dp));     memset(pref, 0, sizeof(pref));     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int fun(long long int x, long long int y, long long int p) {     long long int s = x / p;     if (x % p) s++;     long long int e = y / p;     return e - s + 1;   }   void solve() {     long long int n, p;     cin >> n >> p;     vector<pair<long long int, long long int> > A(n);     for (int i = 0; i < n; i++) cin >> A[i].first >> A[i].second;     double ans = 0;     for (int i = 0; i < n; i++) {       long long int f = i, s = (i + 1 + n) % n;       long long int s1 = A[f].second - A[f].first + 1,                     s2 = A[s].second - A[s].first + 1;       long long int a = fun(A[f].first, A[f].second, p);       long long int b = fun(A[s].first, A[s].second, p);       double up = (s1 - a) * 1.0 * (s2 - b);       double d = s1 * 1.0 * s2 * 1.0;       up = (up * 1.0) / (d * 1.0);       double pro = 1.0 - 1.0 * up;       ans = ans * 1.0 + pro * 2000.0;     }     printf( %f n , ans);   }   int main() {     long long int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q, sm, mx, x, y, ans;   char a[509][509];   int rr[509];   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf(  %c , &a[i][j]);     for (int i = 1; i <= n; i++) {       sm = 0, mx = 0;       for (int j = 1; j <= m; j++) {         if (a[i][j] ==  1 )           sm++;         else           mx = max(mx, sm), sm = 0;       }       mx = max(mx, sm);       rr[i] = mx;     }     for (int i = 1; i <= q; i++) {       scanf( %d%d , &x, &y), sm = 0, ans = 0, mx = 0;       a[x][y] = char(( 1  - a[x][y]) +  0 );       for (int j = 1; j <= m; j++) {         if (a[x][j] ==  1 )           sm++;         else           mx = max(mx, sm), sm = 0;       }       mx = max(mx, sm);       rr[x] = mx;       for (int j = 1; j <= n; j++) ans = max(ans, rr[j]);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   const long long INF = 1000 * 1000 * 1000 + 47;   const long long LINF = INF * (long long)INF;   using namespace std;   const int mod = 1000 * 1000 * 1000 + 9;   const int MAX = 100005;   pair<int, int> pts[MAX];   int n, k;   struct node {     int x, y, l, r;     int dp0, dp1;     node() { l = r = -1; }     node(pair<int, int> pt) {       l = r = -1;       x = pt.first, y = pt.second;       dp1 = 1;       dp0 = 0;     }   };   node treap[MAX];   int getDp0(int u) {     if (u == -1) return 0;     return treap[u].dp0;   }   int getDp1(int u) {     if (u == -1) return 0;     return treap[u].dp1;   }   void upd(int root) {     if (root == -1) return;     treap[root].dp1 = 1 + getDp0(treap[root].l) + getDp0(treap[root].r);     treap[root].dp0 = max(treap[root].dp1 - 1,                           max(getDp0(treap[root].l) + getDp1(treap[root].r),                               getDp1(treap[root].l) + getDp0(treap[root].r)));   }   int merge(int l, int r) {     if (l == -1) return r;     if (r == -1) return l;     int root;     if (treap[l].y > treap[r].y) {       root = l;       treap[l].r = merge(treap[l].r, r);     } else {       root = r;       treap[r].l = merge(l, treap[r].l);     }     upd(root);     return root;   }   pair<int, int> split(int root, int x) {     if (root == -1) return {-1, -1};     pair<int, int> res;     if (treap[root].x <= x) {       res = split(treap[root].r, x);       treap[root].r = res.first;       res = {root, res.second};     } else {       res = split(treap[root].l, x);       treap[root].l = res.second;       res = {res.first, root};     }     upd(res.first);     upd(res.second);     return res;   }   int main() {     ios_base::sync_with_stdio(0);     int root = -1;     cin >> n >> k;     for (int i = 0; i < k; i++) {       cin >> pts[i].first >> pts[i].second;     }     int a, b, c, d;     cin >> a >> b >> c >> d;     for (int i = k; i < n; i++) {       pts[i].first = ((a * (long long)pts[i - 1].first) + b) % mod;       pts[i].second = ((c * (long long)pts[i - 1].second) + d) % mod;     }     sort(pts, pts + n);     for (int i = 0; i < n; i++) {       treap[i] = node(pts[i]);       root = merge(root, i);     }     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r;       auto roots = split(root, l - 1);       auto roots2 = split(roots.second, r);       cout << ((roots2.first == -1) ? 0 : treap[roots2.first].dp0) << endl;       root = merge(roots.first, merge(roots2.first, roots2.second));     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   int main() {     long long n;     cin >> n;     if (n % 2 == 0) {       cout << 1ll * n / 2;       return 0;     }     bool flag = true;     for (int i = 3; i <= sqrt(n); i += 2) {       if (n % i == 0) {         cout << 1ll * (n - i) / 2 + 1;         return 0;       }     }     cout <<  1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2005, maxm = 4000005;   const double pi = 3.141592653589793;   const int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};   const int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};   int s[maxn][maxn], v[maxn][maxn], f[maxn][maxn];   int qx[maxm], qy[maxm];   int n, cir, rec;   double dis(double x, double y) { return sqrt(x * x + y * y); }   int main() {     int i, j, k, a, b, x, y, h, t, tx, ty;     double sumx, sumy, maxd, mind;     scanf( %d , &n);     for (i = 1; i <= n; ++i)       for (j = 1; j <= n; ++j) {         scanf( %d , &x);         if (x == 0) continue;         for (a = -2; a <= 2; ++a)           for (b = -2; b <= 2; ++b)             if (i + a > 0 && i + a <= n && j + b > 0 && j + b <= n)               ++s[i + a][j + b];       }     for (i = 1; i <= n; ++i)       for (j = 1; j <= n; ++j) {         s[i][j] = s[i][j] > 15 ? 1 : 0;         v[i][j] = s[i][j];       }     for (i = 1; i <= n; ++i)       for (j = 1; j <= n; ++j) {         if (s[i][j] == 0) continue;         sumx = 0;         sumy = 0;         h = 1;         t = 1;         qx[h] = i;         qy[h] = j;         for (; h <= t; ++h) {           a = qx[h];           b = qy[h];           sumx += a;           sumy += b;           for (k = 0; k < 8; ++k) {             x = a + dx[k];             y = b + dy[k];             if (v[x][y] == 0) ++f[a][b];             if (s[x][y] == 1) {               ++t;               qx[t] = x;               qy[t] = y;               s[x][y] = 0;             }           }         }         if (t < 125) continue;         tx = round(sumx / t);         ty = round(sumy / t);         maxd = 0;         for (k = 1; k <= t; ++k) maxd = max(maxd, dis(tx - qx[k], ty - qy[k]));         if (t < 2.5 * maxd * maxd)           ++rec;         else           ++cir;       }     printf( %d %d n , cir, rec);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000000;   int T, tot, prod, mn[1000010];   bool solved[10000][11];   bitset<1000> b[10000][11];   vector<int> V, prime;   unordered_map<int, int> id;   int main() {     scanf( %d , &T);     for (int i = 2; i <= N; i++)       if (!mn[i]) {         if (prime.size() < 1000) prime.push_back(i);         for (int j = i; j <= N; j += i) mn[j] = i;       }     auto get = [&](long long x) {       V.clear();       int lst = 50;       while (x > 1) {         int c = 0, t = x <= N ? mn[x] : 0;         if (!t) {           for (int i = lst; ~i; i--) {             if (!(x % prime[i])) {               t = prime[i], lst = i;               break;             }           }         }         while (!(x % t)) x /= t, c++;         V.push_back(c);       }       sort(V.begin(), V.end(), greater<int>());       int z = prod = 1;       for (int i = 0; i < V.size(); i++) {         prod *= V[i] + 1;         for (int j = 0; j < V[i]; j++) z *= prime[i];       }       return z;     };     for (int i = 1; i <= N; i++) {       if (i == get(i)) id[i] = ++tot;     }     function<void(int, int)> solve = [&](int x, int step) {       int y = get(x);       if (prod >= 1000) return;       if (!id.count(x)) id[x] = ++tot;       int $ = id[x];       if (solved[$][step]) return;       solved[$][step] = 1;       if (!step) {         b[$][step][prod] = 1;         return;       }       vector<int> V2 = V;       for (int i = 0; i < V2.size(); i++) {         int v = get(x / prime[i]);         solve(v, step - 1), b[$][step] |= b[id[v]][step - 1];         v = get(1LL * x * prime[i]);         if (v <= N * 100) solve(v, step - 1), b[$][step] |= b[id[v]][step - 1];       }       int v = get(1LL * x * prime[V2.size()]);       if (v <= N * 100) solve(v, step - 1), b[$][step] |= b[id[v]][step - 1];     };     for (int i = 1; i <= N; i++)       if (id[i]) {         for (int j = 0; j <= 10; j++) solve(i, j);       }     while (T--) {       int x, y, ans = INT_MAX;       scanf( %d %d , &x, &y);       x = get(x), y = get(y);       for (int i = 0; i <= 10; i++) {         for (int j = 0; j <= 10; j++)           if (i + j < ans) {             if ((b[id[x]][i] & b[id[y]][j]).any()) ans = min(ans, i + j);           }       }       assert(ans <= 10);       printf( %d n , ans);     }     return 0;   }