#include using namespace std; int main(){ int N; cin >> N; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } 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; long long CS = X[l + c] - X[l]; for (int i = 0; i < Q; i++){ long long K; cin >> K; if (K <= l){ cout << X[K] << endl; } else { cout << X[l] + (K - l) / c * CS + X[l + (K - l) % c] - X[l] << endl; } } }