#ifndef LOCAL #include using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif void solve() { int N; cin >> N; vector A(N); for(int i = 0; i < N; i++) cin >> A[i]; vector memo(N + 1); { int64_t x = 0; for(int i = 0; i < N; i++) { int r = x % N; x += A[r]; memo[i + 1] = x; } } int Q; cin >> Q; while(Q--) { int64_t K; cin >> K; int64_t q = K / N, r = K % N; int64_t ans = memo[N] * q + memo[r]; cout << ans << endl; } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while(tt--) { solve(); } }