#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for(ll i=0; i < (n); i++) #define rrep(i, n) for(ll i=(n)-1; i >=0; i--) #define ALL(v) v.begin(),v.end() #define rALL(v) v.rbegin(),v.rend() #define FOR(i, j, k) for(ll i=j;i llvec; typedef vector dvec; typedef pair P; typedef long double ld; struct edge{ll x, c;}; /************************************** ** A main function starts from here ** ***************************************/ int main(){ ll N; cin >> N; llvec A(N); rep(i, N)cin >> A[i]; vector> p(N, vector

(40)); rep(i, N){ p[i][0] = {(i+A[i])%N, (i+A[i])/N}; } rep(k, 39){ rep(i, N){ auto ip = p[i][k]; ll prev = ip.fi; ll s = ip.se; p[i][k+1] = {p[prev][k].fi, s + p[prev][k].se}; } } ll Q; cin >> Q; while(Q--){ ll K; cin >> K; ll cur = 0; ll r = 0; rep(k, 40){ if(K>>k&1){ r += p[cur][k].se; cur = p[cur][k].fi; // cerr << "\t" << cur << " " << r << endl; } //K>>1; } cout << cur + r*N<