typedef long long ll; #include using namespace std; int main() { ll n; std::cin >> n; priority_queue pq; ll sum = 0; for (int i = 0; i < n; i++) { ll tmp; std::cin >> tmp; sum += tmp; pq.push(tmp); } ll q; std::cin >> q; for (int i = 0; i < q; i++) { ll tmp; std::cin >> tmp; while(pq.top()>=tmp){ auto now = pq.top();pq.pop(); sum -= now-now%tmp; pq.push(now%tmp); } std::cout << sum << std::endl; } }