#include using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int main() { int N; cin >> N; LL sum = 0; priority_queue G; rep(i, N) { int a; cin >> a; G.push(a); sum += a; } int Q; cin >> Q; while (Q--) { int x; cin >> x; while (G.top() >= x) { int p = G.top(); G.pop(); sum -= p; p %= x; G.push(p); sum += p; } cout << sum << endl; } return 0; }