#include using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; ll sum = 0; mapm; vectorv(n); for (ll i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; m[v[i]]++; } ll q; cin >> q; sets; for (auto k : m) { s.insert(k.first); } ll ans = 0; for (ll i = 0; i < q; i++) { ll x; cin >> x; while (*s.rbegin() >= x) { ll aftermod = (*s.rbegin() % x); ll cnt = m[*s.rbegin()]; sum -= (*s.rbegin() - aftermod) * cnt; m[*s.rbegin()] = 0; s.erase(*s.rbegin()); s.insert(aftermod); m[aftermod] += cnt; } cout << sum << endl; } }