#include #define REP(i,n) for(int i=0,i##_len=(n);i>N; vector A(N); ll S=0; priority_queue que; REP(i,N){ cin>>A[i]; S+=A[i]; que.push(A[i]); } int Q;cin>>Q; REP(i,Q){ ll X;cin>>X; while(que.top()>=X){ ll K=que.top();que.pop(); S-=K-K%X; K%=X; que.push(K); } cout<