#include #include #include #include #include #include #include using namespace std; typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int N, Q; cin >> N; priority_queue que; ll sum = 0; for(int i = 0; i < N; i++){ ll a; cin >> a; sum += a; que.push(a); } cin >> Q; for(int i = 0; i < Q; i++){ int x; cin >> x; while(que.top() >= x){ ll t = que.top(); que.pop(); sum -= t; t %= x; sum += t; que.push(t); } cout << sum << endl; } }