#include #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; int main() { int N; cin >> N; vector A(N); REP(i, 0, N) cin >> A[i]; vector> next(60, vector(N)); vector> total(60, vector(N)); REP(i, 0, N) { next[0][i] = (i + A[i]) % N; total[0][i] = A[i]; } REP(i, 1, 60) { REP(j, 0, N) { next[i][j] = next[i - 1][next[i - 1][j]]; total[i][j] = total[i - 1][j] + total[i - 1][next[i - 1][j]]; } } int Q; cin >> Q; while (Q--) { ll k; cin >> k; ll ans = 0; int cur = 0; for (int i = 59; i >= 0; i--) { if (k & (1LL << i)) { ans += total[i][cur]; cur = next[i][cur]; } } cout << ans << endl; } return 0; }