#include using namespace std; #ifdef LOCAL #include "debug.h" #else #define DEBUG(...) #endif int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); for (auto&& e : a) cin >> e; vector dp(40, vector(n, 0LL)); for (int i = 0; i < n; ++i) { dp[0][i] = a[i]; } for (int k = 1; k < 40; ++k) { for (int i = 0; i < n; ++i) { dp[k][i] = dp[k - 1][i] + dp[k - 1][(i + dp[k - 1][i]) % n]; } DEBUG(dp[k - 1]); } int q; cin >> q; while (q--) { long long m; cin >> m; auto res = 0LL; int i = 0; for (int k = 0; k < 40; ++k) { if (m >> k & 1) { res += dp[k][i]; i = res % n; } } cout << res << '\n'; } }