#include "bits/stdc++.h" using namespace std; void solve() { int n, q; cin >> n; priority_queue pq; long ans = 0; while (n--) { int a; cin >> a; ans += a; pq.push(a); } cin >> q; while (q--) { int x; cin >> x; while (pq.top() >= x) { int y = pq.top(); ans -= y; pq.push(y % x); pq.pop(); ans += y % x; } cout << ans << '\n'; } } int main() { solve(); return 0; }