#include #include #include #include #include #include #include #include using namespace std; using ll = long long; using vi = vector; #define in(v) v; cin >> v; void ins() {} templatevoid ins(T& v,Rest&... rest){cin>>v;ins(rest...);} #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) #define rrep(i,n) for(long long i=(n);i>=0;--i) #define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c)) // ========== debug ========== templateostream& operator<<(ostream& os,const vector& vec){os<<"{";for(size_t i=0;i&v){for(size_t i=0;iostream& operator<<(ostream& os,const pair& rhs){os<<"("< void debug(const First& first) {cerr< void debug(const First& first, const Rest&... rest) {cerr< void debug2(const First& first) {cerr< void debug2(const First& first, const Rest&... rest) {cerr<> N; vi A(N); rep(i, N) { cin >> A[i]; } int Q; cin >> Q; ll sum = 0; vector X; set st; int margin, period; rep(i, 2*N) { if (st.find(sum % N) != st.end()) { X.push_back(sum); rep(j, X.size()) { if (X[j] % N == sum % N) { margin = j; period = i - j; break; } } break; } st.insert(sum % N); X.push_back(sum); sum += A[sum % N]; } debug(X, margin, period); rep(i, Q) { ll k; cin >> k; if (k < X.size()) { cout << X[k] << endl; continue; } ll ans = X[margin]; ans += (X.back() - X[margin]) * ((k - margin) / period); ans += X[(k - margin) % period + margin] - X[margin]; cout << ans << endl; } return 0; }