#include #include #include #include #include #include using namespace std; typedef long long int ll; int to[50][100100]; ll sum[50][100100]; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); for(int i=0;i> a[i]; to[0][i]=(i+a[i])%n; sum[0][i]=a[i]; } for(int i=0;i<49;i++){ for(int j=0;j> q; while(q--){ ll k; cin >> k; int now=0; ll res=0; for(int i=49;i>=0;i--){ if((k>>i)&1){ res+=sum[i][now]; now=to[i][now]; } } cout << res << endl; } }