#include using namespace std; typedef long long ll; typedef pair P; #define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) int main() { int n,q; cin >> n; vector a(n); for (int i = 0;i < n;++i) cin >> a[i]; cin >> q; vector ans(q,0); vector

b; int mx = INT_MAX; for (int i = 0;i < q;++i) { int x; cin >> x; if (x < mx) { b.push_back(P(-x,i)); mx = x; } } for (int i = 0;i < n;++i) { ans[0] += a[i]; while (1) { int j = lower_bound(b.begin(),b.end(),P(-a[i],0))-b.begin(); if (j == b.size()) break; ans[b[j].second] -= a[i]/(-b[j].first)*(-b[j].first); a[i] %= -b[j].first; } } for (int i = 1;i < q;++i) ans[i] += ans[i-1]; for (int i = 0;i < q;++i) cout << ans[i] << "\n"; }