malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   set<int> st;   int main() {     int t, i, j, k, n, m;     scanf( %d , &n);     for (i = 0; i < n; i++) {       int x;       scanf( %d , &x);       st.insert(x);     }     int a, b;     scanf( %d , &a);     scanf( %d , &b);     set<int>::iterator it, cit;     int ans = 0;     while (1) {       if (a == b) {         cout << ans << endl;         return 0;       }       int mx = 1;       for (it = st.begin(); it != st.end();) {         int val = *it;         cit = it;         it++;         if (a - (a % val) < b) {           st.erase(cit);         } else {           mx = max(mx, a % val);         }       }       ans++;       a = a - mx;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     int p;     scanf( %I64d %I64d %d , &n, &k, &p);     long long ndiv2 = n / 2;     long long ndiv2minus1 = n / 2 - 1;     long long nminusk = n - k;     for (int i = 0; i < p; i++) {       long long x;       scanf( %I64d , &x);       printf( %c , (((x == n) ? (n)                               : (1 + (x / 2) * ndiv2 -                                  ((x - 1) / 2) * ndiv2minus1)) <= nminusk)                        ? ( . )                        : ( X ));     }   exit:     return (0);   }
#include <bits/stdc++.h>   char str1[200], str2[200];   char lenstr1, lenstr2;   int dp1[200];   int dp2[200];   int got[200] = {0};   int twice;   int twicep;   int countc;   int calel(int st) {     int ite = st;     int len = 1;     for (int i = 0; i < lenstr2; i++) {       int flag = 0;       while (str1[st] != str2[i]) {         st++;         if (st == lenstr1) {           len++;           st = 0;           if (flag) return 1;           flag = 1;         }       }       st++;       if (st == lenstr1) {         len++;         st = 0;       }     }     dp1[ite] = len;     dp2[ite] = st;     return 0;   }   int main() {     int s1, s2;     scanf( %d%d , &s1, &s2);     scanf( %s%s , str1, str2);     lenstr1 = strlen(str1);     lenstr2 = strlen(str2);     for (int i = 0; i < lenstr1; i++)       if (calel(i)) {         printf( 0 n );         return 0;       }     got[0] = 1;     for (int i = 0;;) {       int j = dp2[i];       if (got[j]) {         twice = got[i] + dp1[i] - 1;         twicep = j;         break;       }       got[j] = got[i] + dp1[i] - 1;       i = j;     }     if (twice >= s1) {       countc = 0;       int i, j;       for (i = 0, j = 1; j <= s1;) {         j += dp1[i] - 1;         i = dp2[i];         countc++;       }       if (i == 0 && countc != 1) countc++;     } else {       countc = 0;       int p1 = 1;       for (int i = 0; i != twicep;) {         p1 += dp1[i] - 1;         i = dp2[i];         countc++;       }       int left = s1 - p1;       int i = twicep;       int single = 0;       do {         i = dp2[i];         single++;       } while (i != twicep);       int sinlen = twice - p1;       countc += single * (left / sinlen);       int p2 = p1 + left / sinlen * sinlen;       for (i = twicep;;) {         p2 += dp1[i] - 1;         i = dp2[i];         if (p2 > s1) break;         countc++;       }       if (i == 0) countc++;     }     printf( %d n , countc / s2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[400 + 2], ans = 1 << 30;   int main() {     cin >> n;     for (register int i = 1; i <= n; i++) cin >> a[i];     for (int i = n; i >= 2; i--) {       if (a[i] >= ans) break;       for (int j = i; j <= n; j++) {         register int num = a[i - 1] - 1, x = 1, t;         for (register int k = i; k <= j; k++)           if (num >= a[k]) {             t = num / a[k];             x += t, num -= t * a[k];           }         num = a[i - 1] - 1 - num + a[j];         int res = num;         if (res < ans) {           for (register int k = 1; k <= n; k++)             if (num >= a[k]) {               t = num / a[k];               x -= t, num -= t * a[k];               if (x < 0) break;             }           if (x < 0) ans = res;         }       }     }     if (ans == 1 << 30) ans = -1;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[101][4];   int main() {     int n;     cin >> n;     int min = 0, ind = 0;     for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];     min = 100000;     ind = 0;     for (int i = 0; i < n; i++) {       bool ust = false;       for (int j = 0; j < n; j++)         if (i != j)           if (a[i][0] < a[j][0] && a[i][1] < a[j][1] && a[i][2] < a[j][2]) {             ust = true;             break;           }       if (!ust)         if (a[i][3] < min) {           min = a[i][3];           ind = i;         }     }     cout << ind + 1 << endl;     return 0;   }
#include <stdio.h>   #include <string.h>   #include <math.h>   #include <limits.h>   #include <time.h>   #include <vector>   #include <queue>   #include <stack>   #include <map>   #include <set>   #include <algorithm>   #pragma warning(disable:4996)   #pragma warning(disable:6031)   #define MAX(X,Y) (X>Y?X:Y)   #define MIN(X,Y) (X<Y?X:Y)   #define ll long long   #define pii pair<int,int>   using namespace std;      int t,n;   char str[201];      int main() {    scanf( %d , &t);    while (t--) {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf(  %c , &str[i]);     bool ans = false;     if (str[0] ==  2 ) {      if (str[1] ==  0 ) {       if (str[2] ==  2 ) {        if (str[3] ==  0 ) ans = true;        else if (str[n - 1] ==  0 ) ans = true;       }       else if (str[n - 1] ==  0  && str[n - 2] ==  2 ) ans = true;      }      else if (str[n - 1] ==  0  && str[n - 2] ==  2  && str[n - 3] ==  0 ) ans = true;     }     else if (str[n - 1] ==  0  && str[n - 2] ==  2  && str[n - 3] ==  0  && str[n - 4] ==  2 ) ans = true;     printf( %s n , (ans ?  YES  :  NO ));    }   }
#include <bits/stdc++.h>   using namespace std;   int s[10004];   int main() {     int k, n1, n2, n3, t1, t2, t3;     cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;     for (int i = 0; i < k; i++) {       if (i >= n1) {         s[i] = max(s[i], s[i - n1] + t1);       }       if (i >= n2) {         s[i] = max(s[i], s[i - n2] + t2);       }       if (i >= n3) {         s[i] = max(s[i], s[i - n3] + t3);       }     }     cout << s[k - 1] + t1 + t2 + t3;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, a[33][33], vis[33];   int dfs(int u, int sum, int lim) {     if (sum > lim) return 0;     if (u > n) return 1;     int ans = dfs(u + 1, sum, lim);     for (int v = 1; v <= n && ans < k; v++)       if (!vis[v] && a[u][v])         vis[v] = 1, ans += dfs(u + 1, sum + a[u][v], lim), vis[v] = 0;     return ans;   }   int main() {     cin >> n >> m >> k;     while (m--) {       int x, y, z;       cin >> x >> y >> z;       a[x][y] = z;     }     int l = 0, r = 20000, ans = 0;     while (l <= r) {       m = (l + r) / 2;       if (dfs(1, 0, m) >= k)         ans = m, r = m - 1;       else         l = m + 1;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   std::vector<long long> v[100009];   long long vis[100009], c = 0;   void dfs(long long x) {     c++;     vis[x] = 1;     for (auto i : v[x])       if (!vis[i]) dfs(i);   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     long long i, n, m, s = 0;     cin >> n >> m;     for (i = 1; i <= m; i++) {       long long a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     for (i = 1; i <= n; i++) {       if (!vis[i]) {         c = 0;         dfs(i);         s += (c - 1);       }     }     cout << m - s;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int INF = 0x3f3f3f3f;   int n, h, m, k;   pair<int, int> arr[maxn];   vector<int> out;   int calc(int l, int r, int s) {     if (l <= r) {       int low = lower_bound(arr + 1, arr + 1 + n, make_pair(l, 0)) - arr;       int up = upper_bound(arr + 1, arr + 1 + n, make_pair(r, INF)) - arr;       --up;       if (s) {         for (int i = low; i <= up; i++) out.emplace_back(arr[i].second);       }       return max(0, up - low + 1);     }     swap(l, r);     int low = upper_bound(arr + 1, arr + 1 + n, make_pair(l, INF)) - arr;     --low;     if (s) {       for (int i = 1; i <= low; i++) out.emplace_back(arr[i].second);     }     int up = lower_bound(arr + 1, arr + 1 + n, make_pair(r, 0)) - arr;     if (s) {       for (int i = up; i <= n; i++) out.emplace_back(arr[i].second);     }     return low + (n - up + 1);   }   int solve(int t, int s) {     t = (t + m) % m;     int s1 = t;     int t1 = (s1 + k - 1) % m;     int s2 = (t + m / 2) % m;     int t2 = (s2 + k - 1) % m;     return calc(s1, t1, s) + calc(s2, t2, s);   }   int main() {     scanf( %d%d%d%d , &n, &h, &m, &k);     --k;     for (int i = 1; i <= n; i++) {       int h;       scanf( %d%d , &h, &arr[i].first);       arr[i].second = i;     }     if (k == 0) {       printf( 0 0 n );       return 0;     }     sort(arr + 1, arr + 1 + n);     int ans = INF;     int t = 0;     for (int i = 1; i <= n; i++) {       int nt = arr[i].first + 1;       int ncnt = solve(nt, 0);       if (ncnt < ans) {         ans = ncnt;         t = arr[i].first + k + 1;       }       nt = arr[i].first - k;       ncnt = solve(nt, 0);       if (ncnt < ans) {         ans = ncnt;         t = arr[i].first;       }     }     printf( %d %d n , ans, t % (m / 2));     solve(t - k, 1);     int lens = out.size();     for (int i = 0; i < lens; i++)       printf( %d%c , out[i], i == lens - 1 ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[100005], t, n, d;   signed main() {     cin >> t;     while (t--) {       scanf( %d , &n);       int sum = ans[0] = 1;       for (int i = 1; i <= n; ++i) {         if (sum + (1 << (i + 1)) > n) {           d = i;           break;         }         sum += (1 << i);         ans[i] = (1 << i);       }       if (n - sum <= (1 << d)) {         ans[d] = n - sum;       } else {         ans[d] = (n - sum) / 2;         ans[d + 1] = n - sum - ans[d];         d++;       }       printf( %d n , d);       for (int i = 1; i < d; ++i) {         printf( %d  , ans[i] - ans[i - 1]);       }       printf( %d n , ans[d] - ans[d - 1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = int(1e9);   const double EPS = 1e-5;   const long long mod = ((long long)1e18) - 131;   int n, m, ans = 0;   set<string> h;   string s;   int main() {     cin >> s;     for (int i = 0; i < s.length(); i++)       for (int j = i; j < s.length(); j++) {         if (h.count(s.substr(i, j - i + 1)))           ans = max(ans, j - i + 1);         else           h.insert(s.substr(i, j - i + 1));       }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (b != 0) {       long long c = a % b;       a = b;       b = c;     }     return a;   }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   bool C() {     long long n, k;     cin >> n >> k;     long long lcmk = 1;     for (long long i = 1; i <= k; ++i) {       lcmk = lcm(lcmk, i);       if (lcmk > n + 1) return false;     }     if ((n + 1) % lcmk == 0)       return true;     else       return false;   }   int main() {     if (C())       cout <<  Yes ;     else       cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1e6 + 5;   class Tree {    public:     int son1, son2;     int val;     int op;     bool rev;     vector<int> v;   } tree[maxn];   int degree[maxn];   queue<int> q;   void dfs(int id) {     tree[id].rev = 1;     if (tree[id].op == 5) return;     if (tree[id].op == 1) {       if (tree[tree[id].son1].val) dfs(tree[id].son2);       if (tree[tree[id].son2].val) dfs(tree[id].son1);     }     if (tree[id].op == 2) {       if (!tree[tree[id].son1].val) dfs(tree[id].son2);       if (!tree[tree[id].son2].val) dfs(tree[id].son1);     }     if (tree[id].op == 3) {       dfs(tree[id].son1);       dfs(tree[id].son2);     }     if (tree[id].op == 4) {       dfs(tree[id].son1);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       tree[i].rev = 0;       string s;       cin >> s;       if (s ==  AND ) {         tree[i].op = 1;         cin >> tree[i].son1 >> tree[i].son2;         tree[tree[i].son1].v.push_back(i);         tree[tree[i].son2].v.push_back(i);         degree[i] = 2;       } else if (s ==  OR ) {         tree[i].op = 2;         cin >> tree[i].son1 >> tree[i].son2;         tree[tree[i].son1].v.push_back(i);         tree[tree[i].son2].v.push_back(i);         degree[i] = 2;       } else if (s ==  XOR ) {         tree[i].op = 3;         cin >> tree[i].son1 >> tree[i].son2;         tree[tree[i].son1].v.push_back(i);         tree[tree[i].son2].v.push_back(i);         degree[i] = 2;       } else if (s ==  NOT ) {         tree[i].op = 4;         cin >> tree[i].son1;         tree[tree[i].son1].v.push_back(i);         degree[i] = 1;       } else if (s ==  IN ) {         tree[i].op = 5;         cin >> tree[i].val;         q.push(i);       }     }     int root;     while (!q.empty()) {       int id = q.front();       root = id;       q.pop();       for (int i = 0; i < tree[id].v.size(); i++) {         degree[tree[id].v[i]]--;         if (!degree[tree[id].v[i]]) q.push(tree[id].v[i]);       }       if (tree[id].op == 5)         continue;       else if (tree[id].op == 1) {         tree[id].val = (tree[tree[id].son1].val && tree[tree[id].son2].val);       } else if (tree[id].op == 2) {         tree[id].val = (tree[tree[id].son1].val || tree[tree[id].son2].val);       } else if (tree[id].op == 3) {         tree[id].val = (tree[tree[id].son1].val ^ tree[tree[id].son2].val);       } else if (tree[id].op == 4) {         tree[id].val = !tree[tree[id].son1].val;       }     }     dfs(root);     for (int i = 1; i <= n; i++)       if (tree[i].op == 5) {         if (tree[i].rev)           cout << !tree[root].val;         else           cout << tree[root].val;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, N = 1e5 + 10;   template <class T>   inline bool chkmin(T &A, T B) {     return B < A ? A = B, 1 : 0;   }   template <class T>   inline bool chkmax(T &A, T B) {     return A < B ? A = B, 1 : 0;   }   int n, m, A[N], cnt[N], L = 1, R, cur;   long long tot, dp[2][N];   void get(int l, int r) {     while (l < L) tot += cnt[A[--L]]++;     while (R < r) tot += cnt[A[++R]]++;     while (L < l) tot -= --cnt[A[L++]];     while (r < R) tot -= --cnt[A[R--]];   }   void Solve(int l, int r, int lim1, int lim2) {     if (l > r) return;     int mid = (l + r) >> 1, t = l;     for (int i = (lim1), i_end = (min(lim2, mid)); i <= i_end; ++i) {       get(i, mid);       if (chkmin(dp[!cur][mid], dp[cur][i - 1] + tot)) t = i;     }     Solve(l, mid - 1, lim1, t);     Solve(mid + 1, r, t, lim2);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (1), i_end = (n); i <= i_end; ++i) {       scanf( %d , &A[i]);       get(1, i);       dp[0][i] = tot;     }     for (int i = (2), i_end = (m); i <= i_end; ++i) {       memset(dp[!cur], 63, sizeof(dp[!cur]));       Solve(1, n, 1, n);       cur = !cur;     }     printf( %lld n , dp[cur][n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int getid(string s) {     int len = ((int)(s).size()), id = 0;     if (len > 19) return -1;     for (int j = 0; j < len; j++) id = id * 2 + s[j] -  0 ;     return id + (1 << len) - 2;   }   int n, m, u, v;   char s[110];   string t;   struct blk {     string bg, ed;     bitset<1048576> S;     bool full;     void add(string s) {       int m = ((int)(s).size());       for (int j = 0; j < m; j++)         for (int k = j; k < m; k++) {           string f = s.substr(j, k - j + 1);           int id = getid(f);           if (id == -1) continue;           S[id] = 1;         }     }     void simply() {       if (((int)(bg).size()) > 20) {         bg = bg.substr(0, 20);         full = 0;       }       if (((int)(ed).size()) > 20) {         ed = ed.substr(((int)(ed).size()) - 20, 20);         full = 0;       }     }     int query() {       for (int i = 20 - 1; i >= 1; i--) {         int d = (1 << i) - 2, val = 1;         for (int j = 0; j < (1 << i); j++) {           if (!S[d + j]) {             val = 0;             break;           }         }         if (val) return i;       }       return 0;     }   } b[210];   void gao(int p, int u, int v) {     b[p].S = b[u].S | b[v].S;     if (b[u].full)       b[p].bg = b[u].bg + b[v].bg, b[p].full = 1;     else       b[p].bg = b[u].bg;     if (b[v].full)       b[p].ed = b[u].ed + b[v].ed, b[p].full = 1;     else       b[p].ed = b[v].ed;     b[p].add(b[u].ed + b[v].bg);     b[p].simply();   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , s);       t = s;       b[i].add(t);       b[i].bg = t;       b[i].ed = t;       b[i].full = 1;       b[i].simply();     }     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       gao(n + i, u - 1, v - 1);       printf( %d n , b[n + i].query());     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 51;   const long long mod = 1e9 + 7;   int n, k, n1 = 0, n2 = 0;   long long dp[202][N][N][2], C[N][N];   int main() {     int x;     scanf( %d%d , &n, &k);     k /= 50;     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       if (x == 50)         n1++;       else         n2++;     }     for (int i = 0; i <= n; i++) C[i][0] = 1, C[i][i] = 1;     for (int i = 2; i <= n; i++)       for (int j = 1; j < i; j++) {         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;       }     dp[0][n1][n2][0] = 1;     for (int st = 0; st <= 200; st++) {       if (dp[st][0][0][1]) {         printf( %d n%I64d n , st, dp[st][0][0][1]);         return 0;       }       for (int a1 = 0; a1 <= n1; a1++) {         for (int a2 = 0; a2 <= n2; a2++) {           if (dp[st][a1][a2][0]) {             for (int u = 0; u <= a1; u++) {               if (u > k) break;               for (int v = 0; v <= a2; v++) {                 if (u + v * 2 > k) break;                 if (u + v == 0) continue;                 dp[st + 1][a1 - u][a2 - v][1] +=                     (C[a2][v] * (dp[st][a1][a2][0] * C[a1][u]) % mod) % mod;                 dp[st + 1][a1 - u][a2 - v][1] %= mod;               }             }           }           if (dp[st][a1][a2][1]) {             for (int u = 0; u <= n1 - a1; u++) {               if (u > k) break;               for (int v = 0; v <= n2 - a2; v++) {                 if (u + v * 2 > k) break;                 if (u + v == 0) continue;                 dp[st + 1][a1 + u][a2 + v][0] +=                     (C[n2 - a2][v] * (dp[st][a1][a2][1] * C[n1 - a1][u]) % mod) %                     mod;                 dp[st + 1][a1 + u][a2 + v][0] %= mod;               }             }           }         }       }     }     printf( -1 n0 n );     return 0;   }
#include <bits/stdc++.h>   int main() {     int i, j, l, flag;     char arr[1000100], arr2[1000100];     gets(arr);     l = strlen(arr);     for (flag = 0, j = 0, i = 0; i < l - 1; i++) {       if (arr[i] ==  0  && flag == 0) {         flag = 1;         continue;       } else         arr2[j++] = arr[i];     }     if (flag == 1) arr2[j++] = arr[l - 1];     printf( %s n , arr2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1e9;   const long long LINF = INF * (long long)INF + 100;   const double EPS = 1e-7;   const int MAX = 20 * 1000 + 47;   const int MAS = 2 * 1e5 + 10;   const int MOD = 998244353;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<string> s(n);       for (int i = (0); i < (n); i++) {         cin >> s[i];       }       vector<vector<int>> g(n);       vector<string> s1(n);       vector<vector<int>> p(n * m, vector<int>(21));       for (int i = (0); i < (n); i++) {         cin >> s1[i];         for (int j = (0); j < (m); j++) {           int num = i * m + j;           if (s1[i][j] ==  R ) {             p[num][0] = num + 1;           }           if (s1[i][j] ==  L ) {             p[num][0] = num - 1;           }           if (s1[i][j] ==  U ) {             p[num][0] = num - m;           }           if (s1[i][j] ==  D ) {             p[num][0] = num + m;           }         }       }       for (int k = (1); k < (21); k++) {         for (int i = (0); i < (n * m); i++) {           p[i][k] = p[p[i][k - 1]][k - 1];         }       }       set<int> all;       set<int> black;       for (int i = (0); i < (n); i++)         for (int j = (0); j < (m); j++) {           int num = (i * m + j);           int p1 = p[num][20];           all.insert(p1);           if (s[i][j] ==  0 ) {             black.insert(p1);           }         }       cout << all.size() <<     << black.size() << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   namespace Flandre_Scarlet {   int I() {     char c = getchar();     int x = 0;     int f = 1;     while (c <  0  or c >  9 ) f = (c ==  - ) ? -1 : 1, c = getchar();     while (c >=  0  and c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return (x = (f == 1) ? x : -x);   }   template <typename T>   void Rd(T& arg) {     arg = I();   }   template <typename T, typename... Types>   void Rd(T& arg, Types&... args) {     arg = I();     Rd(args...);   }   void RA(int* p, int n) {     for (int i = 1; i <= n; ++i) *p = I(), ++p;   }   int n, a[200005];   void Input() {     n = I();     RA(a + 1, n);   }   int st[200005][18];   short lg[200005];   inline int gcd(int a, int b) {     while (b) {       a ^= b ^= a ^= b;       b %= a;     }     return a;   }   void SparseTable() {     memset(lg, -1, sizeof(lg));     for (int i = 0; i <= 17; ++i)       if ((1 << i) <= n) lg[1 << i] = i;     for (int i = 1; i <= n; ++i)       if (lg[i] == -1) lg[i] = lg[i - 1];     for (int i = 1; i <= n; ++i) st[i][0] = a[i];     for (int j = 1; j <= 17; ++j) {       for (int i = 1; i <= n; ++i)         st[i][j] = gcd(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);     }   }   inline int Query(int l, int r) {     int k = lg[r - l + 1];     return gcd(st[l][k], st[r - (1 << k) + 1][k]);   }   unordered_map<int, long long> ans;   int GetNex(int l, int g) {     if (Query(l, n) == g) return n + 1;     int cur = l;     for (int i = 17; i >= 0; --i)       if (st[cur][i] % g == 0) cur = cur + (1 << i);     return cur;   }   void Soviet() {     SparseTable();     for (int i = n; i >= 1; --i) {       int g = a[i];       for (register int l = i, r; l <= n; l = r) {         r = GetNex(i, g);         ans[g] += r - l;         if (r == n + 1) break;         g = gcd(g, a[r]);       }     }     int q = I();     for (int i = 1; i <= q; ++i) printf( %lld n , ans[I()]);   }   void IsMyWife() {     Input();     Soviet();   }   }  // namespace Flandre_Scarlet   int main() {     Flandre_Scarlet::IsMyWife();     getchar();     return 0;   }