#include using namespace std; int main() { int N; cin>>N; vector a(N); for(int i=0;i>a[i]; } priority_queue Q; int S=0; for(int i=0;i>q; while(q--){ int x; cin>>x; while(Q.top()>=x){ int t=Q.top(); Q.pop(); S-=t-t%x; Q.push(t%x); } cout<