#include #include #include using namespace std; int main(){ int n;cin>>n; vector A(n); for(int i = 0; n > i; i++){ cin>>A[i]; } vector pre; vector circle; set B; long long nw = 0; B.insert(nw); while(true){ nw = (nw+A[nw])%n; if(B.count(nw)){ break; } B.insert(nw); } long long nw2 = 0; while(nw2 != nw){ if(nw2)pre.push_back(pre[pre.size()-1]+A[nw2]); else pre.push_back(A[nw2]); nw2 = (nw2+A[nw2])%n; } circle.push_back(A[nw2]); nw2 = (nw2+A[nw2])%n; while(nw2 != nw){ circle.push_back(circle[circle.size()-1]+A[nw2]); nw2 = (nw2+A[nw2])%n; } int q;cin>>q; for(int i = 0; q > i; i++){ int x;cin>>x; if(pre.size() >= x){ cout << pre[x-1] << endl; }else{ long long ans = 0; if(pre.size())ans += pre[pre.size()-1]; ans += (x-pre.size())/circle.size()*circle[circle.size()-1]; if((x-pre.size())%circle.size() != 0)ans += circle[(x-pre.size()-1)%circle.size()]; cout << ans << endl; } } }