#include using namespace std; int MAX_N = 100000; int MAX_A = 1000000; int MAX_Q = 100000; long long MAX_K = 1000000000000; int main(){ int N; cin >> N; assert(1 <= N); assert(N <= MAX_N); vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; assert(0 <= A[i]); assert(A[i] <= MAX_A); } vector B(N); for (int i = 0; i < N; i++){ B[i] = (i + A[i]) % N; } vector ord(N, -1); vector S(1, 0); int c = 0; int l = 0; int curr = 0; while (1){ if (ord[curr] == -1){ ord[curr] = S.size() - 1; S.push_back(S.back() + A[curr]); curr = B[curr]; } else { c = S.size() - ord[curr] - 1; l = ord[curr]; break; } } int Q; cin >> Q; assert(1 <= Q); assert(Q <= MAX_Q); long long CS = S[l + c] - S[l]; for (int i = 0; i < Q; i++){ long long K; cin >> K; assert(1 <= K); assert(K <= MAX_K); if (K <= l){ cout << S[K] << endl; } else { cout << S[l] + (K - l) / c * CS + S[l + (K - l) % c] - S[l] << endl; } } }