#include #include #include using namespace std; int N; int A[1<<17],X[1<<17]; long sum[1<<17]; main() { cin>>N; for(int i=0;i>A[i]; int Q;cin>>Q; for(int i=0;i>X[i]; vector >Y; Y.push_back(make_pair(X[0],0)); for(int i=1;i >::iterator it= upper_bound(Y.begin(),Y.end(),make_pair(now,Q)); if(it==Y.begin())break; it--; sum[it->second]-=now-now%it->first; now%=it->first; } } for(int i=0;i