#include #include #include using namespace std; int main(){ int N; cin >> N; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } long long ans = 0; for (int i = 0; i < N; i++){ ans += A[i]; } priority_queue pq; for (int i = 0; i < N; i++){ pq.push(A[i]); } int Q; cin >> Q; for (int i = 0; i < Q; i++){ int X; cin >> X; while (pq.top() >= X){ int t = pq.top(); pq.pop(); ans -= t - t % X; pq.push(t % X); } cout << ans << endl; } }