#include #include int ri() { int n; std::cin >> n; return n; } int main() { int n = ri(); std::priority_queue que; long long sum = 0; for (int i = 0; i < n; i++) { int a = ri(); sum += a; que.push(a); } int q = ri(); for (int i = 0; i < q; i++) { int x = ri(); int t; while ((t = que.top()) >= x) sum -= t - t % x, que.pop(), que.push(t % x); printf("%lld\n", sum); } return 0; }