malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   vector<string> A[N];   vector<int> pq[N];   int n, m;   bool val[N];   inline int fnc(int i, int x) {     int ans = 0;     for (__typeof((n)) j = (1); j <= (n); j++) {       if (A[j].size() == 3) {         if (!pq[j].empty())           val[j] = val[pq[j][0]];         else           val[j] = A[j][2][0] ==  ?  ? x : A[j][2][i] -  0 ;       } else {         if (A[j][3] ==  XOR ) {           if (pq[j].size() == 0)             val[j] = (A[j][2][0] ==  ?  ? x : A[j][2][i] -  0 ) ^                      (A[j][4][0] ==  ?  ? x : A[j][4][i] -  0 );           else if (pq[j].size() == 1) {             if (A[j][2][0] >=  a  and A[j][2][0] <=  z )               val[j] = val[pq[j][0]] ^ (A[j][4][0] ==  ?  ? x : A[j][4][i] -  0 );             else               val[j] = val[pq[j][0]] ^ (A[j][2][0] ==  ?  ? x : A[j][2][i] -  0 );           } else             val[j] = val[pq[j][0]] ^ val[pq[j][1]];         } else if (A[j][3] ==  OR ) {           if (pq[j].size() == 0)             val[j] = (A[j][2][0] ==  ?  ? x : A[j][2][i] -  0 ) |                      (A[j][4][0] ==  ?  ? x : A[j][4][i] -  0 );           else if (pq[j].size() == 1) {             if (A[j][2][0] >=  a  and A[j][2][0] <=  z )               val[j] = val[pq[j][0]] | (A[j][4][0] ==  ?  ? x : A[j][4][i] -  0 );             else               val[j] = val[pq[j][0]] | (A[j][2][0] ==  ?  ? x : A[j][2][i] -  0 );           } else             val[j] = val[pq[j][0]] | val[pq[j][1]];         } else {           if (pq[j].size() == 0)             val[j] = (A[j][2][0] ==  ?  ? x : A[j][2][i] -  0 ) &                      (A[j][4][0] ==  ?  ? x : A[j][4][i] -  0 );           else if (pq[j].size() == 1) {             if (A[j][2][0] >=  a  and A[j][2][0] <=  z )               val[j] = val[pq[j][0]] & (A[j][4][0] ==  ?  ? x : A[j][4][i] -  0 );             else               val[j] = val[pq[j][0]] & (A[j][2][0] ==  ?  ? x : A[j][2][i] -  0 );           } else             val[j] = val[pq[j][0]] & val[pq[j][1]];         }       }       ans += val[j];     }     return ans;   }   void solve() {     string s;     cin >> n >> m;     cin.ignore();     unordered_map<string, int> idx;     for (__typeof((n)) i = (1); i <= (n); i++) {       getline(cin, s,   n );       stringstream second(s);       vector<string> v;       string r;       while (second >> r) v.push_back(r);       A[i] = v;       idx[v[0]] = i;       if (idx.count(v[2])) pq[i].push_back(idx[v[2]]);       if (v.size() == 5 and idx.count(v[4])) pq[i].push_back(idx[v[4]]);     }     string mn, mx;     for (__typeof((m - 1)) i = (0); i <= (m - 1); i++) {       int x = fnc(i, 0);       int y = fnc(i, 1);       if (x == y) {         mn.push_back( 0 );         mx.push_back( 0 );       } else if (x < y) {         mn.push_back( 0 );         mx.push_back( 1 );       } else {         mn.push_back( 1 );         mx.push_back( 0 );       }     }     cout << mn <<   n  << mx <<   n ;   }   signed main() {     int t;     ios_base::sync_with_stdio(false);     t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   inline void in(int &MAGNUS) { scanf( %d , &MAGNUS); }   inline void out(int MAGNUS) { printf( %d n , MAGNUS); }   inline void in(int &MAGNUS, int &CLAR) { scanf( %d%d , &MAGNUS, &CLAR); }   inline void out(int MAGNUS, int CLAR) { printf( %d %d n , MAGNUS, CLAR); }   inline void inl(long long &LIV) { scanf( %lld , &LIV); }   inline void inl(long long &LIV, long long &MART) {     scanf( %lld%lld , &LIV, &MART);   }   inline void outl(long long LIV) { printf( %lld n , LIV); }   inline void outl(long long LIV, long long MART) {     printf( %lld %lld n , LIV, MART);   }   using namespace std;   int main() {     int N, one, two, twoone = 0;     in(N);     in(one, two);     int ans = 0;     for (int i = 1; i <= N; i++) {       int x;       in(x);       if (x == 1) {         if (one > 0)           one--;         else {           if (two > 0)             two--, twoone++;           else if (twoone > 0)             twoone--;           else             ans++;         }       } else if (x == 2) {         if (two == 0)           ans += 2;         else           two--;       }     }     out(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sBs(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long SUMD(long long n);   long long BS(vector<pair<long long, long long> > &PS, long long s, long long e,                long long ser);   long long MI(long long a, long long m);   long long P[101LL + 1];   void Sieve(int n = 101LL);   long long Powb(long long b, long long n, long long m);   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long q = 1, t;     cin >> q;     t = q;     while (q--) {       long long i, j, n, m, k, l = 0, r = 0, a = 0, b = 0, c = 0, d = 0, e, g = 1,                                p, u, v, w, x, y, flag = 1;       cin >> n >> x;       long long ans = 0;       vector<long long> V(n);       for (i = 0; i < n; i++) cin >> V[i];       sort(V.rbegin(), V.rend());       for (i = 0; i < n; i++) {         if (V[i] * (i - l + 1) >= x) {           ans += 1;           l = i + 1;         }       }       cout << ans <<   n ;     }     return 0;   }   long long Powb(long long b, long long n, long long m) {     if (n == 0) return 1LL;     if (n == 1) return b;     long long temp = Powb(b, n / 2, m);     if (n % 2 == 0) {       return (temp * temp) % m;     } else {       return (b * ((temp * temp) % m)) % m;     }   }   long long SUMD(long long n) {     long long sum = 0;     while (n > 0) {       sum += n % 10;       n = n / 10;     }     return sum;   }   long long BS(vector<pair<long long, long long> > &PS, long long s, long long e,                long long ser) {     if (s > e) return s;     long long mid = (s + e) / 2;     if (PS[mid].first == ser) {       return mid;     } else if (PS[mid].first > ser) {       return BS(PS, s, mid - 1, ser);     } else       return BS(PS, mid + 1, e, ser);   }   long long MI(long long a, long long m) {     long long m0 = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   void Sieve(int n) {     for (int i = 1; i <= n; i++) P[i] = i;     for (long long i = 2; i * i <= n; i++) {       if (P[i] == i) {         for (long long j = i * i; j <= n; j += i) {           if (P[j] == j) P[j] = i;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   struct point {     int x, y, ind;   };   vector<point> fd[200200];   vector<point> bd[200200];   long long out[100100];   int main() {     scanf( %d%d%d , &n, &m, &k);     memset(out, -1, sizeof out);     for (int i = 0, x, y; i < k; ++i) {       scanf( %d%d , &x, &y);       fd[x - y + m].push_back({x, y, i});       bd[x + y].push_back({x, y, i});     }     int x = 0, y = 0, dx = 1, dy = 1;     long long t = 0;     while (true) {       if (dx == dy) {         int l = x - y + m;         for (int i = 0; i < (int)fd[l].size(); ++i) {           point &p = fd[l][i];           if (out[p.ind] != -1) continue;           long long dfx = x - p.x;           out[p.ind] = t + abs(dfx);         }       } else {         int l = x + y;         for (int i = 0; i < (int)bd[l].size(); ++i) {           point &p = bd[l][i];           if (out[p.ind] != -1) continue;           long long dfx = x - p.x;           out[p.ind] = t + abs(dfx);         }       }       int mh, mv;       if (dx == 1)         mh = n - x;       else         mh = x;       if (dy == 1)         mv = m - y;       else         mv = y;       if (mh < mv) {         if (dx == 1)           x = n;         else           x = 0;         t += mh;         y += mh * dy;         dx *= -1;       } else if (mh > mv) {         if (dy == 1)           y = m;         else           y = 0;         t += mv;         x += mv * dx;         dy *= -1;       } else {         break;       }     }     for (int i = 0; i < k; ++i) printf( %I64d n , out[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000000001;   const long long maxg = 4444444444LL;   vector<long long> g;   void recurs(int d, int len, long long z) {     if (d == len)       g.push_back(z);     else {       recurs(d + 1, len, z * 10 + 4);       recurs(d + 1, len, z * 10 + 7);     }   }   long long a[1000];   long long f[100];   long long fact(int n) {     if (n > 50) return inf;     if (f[n] != 0) return f[n];     if (n == 1 || n == 0) return f[n] = 1;     return f[n] = min(inf, n * min(inf, (fact(n - 1))));   }   bool good(int a) {     if (a == 0) return false;     while (a > 0) {       if (!(a % 10 == 4 || a % 10 == 7)) return false;       a /= 10;     }     return true;   }   int main() {     for (int ll = 1; ll <= 9; ll++) {       recurs(0, ll, 0);     }     g.push_back(maxg);     long long n, k;     cin >> n >> k;     if (fact(n) < k) {       cout << -1 << endl;       return 0;     }     long long p = 1;     long long m = n - 1;     while (fact(n - m) + 1 <= k) m--;     long long s = n - m;     for (int i = 1; i <= s; i++) a[i] = m + i;     while (p < k) {       for (int i = 1;; i++) {         if (fact(i + 1) + p > k) {           p += fact(i);           for (int j = s - i + 1;; j++) {             if (a[j] > a[s - i]) {               swap(a[j], a[s - i]);               break;             }           }           break;         }       }     }     long long ans = 0;     for (int i = 0; i < int(g.size()); i++) {       if (g[i] <= m) ans = i + 1;     }     for (int i = 1; i <= s; i++) {       if (good(i + m) && good(a[i])) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5;   int main() {     int x1, y1, x2, y2;     while (~scanf( %d%d%d%d , &x1, &y1, &x2, &y2)) {       long long x = x2 - x1 + 1;       long long y = y2 - y1 + 2;       long long s = x * y / 2 - x / 2;       printf( %lld n , s);     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> facts;   vector<long long int> inv_facts;   long long int c(long long int n, long long int p) {     if (p < 0 || n < p) return 0;     return (facts[n] * inv_facts[p]) % 1000000007 * inv_facts[n - p] % 1000000007;   }   long long int pow_mod(long long int x, long long int n) {     if (n == 0) return 1;     if (n & 1) return x * pow_mod(x, n - 1) % 1000000007;     long long int tmp = pow_mod(x, n / 2);     return tmp * tmp % 1000000007;   }   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     long long int X, Y, N;     cin >> X >> Y >> N;     facts.push_back(1);     inv_facts.push_back(1);     long long int maxF = X + Y + 1;     for (long long int n = 1; n <= maxF; ++n) {       long long int f = facts[n - 1] * n % 1000000007;       facts.push_back(f);       inv_facts.push_back(pow_mod(f, 1000000007 - 2));     }     vector<pair<long long int, long long int> > xys;     for (long long int n = 0; n < N; ++n) {       long long int x, y;       cin >> x >> y;       xys.push_back(make_pair(x - 1, y - 1));     }     xys.push_back(make_pair(X - 1, Y - 1));     sort(xys.begin(), xys.end());     vector<long long int> dp(N + 1);     for (long long int n = 0; n <= N; ++n) {       long long int x = xys[n].first, y = xys[n].second;       long long int tmp = c(x + y, y);       for (long long int m = 0; m < N; ++m) {         long long int xm = xys[m].first, ym = xys[m].second;         if (xm <= x && ym <= y)           tmp = (tmp + 1000000007 -                  dp[m] * c(x - xm + y - ym, x - xm) % 1000000007) %                 1000000007;       }       dp[n] = tmp;     }     cout << dp[N] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000005, md = 998244353;   int n, i, j, k, e, p[N], lmt, len, rt[N], ome[N], rome[N], g[N], h[N], w1[N],       w2[N], inv[N];   long long a[N], b[N], w, xxj[65];   inline void Read(long long &x) {     char c;     while ((c = getchar()) <  0  || c >  9 )       ;     x = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;   }   void ntt(int a[N], bool t) {     for (int i = 0; i < len; ++i)       if (i < rt[i]) swap(a[i], a[rt[i]]);     for (int l = 2; l <= len; l <<= 1) {       int m = l >> 1;       for (int i = 0; i < len; i += l)         for (int j = 0; j < m; ++j) {           int w = 1ll * (t ? ome[len / l * j] : rome[len / l * j]) *                   a[i + j + m] % md;           a[i + j + m] = (a[i + j] - w + md) % md;           a[i + j] = (a[i + j] + w) % md;         }     }     if (!t)       for (int i = 0; i < len; ++i) a[i] = 1ll * a[i] * inv[len] % md;   }   void merge(int l, int r) {     if (l == r) {       p[l] = 2;       return;     }     int mid = (l + r) / 2, i;     merge(l, mid);     merge(mid + 1, r);     lmt = 0;     while ((1 << lmt) <= r - l + 1) ++lmt;     len = 1 << lmt;     ome[0] = rome[0] = 1;     for (i = 1; i < len; ++i) {       rt[i] = 0;       for (j = 0; j < lmt; ++j)         if ((1 << j) & i) rt[i] |= 1 << (lmt - j - 1);       ome[i] = 1ll * ome[i - 1] * w1[len] % md,       rome[i] = 1ll * rome[i - 1] * w2[len] % md;     }     for (i = 0; i < len; ++i) g[i] = h[i] = 0;     for (i = l; i <= mid; ++i) g[i - l] = p[i];     for (i = mid + 1; i <= r; ++i) h[i - mid - 1] = p[i];     ntt(g, true);     ntt(h, true);     for (i = 0; i < len; ++i) g[i] = 1ll * g[i] * h[i] % md;     ntt(g, false);     for (i = 0; i < len; ++i) {       g[i + 1] += g[i] / 10;       g[i] %= 10;     }     for (i = l; i <= r; ++i) p[i] = g[i - l];   }   inline int pw(int a, int b) {     int rtn = 1;     while (b) {       if (b & 1) rtn = 1ll * rtn * a % md;       a = 1ll * a * a % md;       b >>= 1;     }     return rtn;   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       Read(a[i]);       Read(b[i]);       b[i] ^= a[i];       w ^= a[i];     }     e = 0;     for (i = 1; i <= n; ++i) {       for (j = 60; j >= 0; --j)         if ((1ll << j) & b[i]) {           if (!xxj[j]) {             xxj[j] = b[i];             break;           }           b[i] ^= xxj[j];         }       if (b[i] == 0) ++e;     }     for (j = 60; j >= 0; --j)       if ((1ll << j) & w) {         if (!xxj[j]) {           printf( 1/1 );           return 0;         }         w ^= xxj[j];       }     if (n - e == 0) {       printf( 0/1 );       return 0;     }     for (i = 1; i <= 2 * (n - e); ++i) {       w1[i] = pw(3, (md - 1) / i), w2[i] = pw(w1[i], md - 2);       if (i == 1)         inv[i] = 1;       else         inv[i] = 1ll * inv[md % i] * (md - md / i) % md;     }     merge(1, n - e);     for (i = n - e; p[i] == 0; --i)       ;     for (; i >= 2; --i) printf( %d , p[i]);     printf( %d/ , p[i] - 1);     for (i = n - e; p[i] == 0; --i)       ;     for (; i >= 1; --i) printf( %d , p[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[5005][15], oo = 1e5;   char str[5005];   int solve(int i, int s) {     if (str[i] == 0 and s == 2) {       return 0;     } else if (str[i] == 0 and s != 2) {       return oo;     } else if (~dp[i][s]) {       return dp[i][s];     } else {       int ans = 0;       if (s == 0) {         if (str[i] ==  a ) {           ans = min(solve(i + 1, s), solve(i + 1, 1));         } else {           ans = min(solve(i + 1, s) + 1, solve(i + 1, 1));         }       } else if (s == 1) {         if (str[i] ==  b ) {           ans = min(solve(i + 1, s), solve(i + 1, 2));         } else {           ans = min(solve(i + 1, s) + 1, solve(i + 1, 2));         }       } else if (s == 2) {         if (str[i] ==  a ) {           ans = solve(i + 1, s);         } else {           ans = solve(i + 1, s) + 1;         }       }       return dp[i][s] = ans;     }   }   int main() {     scanf(  %s , str);     memset(dp, -1, sizeof dp);     if (str[1] == 0) {       printf( 1 n );     } else {       printf( %d n , strlen(str) - solve(0, 0));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int cnt[maxn][26];   int dif[26];   int getAns() {     int cc = 0;     for (int i = 0; i < 26; ++i)       if (dif[i]) {         ++cc;       }     return cc;   }   int main() {     string s;     cin >> s;     int len = s.length();     for (int i = 1; i <= len; ++i) {       for (int k = 0; k < 26; ++k) cnt[i][k] = cnt[i - 1][k];       ++cnt[i][s[i - 1] -  a ];     }     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r;       --l;       for (int i = 0; i < 26; ++i) dif[i] = cnt[r][i] - cnt[l][i];       int tot = getAns();       if (tot == 1) {         if (r - l == 1)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       } else if (tot == 2) {         if (s[l] != s[r - 1])           cout <<  YES  << endl;         else           cout <<  NO  << endl;       } else {         cout <<  YES  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   inline int add(int a, int b) {     a += b;     if (a >= mod) a -= mod;     return a;   }   inline int mult(int a, int b) {     long long t = 1ll * a * b;     if (t >= mod) t %= mod;     return t;   }   int k, dp[1010][1010];   int main() {     scanf( %d , &k);     dp[1][0] = dp[1][1] = 1;     for (int p = 1; p < k; p++) {       for (int i = 0; i <= (p >= 10 ? k : min(k, 1 << p)); i++) {         for (int j = 0; i + j <= (p >= 10 ? k : min(k, (1 << (p + 1)))); j++) {           int tmp = mult(dp[p][i], dp[p][j]);           dp[p + 1][i + j] = add(dp[p + 1][i + j], tmp);           dp[p + 1][i + j + 1] = add(dp[p + 1][i + j + 1], tmp);           dp[p + 1][i + j] = add(dp[p + 1][i + j], mult(tmp, mult(i + j, 2)));           if (i + j)             dp[p + 1][i + j - 1] =                 add(dp[p + 1][i + j - 1], mult(tmp, mult(i + j, i + j - 1)));         }       }     }     printf( %d n , dp[k][1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 3e5 + 5;   int a[M], b[M], c, lst[M], sl[M], ans[M];   struct D {     int p1, p, s;   };   queue<D> q;   int read() {     int s = 0, t = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) t = -1;     for (; isdigit(ch); ch = getchar()) s = s * 10 + ch -  0 ;     return s * t;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) b[i] = read();     int h = n;     q.push({n, n, 0});     while (!q.empty()) {       int p1 = q.front().p1, p = q.front().p, s = q.front().s;       q.pop();       if (!p) {         c = s;         break;       }       for (int i = h - 1; i >= p - a[p]; i--)         lst[i] = p1, q.push({i, i + b[i], s + 1}), h = i;     }     if (!c) return printf( -1 ), 0;     printf( %d n , c);     for (int i = 1, x = 0; i <= c; i++, x = lst[x]) ans[i] = x;     for (int i = c; i; i--) printf( %d  , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> dp;   int l[305], c[305];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> l[i];     for (int i = 0; i < n; i++) cin >> c[i];     dp[0] = 0;     for (int i = 0; i < n; i++) {       for (auto x : dp) {         int a = gcd(x.first, l[i]);         if (dp.count(a))           dp[a] = min(dp[a], x.second + c[i]);         else           dp[a] = x.second + c[i];       }     }     if (dp.count(1))       cout << dp[1] << endl;     else       cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, c, b, ans = 0;     cin >> n;     int a[n + 1];     for (int i = 1; i <= n - 1; i++) cin >> a[i];     cin >> c >> b;     for (int i = c; i <= b - 1; i++) ans += a[i];     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int C[155][155];   int ans[155][2][155], cnt = 0;   bool vis[150] = {0};   void DFS(int x, int c) {     int i;     if (x > 150) return;     C[x][0] = C[x - 2][0];     for (i = 1; i < x; i++) {       C[x][i] = c * C[x - 1][i - 1] + C[x - 2][i];       if (C[x][i] < -1 || C[x][i] > 1) return;     }     C[x][x] = c * C[x - 1][x - 1];     if (vis[x] == 0 && C[x][x] == C[x - 1][x - 1]) {       vis[x] = 1;       ++cnt;       memcpy(ans[x][0], C[x], sizeof(C[x]));       memcpy(ans[x][1], C[x - 1], sizeof(C[x - 1]));     }     DFS(x + 1, 1);     DFS(x + 1, -1);   }   int main() {     int i, j;     ans[1][0][0] = 0;     ans[1][0][1] = 1;     ans[1][1][0] = 1;     cnt = 1;     C[0][0] = 1;     C[1][0] = 0;     C[1][1] = 1;     DFS(2, 1);     DFS(2, -1);     C[0][0] = -1;     DFS(2, 1);     DFS(2, -1);     int n;     scanf( %d , &n);     printf( %d n , n);     for (i = 0; i <= n; i++) printf( %d  , ans[n][0][n] * ans[n][0][i]);     printf(  n );     printf( %d n , n - 1);     for (i = 0; i <= n - 1; i++) printf( %d  , ans[n][0][n] * ans[n][1][i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ull = unsigned long long;   constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }   int bsr(int x) { return 31 - __builtin_clz(x); }   template <class T>   using V = vector<T>;   template <class T>   using VV = V<V<T>>;   template <class T>   T pow(T x, ll n) {     T r = 1;     while (n) {       if (n & 1) r *= x;       x *= x;       n >>= 1;     }     return r;   }   template <uint MD>   struct ModInt {     uint v;     ModInt() : v{0} {}     ModInt(ll v) : v{normS(v % MD + MD)} {}     static uint normS(const uint &x) { return (x < MD) ? x : x - MD; };     static ModInt make(const uint &x) {       ModInt m;       m.v = x;       return m;     }     ModInt operator+(const ModInt &r) const { return make(normS(v + r.v)); }     ModInt operator-(const ModInt &r) const { return make(normS(v + MD - r.v)); }     ModInt operator*(const ModInt &r) const { return make((ull)v * r.v % MD); }     ModInt &operator+=(const ModInt &r) { return *this = *this + r; }     ModInt &operator-=(const ModInt &r) { return *this = *this - r; }     ModInt &operator*=(const ModInt &r) { return *this = *this * r; }     static ModInt inv(const ModInt &x) { return pow(ModInt(x), MD - 2); }   };   using Mint = ModInt<TEN(9) + 7>;   const int MD = 1001001;   int factor[MD];   void first() {     fill(begin(factor), end(factor), -1);     for (int i = 2; i < MD; i++) {       if (factor[i] != -1) continue;       for (int j = i; j < MD; j += i) {         factor[j] = i;       }     }   }   int main() {     first();     V<int> id2v[300];     map<V<int>, int> vs;     int id[MD];     for (int i = 1; i < MD; i++) {       map<int, int> mp;       int x = i;       while (factor[x] != -1) {         mp[factor[x]]++;         x /= factor[x];       }       V<int> v;       for (auto p : mp) {         v.push_back(p.second);       }       sort(begin(v), end(v));       if (vs.count(v)) {         id[i] = vs[v];       } else {         int nid = int(vs.size());         vs[v] = nid;         id[i] = nid;         id2v[nid] = v;       }     }     int C = vs.size();     static Mint to1[MD][25], to0[MD][25];     to0[0][0] = 1;     for (int i = 1; i < 30; i++) {       to1[0][i] = 1;     }     for (int i = 1; i < MD; i++) {       Mint sm0, sm1;       for (int j = 0; j < 25; j++) {         sm0 += to0[i - 1][j];         sm1 += to1[i - 1][j];         to0[i][j] = sm0;         to1[i][j] = sm1;       }     }     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int r, n;       scanf( %d %d , &r, &n);       V<int> v = id2v[id[n]];       Mint co[11];       co[0] = 1;       int nw = 1;       for (int d : v) {         for (int i = nw; i >= 0; i--) {           co[i] = co[i] * to0[r][d];           if (i) co[i] += co[i - 1] * to1[r][d];         }         nw++;       }       Mint ans = 0;       for (int i = 0; i < 11; i++) {         ans += co[i] * Mint(1 << i);       }       printf( %d n , ans.v);     }     return 0;   }