#include using namespace std; using ll = long long; #define all(A) A.begin(),A.end() using vll = vector; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) using Graph = vector>; ll mod=1e9+7; int main() { ll N; cin>>N; vll A(N); ll S=0; priority_queue Q; rep(i,N){ cin>>A[i]; S+=A[i]; Q.push(A[i]); } ll q; cin>>q; rep(i,q){ ll X; cin>>X; while(Q.top()>=X){ ll p=Q.top(); S-=p; Q.pop(); S+=p%X; Q.push(p%X); } cout<