#include using namespace std; using ll = long long; #define FOR(i, m, n) for (int i = (m); i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define REP1(i, n) FOR(i, 1, (n) + 1) #define ALL(c) (c).begin(), (c).end() template inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} const int MOD = 1000000007; int main() { int n; cin >> n; map m; ll t = 0; ll a; REP(i, n) { cin >> a; t += a; m[a]++; } int q; cin >> q; ll x; REP(i, q) { ll s = t; vector r; cin >> x; for (auto itr = m.rbegin(); itr != m.rend(); itr++) { if (itr->first >= x) { ll y = itr->first % x; if (y == 0) { s -= itr->first * itr->second; } else { s -= (itr->first - y) * itr->second; m[y] += itr->second; } r.push_back(itr->first); } else { break; } } cout << s << endl; t = s; for (auto z : r) { m.erase(z); } } }