#include #define rep(i,n) for (int i = 0; i < (int)(n); i ++) #define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i) using namespace std; using ll = long long; using PL = pair; using P = pair; constexpr int INF = 1000000000; constexpr long long HINF = 1000000000000000; constexpr long long MOD = 1000000007;// = 998244353; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; vector A(N); rep(i,N) cin >> A[i]; int now = 0; vector visited(N,0); vector route; while (visited[now] == 0) { visited[now] = 1; route.push_back(now); now = (now + A[now])%N; } vector before,loop; ll before_size,loop_size; ll sumbefore = 0,sumloop = 0; bool flag = false; rep(i,route.size()) { if (route[i] == now) flag = true; if (flag) { loop.push_back(A[route[i]]); sumloop += A[route[i]]; } else { before.push_back(A[route[i]]); sumbefore += A[route[i]]; } } before_size = before.size(); loop_size = loop.size(); rep(i,before_size - 1) before[i + 1] += before[i]; rep(i,loop_size - 1) loop[i + 1] += loop[i]; int Q; cin >> Q; rep(i,Q) { ll K; cin >> K; if (K <= before_size) cout << before[K - 1] << '\n'; else { ll ret = sumbefore; K -= before_size; ret += K/loop_size * sumloop; if (K%loop_size > 0) ret += loop[K%loop_size - 1]; cout << ret << '\n'; } } return 0; }