#include #define all(x) (x).begin(), (x).end() typedef long long ll; #define MOD 1000000007 using namespace std; int main() { int n; cin >> n; vector a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } vector> dub(60, vector(n, 0)); vector> sum(60, vector(n, 0)); for(int i = 0; i < n; i++) { dub[0][i] = (i + a[i]) % n; sum[0][i] = a[i]; } for(int i = 1; i < 60; i++) { for(int j = 0; j < n; j++) { dub[i][j] = dub[i - 1][dub[i - 1][j]]; sum[i][j] = sum[i - 1][j] + sum[i - 1][dub[i - 1][j]]; } } int q; cin >> q; while(q--) { ll k; cin >> k; ll res = 0; int now = 0; int i = 0; while(k) { if(k % 2) { res += sum[i][now]; now = dub[i][now]; } k /= 2; i++; } cout << res << endl; } }