// ※※※ 解答不能 ※※※ // 正答者のソースを勉強する. // QCFium氏 // https://yukicoder.me/submissions/353962 #include using namespace std; using LL = long long; int main(){ int n; scanf("%d", &n); priority_queue que; LL sum = 0; for(int i = 0; i < n; i++){ LL a; scanf("%lld", &a); sum += a; que.push(a); } int q; scanf("%d", &q); for(int i = 0; i < q; i++){ LL x; scanf("%lld", &x); int t; while((t = que.top()) >= x) sum -= t - t % x, que.pop(), que.push(t % x); printf("%lld\n", sum); } return 0; }