#define _USE_MATH_DEFINES #include using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; long long sum = 0; priority_queue que; for (int i = 0; i < n; i++) { int a; cin >> a; que.push(a); sum += a; } int q; cin >> q; for (int i = 0; i < q; i++) { int x; cin >> x; while (que.top() >= x) { int cur = que.top(); que.pop(); sum = sum - cur + cur % x; que.push(cur % x); } cout << sum << '\n'; } return 0; }