#define _USE_MATH_DEFINES #include using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector> nxt(41, vector(n)); vector> sum(41, vector(n)); for (int i = 0; i < n; i++) { nxt[0][i] = (i + a[i]) % n; sum[0][i] = a[i]; } for (int u = 1; u < 41; u++) { for (int i = 0; i < n; i++) { nxt[u][i] = nxt[u - 1][nxt[u - 1][i]]; sum[u][i] = sum[u - 1][i] + sum[u - 1][nxt[u - 1][i]]; } } int q; cin >> q; while (q--) { long long k; cin >> k; long long ans = 0; int cur = 0; for (int i = 40; i >= 0; i--) { if (k >= (1LL << i)) { ans += sum[i][cur]; cur = nxt[i][cur]; k -= (1LL << i); } } cout << ans << '\n'; } return 0; }