func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 700000;   int n, g, r;   int l[MAXN];   long long sum[MAXN];   long long d[MAXN];   long long cycle;   int m;   long long q[MAXN], code[MAXN];   int minv[MAXN];   void build(int l, int r, int v) {     minv[v] = n + 1;     if (l != r)       build(l, (l + r) >> 1, v << 1), build(((l + r) >> 1) + 1, r, (v << 1) + 1);   }   void change(int p, int l, int r, int v, int x) {     if (l > p || r < p) return;     minv[v] = x;     if (l != r)       change(p, l, (l + r) >> 1, v << 1, x),           change(p, ((l + r) >> 1) + 1, r, (v << 1) + 1, x);   }   int getmin(int L, int R, int l, int r, int v) {     if (L > r || l > R) return n + 1;     if (L <= l && r <= R) return minv[v];     return min(getmin(L, R, l, (l + r) >> 1, v << 1),                getmin(L, R, ((l + r) >> 1) + 1, r, (v << 1) + 1));   }   int process(int u, int curt) {     assert(curt < g);     int l, r;     l = g - curt;     r = cycle - 1 - curt;     l = (1LL * l + code[u]) % cycle;     r = (1LL * r + code[u]) % cycle;     int p1, p2;     p1 = lower_bound(q, q + m, l) - q;     p2 = lower_bound(q, q + m, r + 1) - q - 1;     if (l <= r) {       if (p1 > p2) return n + 1;       return getmin(p1, p2, 0, m - 1, 1);     }     int ret = n + 1;     if (p1 < m) ret = min(ret, getmin(p1, m - 1, 0, m - 1, 1));     assert(p2 >= 0);     ret = min(ret, getmin(0, p2, 0, m - 1, 1));     return ret;   }   int main() {     scanf( %d%d%d , &n, &g, &r);     cycle = g + r;     for (int i = 0; i <= n; i++) scanf( %d , l + i);     for (int i = 1; i <= n + 1; i++) sum[i] = sum[i - 1] + l[i - 1];     for (int i = 1; i <= n + 1; i++) code[i] = sum[i] % cycle;     for (int i = 0; i <= n + 1; i++) q[m++] = code[i];     sort(q, q + m);     m = unique(q, q + m) - q;     build(0, m - 1, 1);     for (int i = n, pos; i > 1; i--) {       pos = process(i, 0);       assert(pos == n + 1 || (sum[pos] - sum[i]) % cycle >= g);       assert(pos > i);       d[i] = d[pos] + sum[pos] - sum[i];       if (pos != n + 1) d[i] += cycle - (sum[pos] - sum[i]) % cycle;       change(lower_bound(q, q + m, code[i]) - q, 0, m - 1, 1, i);     }     int test_num;     scanf( %d , &test_num);     for (int pos; test_num--;) {       long long tim;       scanf( %I64d , &tim);       tim += sum[1];       if (tim % cycle >= g) tim += cycle - tim % cycle;       pos = process(1, tim % cycle);       assert(pos);       assert((sum[pos] - sum[1] + tim) % cycle >= g || pos == n + 1);       long long res = d[pos] + sum[pos] - sum[1] + tim;       if (pos != n + 1) res += cycle - (sum[pos] - sum[1] + tim) % cycle;       printf( %I64d n , res);     }     return 0;   }   