#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(1 <= 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 X(1, 0); int c = 0; int l = 0; int curr = 0; while (1){ if (ord[curr] == -1){ ord[curr] = X.size() - 1; X.push_back(X.back() + A[curr]); curr = B[curr]; } else { c = X.size() - ord[curr] - 1; l = ord[curr]; break; } } int Q; cin >> Q; assert(1 <= Q); assert(Q <= MAX_Q); long long CS = X[l + c] - X[l]; for (int i = 0; i < Q; i++){ long long K; cin >> K; assert(1 <= K); assert(K <= MAX_K); if (K <= l){ cout << X[K] << endl; } else { cout << X[l] + (K - l) / c * CS + X[l + (K - l) % c] - X[l] << endl; } } }