#include #include #ifdef _WIN32 #define getchar_fast _getchar_nolock #else #define getchar_fast getchar_unlocked #endif int ri() { int r = 0, c, s = 0; for (;;) {c=getchar_fast(); if (c == '-') { s = 1; break; } if (c <= '9' && c >= '0') { r = c - '0'; break; } } for (;;) {c=getchar_fast(); if (c < '0' || c > '9') break; r = r * 10 + c - '0'; } if (s) r = -r; return r; } 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; }