#include using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) #define endl "\n" int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); ll n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; ll q; cin >> q; vector x(q); rep(i, q) cin >> x[i]; priority_queue pq; rep(i, n) pq.push(a[i]); ll sum = accumulate(all(a), 0LL); rep(i, q) { while((pq.top() >= x[i])) { ll v = pq.top(); pq.pop(); ll tmp = v % x[i]; pq.push(tmp); sum -= (v - tmp); } cout << sum << endl; } return 0; }