#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define ALL(v) (v).begin(), (v).end() using ll = long long; using P = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e18; constexpr long long MOD = 1e9 + 7; #define MAX 70 signed main() { int n; cin >> n; int a[n]; rep(i, n) { cin >> a[i]; } int q; cin >> q; ll k[q]; rep(i, q) { cin >> k[i]; } ll dp[MAX + 1][n]; rep(i, n) { dp[0][i] = a[i]; } for (int i = 0; i < MAX; i++) { for (int j = 0; j < n; j++) { dp[i + 1][j] = dp[i][(dp[i][j] + j) % n] + dp[i][j]; } } rep(i, q) { ll ans = 0; ll cur = 0; for (int j = 0; j < MAX; j++) { if (k[i] & (1LL << j)) { ans += dp[j][cur]; cur = dp[j][cur] % n; } } cout << ans << endl; } return 0; }