#include #include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define ll long long #define ld long double #define INF 1000000000000000000 typedef pair pll; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector A(N); rep(i, N) { cin >> A[i]; } ll X = 0; map ma1, ma2; ll cnt = 0, e = 0; bool judge = 0; vector v, vv; while (1) { ll r = X % N; if (ma1[A[r]]) { judge = 1; } if (ma2[A[r]]) { break; } if (!judge) ma1[A[r]] = true, v.push_back(A[r]); if (judge) ma2[A[r]] = true, vv.push_back(A[r]); X += A[r]; } rep(i, v.size() - 1) { v[i + 1] += v[i]; } rep(i, vv.size()) { vv[i + 1] += vv[i]; } int Q; cin >> Q; rep(i, Q) { ll q; cin >> q; q--; if (q < (ll)v.size()) { cout << v[q] << endl; } else { ll ans = v.back(); q -= v.size(); ans += (q / vv.size()) * vv.back() + vv[q % (ll)vv.size()]; cout << ans << endl; } } }