#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; priority_queue pq; ll sum = 0; rep(i,n){ ll p; cin >> p; pq.push(p); sum += p; } ll mn = LINF; int q; cin >> q; rep(i,q){ ll x; cin >> x; if(mn <= x){ cout << sum << '\n'; continue; } mn = x; int c = 0; while(c < n){ ll now = pq.top(); if(now < x) break; pq.pop(); sum -= now; now %= x; sum += now; pq.push(now); ++c; } cout << sum << '\n'; } return 0; }