malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   const int mod = (int)1e9 + 7;   const int MAXN = (int)3e5 + 5;   vector<int> primes[1000005];   int x, p, k;   vector<pair<int, int> > v(1 << 7);   int calc(int a) {     int cnt = 1;     int num = 0;     int tmp = a;     a = 0;     for (int i = 1; i < (1 << primes[p].size()); i++) {       if (cnt * 2 == i) {         cnt *= 2;         num++;       }       v[i] = {v[i - cnt].first * primes[p][num], v[i - cnt].second + 1};       if (v[i].second % 2) {         a += tmp / v[i].first;       } else {         a -= tmp / v[i].first;       }     }     return tmp - a;   }   void solve() {     cin >> x >> p >> k;     k += calc(x);     int l = x + 1, r = 6e6 + 5e5 + 3e4 + 4e3 + 0e2 + 4e1;     while (l < r) {       int m = (l + r) / 2;       if (calc(m) >= k) {         r = m;       } else {         l = m + 1;       }     }     cout << l <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     for (int i = 2; i < 1000005; i++) {       if (!primes[i].size()) {         for (int j = i; j < 1000005; j += i) {           primes[j].push_back(i);         }       }     }     v[0] = {1, 0};     int t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e9 + 1;   int a[201][201];   int cnt[10][10];   int calc(int x, int y) {     if (x * 2 > y)       return 500;     else if (x * 4 > y)       return 1000;     else if (x * 8 > y)       return 1500;     else if (x * 16 > y)       return 2000;     else if (x * 32 > y)       return 2500;     else       return 3000;   }   int use[10];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 5; j++) {         cin >> a[i][j];       }     }     for (int k = 0; k < 5; k++) {       if (a[0][k] == -1)         use[k] = 0;       else if (a[1][k] == -1 || (a[1][k] != -1 && a[1][k] > a[0][k]))         use[k] = -1;       else         use[k] = 1;     }     for (int t = 0; t < 50000; t++) {       int sc1 = 0, sc0 = 0;       for (int i = 0; i < 5; i++) {         long long x = 0, y = 0;         for (int j = 0; j < n; j++) {           if (a[j][i] != -1) x++;         }         if (use[i] == 1) x += t;         y = n + t;         if (a[0][i] != -1) {           sc0 += calc(x, y) * (250 - a[0][i]);         }         if (a[1][i] != -1) {           sc1 += calc(x, y) * (250 - a[1][i]);         }       }       if (sc0 > sc1) {         cout << t << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long powmod(long long base, long long exp) {     base %= ((int)1e9 + 7);     long long result = 1;     while (exp > 0) {       if (exp & 1) result = (result * base) % ((int)1e9 + 7);       base = (base * base) % ((int)1e9 + 7);       exp >>= 1;     }     return result % ((int)1e9 + 7);   }   long long inv(long long x) {     return powmod(x, ((int)1e9 + 7) - 2) % ((int)1e9 + 7);   }   long long sum_to(long long x) {     if (x < 0) return 0;     return (((x * (x + 1)) % ((int)1e9 + 7)) * inv(2)) % ((int)1e9 + 7);   }   long long sq(long long x) { return (x * x) % ((int)1e9 + 7); }   long long sumodd(long long o) {     long long x = o / 2;     x %= ((int)1e9 + 7);     return sq(x + 1) % ((int)1e9 + 7);   }   long long sumeven(long long e) {     e /= 2;     e %= ((int)1e9 + 7);     return (2 * sum_to(e)) % ((int)1e9 + 7);   }   long long f(long long x) {     if (x == 0) return 0;     if (x == 1) return 1;     if (x == 2) return 3;     long long k = 0;     for (;; k++)       if ((1LL << k) - 1 > x) break;     k--;     long long e = 2, o = 1;     long long adde = 4, addo = 2;     for (int i = int(0); i < int(k / 2 - 1); i++) {       e += adde;       o += addo;       adde *= 4;       addo *= 4;     }     long long d = x - ((1LL << k) - 1);     if (k & 1) o = (o + addo);     if (k & 1) {       o = (o + 2 * ((1LL << (k - 1)) - 1));       e = (e + 2 * ((1LL << (k - 2)) - 1));       e = (e + 2 * d);     } else {       o = (o + 2 * ((1LL << (k - 2)) - 1));       e = (e + 2 * ((1LL << (k - 1)) - 1));       o = (o + 2 * d);     }     return ((sumodd(o) + sumeven(e)) % ((int)1e9 + 7) + ((int)1e9 + 7)) %            ((int)1e9 + 7);   }   int main() {     ios::sync_with_stdio(false);     long long l, r;     cin >> l >> r;     cout << (f(r) - f(l - 1) + ((int)1e9 + 7)) % ((int)1e9 + 7) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int d, m, n, b[210000];   int top, s[210000];   struct node {     int x, p;     bool operator<(const node &a) const { return x < a.x; }   } a[210000];   char Getchar() {     static char now[1 << 20], *S, *T;     if (T == S) {       T = (S = now) + fread(now, 1, 1 << 20, stdin);       if (T == S) return EOF;     }     return *S++;   }   int read() {     int x = 0, f = 1;     char ch = Getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = Getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = Getchar();     return x * f;   }   int main() {     d = read();     m = read();     n = read();     for (int i = 0; i < n; i++) {       a[i].x = read();       a[i].p = read();     }     sort(a, a + n);     a[n].x = d;     a[n].p = 0;     top = 1;     s[top] = n;     for (int i = n - 1; i >= 0; i--) {       while (a[s[top]].p >= a[i].p) top--;       b[i] = s[top];       s[++top] = i;     }     int res = m - a[0].x;     long long ans = 0;     for (int i = 0; i < n && res >= 0; i++) {       if (a[b[i]].x - a[i].x > res) {         int d = min(a[b[i]].x - a[i].x, m) - res;         res += d;         ans += 1ll * d * a[i].p;       }       res -= a[i + 1].x - a[i].x;     }     if (res < 0)       puts( -1 );     else       printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5, M = 1e4, MOD = 1e9 + 7, INF = 0x3f3f3f3f;   const double eps = 1e-8, pi = acos(-1.0);   int n, m;   vector<int> son[N + 10];   int col[N + 10];   int in[N + 10], out[N + 10], bel[N + 10];   int tot;   int k[N + 10];   struct query {     int l, r, id;   } node[N + 10];   int unit;   int cnt[N + 10];   int k_ti[N + 10];   int ans[N + 10];   bool cmp(query a, query b) {     if (a.l / unit != b.l / unit)       return a.l / unit < b.l / unit;     else       return a.r < b.r;   }   void work() {     memset(cnt, 0, sizeof cnt);     memset(k_ti, 0, sizeof k_ti);     int l = 1, r = 0;     for (int i = 0; i < m; i++) {       while (r < node[i].r) {         r++;         cnt[col[bel[r]]]++;         k_ti[cnt[col[bel[r]]]]++;       }       while (r > node[i].r) {         k_ti[cnt[col[bel[r]]]]--;         cnt[col[bel[r]]]--;         r--;       }       while (l < node[i].l) {         k_ti[cnt[col[bel[l]]]]--;         cnt[col[bel[l]]]--;         l++;       }       while (l > node[i].l) {         l--;         cnt[col[bel[l]]]++;         k_ti[cnt[col[bel[l]]]]++;       }       ans[node[i].id] = k_ti[k[node[i].id]];     }   }   void dfs(int u, int fa) {     in[u] = ++tot;     bel[tot] = u;     for (int i = 0; i < son[u].size(); i++) {       int v = son[u][i];       if (v == fa) continue;       dfs(v, u);     }     out[u] = tot;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &col[i]);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       son[u].push_back(v);       son[v].push_back(u);     }     tot = 0;     dfs(1, -1);     unit = (int)sqrt(n);     for (int i = 0; i < m; i++) {       int v;       scanf( %d%d , &v, &k[i]);       node[i].id = i;       node[i].l = in[v];       node[i].r = out[v];     }     sort(node, node + m, cmp);     work();     for (int i = 0; i < m; i++) printf( %d n , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m >> n;     vector<int> sg(n, +1);     for (int i = 1, x; i <= n; ++i) {       cout << i <<   n ;       fflush(stdout);       cin >> x;       if (x < 0) sg[i - 1] = -1;       if (x == 0) return 0;     }     int l = n + 1, r = m, pt = 0, x;     while (l < r) {       int md = (l + r) >> 1;       cout << md <<   n ;       fflush(stdout);       cin >> x;       x *= sg[pt];       pt = (pt + 1) % n;       if (x == 0) return 0;       if (x < 0)         r = md;       else         l = md + 1;     }     cout << l <<   n ;     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5, mod = 1e9 + 7;   long long pwr(long long b, long long p) {     long long res = 1;     while (p) {       if (p % 2) res = res * b % mod;       b = b * b % mod;       p /= 2;     }     return res;   }   long long k, n;   string colors[] = { white ,  yellow ,  green ,  blue ,  red ,  orange };   map<string, int> ids;   int cant[10][10];   map<long long, int> node_color;   map<long long, set<long long>> adj;   map<long long, long long> mem[10];   long long dfs(long long p, long long c) {     if (node_color.count(p) && node_color[p] != c) return 0;     if (adj.count(p) == 0) return 1;     if (mem[c].count(p)) return mem[c][p];     long long ret = 1;     for (long long ch : adj[p]) {       long long cur = 0;       for (int i = 1; i <= 6; ++i) {         if (cant[c][i]) continue;         cur += dfs(ch, i);         cur %= mod;       }       ret *= cur;       ret %= mod;     }     return mem[c][p] = ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     for (int i = 0; i < 6; ++i) {       ids[colors[i]] = i + 1, cant[i + 1][i + 1] = 1;       if (i % 2 == 0) cant[i + 1][i + 2] = cant[i + 2][i + 1] = 1;     }     cin >> k >> n;     set<long long> used;     while (n--) {       long long node;       string c;       cin >> node >> c;       int id = ids[c];       node_color[node] = id;       used.insert(node);       while (node != 1) {         long long parent = node / 2;         used.insert(parent);         adj[parent].insert(node);         node = parent;       }     }     long long color_ways = 0;     for (int i = 1; i <= 6; ++i) {       color_ways += dfs(1, i);       color_ways %= mod;     }     long long rem = ((1ll) << (1ll * k)) - 1 - used.size();     cout << color_ways * pwr(4, rem) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char c1, c2;     int t, n1, n2, ans1, ans2;     string s =  ^>v< ;     cin >> c1 >> c2 >> t;     n1 = s.find(c1);     n2 = s.find(c2);     t = t % 4;     ans1 = (n1 + t) % 4;     ans2 = (n1 - t);     if (ans2 < 0) ans2 += 4;     if (ans1 == n2 && ans2 == n2)       puts( undefined );     else if (ans1 == n2)       puts( cw );     else       puts( ccw );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void upd(long long& x) { x = -x - 1; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     for (int j = 0; j < n; j++) {       cin >> a[j];       if (a[j] >= 0) upd(a[j]);     }     if (n & 1) {       int jd = 0;       for (int j = 0; j < n; j++) {         if (a[jd] > a[j]) jd = j;       }       upd(a[jd]);     }     for (int j = 0; j < n; j++) cout << a[j] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   const int N = 100010;   int n;   long long x, y, a[N];   void solve() {     for (int i = 0; i < (int)(n); ++i) a[i] = 1;     a[0] = y - n + 1;     for (int i = 0; i < (int)(n); ++i) x -= ((a[i]) * (a[i]));     if (y < n || x > 0)       puts( -1 );     else {       for (int i = 0; i < (int)(n); ++i)         printf(              %I64d                n ,             a[i]);     }   }   int main() {     while (         ~scanf( %d                  %I64d                  %I64d ,                &n, &x, &y)) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const int maxn = 100010;   int IN() {     int c, f, x;     while (!isdigit(c = getchar()) && c !=  - )       ;     c ==  -  ? (f = 1, x = 0) : (f = 0, x = c -  0 );     while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c -  0 ;     return !f ? x : -x;   }   int n, T;   char s[maxn];   bool vis[maxn], c[maxn];   bool check() {     int ans = 0;     for (int i = 0; i < 26; i++)       if (vis[i]) ans++;     return ans == 1;   }   int main() {     scanf( %d , &n);     int ans = 0;     fill(vis, vis + maxn, 1);     fill(c, c + maxn, 1);     for (int i = 1; i <= n; i++) {       char op[10];       scanf( %s%s , op, s);       char tp = op[0];       int len = strlen(s);       if (tp ==  . ) {         for (int i = 0; i < len; i++) vis[s[i] -  a ] = 0;       } else if (tp ==  ! ) {         if (check()) ans++;         int t[27];         memset(t, 0, sizeof(t));         for (int i = 0; i < len; i++) t[s[i] -  a ]++;         for (int i = 0; i < 26; i++)           if (!t[i]) vis[i] = 0;       } else if (tp ==  ? ) {         if (i != n && check()) ans++;         vis[s[0] -  a ] = 0;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     char name[55];     int score;     int c[50];   } comp[55];   int cmp1(node x, node y) {     if (x.score > y.score)       return 1;     else if (x.score == y.score) {       for (int i = 0; i < 50; i++)         if (x.c[i] > y.c[i])           return 1;         else if (x.c[i] < y.c[i])           return 0;     } else       return 0;   }   int cmp2(node x, node y) {     if (x.c[0] > y.c[0])       return 1;     else if (x.c[0] == y.c[0]) {       if (x.score > y.score)         return 1;       else if (x.score == y.score) {         for (int i = 1; i < 50; i++)           if (x.c[i] > y.c[i])             return 1;           else if (x.c[i] < y.c[i])             return 0;       } else         return 0;     } else       return 0;   }   int s[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};   int main() {     int t;     while (scanf( %d , &t) != EOF) {       memset(comp, 0, sizeof(comp));       int sum = 0;       while (t--) {         int n, i;         char na[55];         scanf( %d , &n);         for (i = 0; i < n; i++) {           scanf( %s , na);           int j;           for (j = 0; j < sum; j++) {             if (strcmp(comp[j].name, na) == 0) {               if (i < 10) comp[j].score += s[i];               comp[j].c[i]++;               break;             }           }           if (j == sum) {             strcpy(comp[sum].name, na);             if (i < 10) comp[sum].score += s[i];             comp[sum].c[i]++;             sum++;           }         }       }       sort(comp, comp + sum, cmp1);       printf( %s n , comp[0].name);       sort(comp, comp + sum, cmp2);       printf( %s n , comp[0].name);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long k;     cin >> k;     if (k <= 36) {       for (long long i = 1; i <= (k / 2); i++) {         cout << 8;       }       if (k % 2 == 1) {         cout << 4;       }     } else {       cout << -1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int getT(vector<vector<long long int>>&, int, int);   void _dp(vector<vector<long long int>>& dp, int n) {     for (int j = 0; j < n; j++) dp[0][j] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int k = 0; k < i; k++)           dp[i][j] += dp[k][j - 1] * dp[(i - 1) - k][j - 1];   }   int main() {     int n, h;     scanf( %d %d , &n, &h);     vector<vector<long long int>> dp(n + 1, vector<long long int>(n + 1, 0));     _dp(dp, n);     cout << dp[n][n] - dp[n][h - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, a[101], x, y;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     cin >> m;     while (m--) {       cin >> x >> y;       if (x != 1) a[x - 1] += y - 1;       if (x != n) a[x + 1] += a[x] - y;       a[x] = 0;     }     for (i = 1; i <= n; i++) cout << a[i] << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   const int maxn = (int)1e4 + 10;   long long a[maxn], v[maxn], b[maxn];   long long gcd(long long A, long long B) {     A = abs(A);     B = abs(B);     while (B != 0) {       A %= B;       swap(A, B);     }     return A;   }   bool gcdEx(long long A, long long &X, long long B, long long &Y, long long C) {     long long lastX = 0;     long long lastY = 1;     X = 1;     Y = 0;     while (B != 0) {       long long sub = A / B;       X -= lastX * sub;       Y -= lastY * sub;       A -= B * sub;       swap(A, B);       swap(X, lastX);       swap(Y, lastY);     }     if (C % A != 0) return false;     X *= C / A;     Y *= C / A;     return true;   }   int main() {     long long n, m;     int k;     cin >> n >> m >> k;     long long lcm = 1;     for (int i = 0; i < k; i++) {       cin >> a[i];       b[i] = a[i];       long long g = gcd(lcm, a[i]);       if (a[i] / g > n / lcm) {         puts( NO );         return 0;       }       lcm = a[i] / g * lcm;     }     for (int i = 0; i < k; i++) {       v[i] = (-i % a[i] + a[i]) % a[i];     }     for (int i = 0; i < k - 1; i++) {       long long A = a[i];       long long B = -a[i + 1];       long long C = v[i + 1] - v[i];       long long G = gcd(A, B);       long long x, y;       if (!gcdEx(A, x, B, y, C)) {         puts( NO );         return 0;       }       assert(A * x + B * y == C);       long long X = (long long)1e18;       if (x < 0) {         long long add = (-x - B / G - 1) / (-B / G);         x += add * (-B / G);         y -= add * (-A / G);       }       long long sub = x / (-B / G);       x -= sub * (-B / G);       y += sub * (-A / G);       assert(x >= 0);       assert(B < 0 && -B == a[i + 1]);       assert(A * x + B * y == C);       assert(A * x >= 0);       assert(C < a[i + 1]);       if (y >= 0) {         X = min(X, a[i] * x + v[i]);       }       if (y < 0) {         long long add = (-y + A / G - 1) / (A / G);         y += add * (A / G);         x -= add * (B / G);       }       if (y >= 0) {         long long sub = y / (A / G);         y -= sub * (A / G);         x += sub * (B / G);       }       if (x >= 0) {         X = min(X, a[i + 1] * y + v[i + 1]);       }       if (X == (long long)1e18) {         puts( NO );         return 0;       }       if (X > m - k + 1) {         puts( NO );         return 0;       }       assert(X % a[i + 1] == v[i + 1]);       a[i + 1] = a[i] / gcd(a[i], a[i + 1]) * a[i + 1];       v[i + 1] = X;     }     long long X = v[k - 1];     if (X == 0) X = a[k - 1];     if (X > m - k + 1) {       puts( NO );       return 0;     }     for (int i = 0; i < k; i++) {       if (gcd(lcm, X + i) != b[i]) {         puts( NO );         return 0;       }     }     puts( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   int Ans[MAXN * 2], L, R, n;   struct XY {     int sz = 0, totid = 0, Ret, ll, rr;     int las[MAXN * 10], top[MAXN], en[MAXN], pos[MAXN], siz[MAXN], dep[MAXN],         fa[MAXN], deleted[MAXN * 3];     struct Edge {       int to, pre;     } e[MAXN * 35];     void add(int a, int b) {       e[++sz].to = b;       e[sz].pre = las[a];       las[a] = sz;     }     void dfs1(int u, int father, int depth) {       dep[u] = depth;       fa[u] = father;       siz[u] = 1;       for (int i = las[u]; i; i = e[i].pre) {         dfs1(e[i].to, u, depth + 1);         siz[u] += siz[e[i].to];       }     }     void dfs2(int u, int tp) {       pos[u] = ++totid;       top[u] = tp;       int v = 0, maxisz = 0;       for (int i = las[u]; i; i = e[i].pre)         if (siz[e[i].to] > maxisz) v = e[i].to, maxisz = siz[e[i].to];       if (v) dfs2(v, tp);       for (int i = las[u]; i; i = e[i].pre)         if (e[i].to != v) dfs2(e[i].to, e[i].to);     }     void link(int rt, int l, int r) {       if (ll <= l && r <= rr) {         add(rt, Ret);         return;       }       int mid = (l + r) >> 1;       if (ll <= mid) link(rt << 1, l, mid);       if (rr > mid) link(rt << 1 | 1, mid + 1, r);     }     void insert(int x, int y, int id) {       while (top[x] != top[y]) {         if (dep[top[x]] < dep[top[y]]) swap(x, y);         ll = pos[top[x]];         rr = pos[x];         Ret = id;         link(1, 1, n);         x = fa[top[x]];       }       if (dep[x] < dep[y]) swap(x, y);       ll = pos[y] + 1;       rr = pos[x];       Ret = id;       if (ll <= rr) link(1, 1, n);     }     void query(int rt, int l, int r) {       for (int i = las[rt]; i; i = e[i].pre)         if (!deleted[e[i].to]) Ans[++R] = e[i].to, deleted[e[i].to] = 1;       las[rt] = 0;       int mid = (l + r) >> 1;       if (l == r) return;       if (ll <= mid)         query(rt << 1, l, mid);       else         query(rt << 1 | 1, mid + 1, r);     }     void doit(int t) {       ll = pos[t + 1];       query(1, 1, n);     }     void work(int l, int r) {       sort(Ans + l, Ans + r + 1);       for (int i = l; i <= r; ++i) printf( %d  , Ans[i]);       puts(  );       for (int i = l; i <= r; ++i) doit(Ans[i]);       L = r;     }     void read() {       for (int i = 2; i <= n; ++i) scanf( %d , &fa[i]), add(fa[i], i);       dfs1(1, -1, 1);       dfs2(1, 1);       for (int i = 0; i <= n + 9; ++i) las[i] = 0;       sz = 0;     }   } Tree[2];   int main() {     scanf( %d , &n);     Tree[0].read();     Tree[1].read();     for (int i = 2; i <= n; ++i) Tree[1].insert(Tree[0].fa[i], i, i - 1);     for (int i = 2; i <= n; ++i) Tree[0].insert(Tree[1].fa[i], i, i - 1);     scanf( %d , &Ans[++R]);     Tree[1].deleted[Ans[R]] = 1;     while (L < R) {       if (L < R) puts( Blue ), Tree[0].work(L + 1, R);       if (L < R) puts( Red ), Tree[1].work(L + 1, R);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[200007], q;   int l[200007], r[200007], prime[1000007], id[1000007];   long long bit[200007], ans[200007], inv[1000007], prd[200007], divide[200007],       cal[1000007];   vector<pair<int, int> > query[200007];   vector<int> dv[200007];   const long long mod = 1e9 + 7;   long long pw(long long a, long long b) {     if (b == 1) return a;     long long ret = pw(a, b / 2);     if (b % 2 == 0) return ret * ret % mod;     return ret * ret % mod * a % mod;   }   void upd(int pos, long long val) {     for (int i = pos; i <= n; i += i & -i) bit[i] = bit[i] * val % mod;   }   long long get(int pos) {     long long res = 1;     for (int i = pos; i >= 1; i -= i & -i) {       res = (res * bit[i]) % mod;     }     return res;   }   long long get(int l, int r) { return (get(r) * pw(get(l - 1), mod - 2)) % mod; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 2; i <= 1000000; i++) {       if (prime[i]) continue;       for (int j = i; j <= 1000000; j += i) {         if (!prime[j]) prime[j] = i;       }     }     inv[0] = 1;     for (int i = 1; i <= 1000000; i++) {       inv[i] = pw(i, mod - 2);       if (prime[i] == i) cal[i] = 1LL * (i - 1) * inv[i] % mod;     }     prd[0] = 1, divide[0] = 1;     for (int i = 1; i <= n; i++)       prd[i] = (prd[i - 1] * 1LL * a[i]) % mod,       divide[i] = (divide[i - 1] * inv[a[i]]) % mod;     for (int i = 1; i <= n; i++) {       bit[i] = 1;       int cur = a[i], prv = 1;       while (cur > 1) {         if (prime[cur] != prv) {           prv = prime[cur];           dv[i].push_back(prv);         }         cur /= prv;       }     }     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %d %d , &l[i], &r[i]);       ans[i] = (prd[r[i]] * divide[l[i] - 1]) % mod;       query[r[i]].push_back(make_pair(l[i], i));     }     for (int i = 1; i <= n; i++) {       for (int j : dv[i]) {         int pos = id[j];         if (pos) upd(pos, 1LL * j * inv[j - 1] % mod);         upd(i, cal[j]);         id[j] = i;       }       for (int j = 0; j < (int)query[i].size(); j++) {         int L = query[i][j].first;         int idx = query[i][j].second;         ans[idx] = (ans[idx] * get(L, i)) % mod;       }     }     for (int i = 1; i <= q; i++) printf( %lld n , ans[i]);   }