func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 10;   long long n, m;   long long res[N], sum[N], a[N];   long long len;   struct Node {     int x, p, id;   } Q[N];   inline long long read() {     long long x = 0, f = 0;     char ch;     while (((ch = getchar()) <  0  || ch >  9 ) && (ch !=  - ))       ;     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();     return f ? -x : x;   }   inline bool cmp(Node a, Node b) { return a.p != b.p ? a.p < b.p : a.x > b.x; }   signed main() {     n = read();     len = sqrt(n);     for (long long i = 1; i <= n; i++) a[i] = read();     m = read();     for (int i = 1; i <= m; i++) {       long long x, p;       x = read(), p = read();       Q[i].x = x, Q[i].p = p;       Q[i].id = i;     }     sort(Q + 1, Q + m + 1, cmp);     int last = n;     for (int i = 1; i <= m; i++) {       long long ans = 0;       if (Q[i].p >= len) {         for (int j = Q[i].x; j <= n; j += Q[i].p) {           ans += a[j];         }       } else {         int p = Q[i].p, x = Q[i].x;         if (Q[i].p != Q[i - 1].p) last = n;         for (int j = last; j >= x; j--) {           sum[j] = a[j];           if (j + p <= n) sum[j] += sum[j + p];         }         last = x - 1;         ans = sum[x];       }       res[Q[i].id] = ans;     }     for (int i = 1; i <= m; i++) printf( %lld n , res[i]);     return 0;   }   