#include using namespace std; #define rep(i,l,r)for(int i=(l);i<(r);i++) using ll=long long; int main(){ mapdp; int n; cin >> n; vectora(n); for(auto&x:a)cin >> x; int q; cin >> q; ll start=0; ll len=0; vectorseg; while(q--){ ll a,b; cin >> a >> b; if(a<=start+len){ len+=b; }else{ if(len)seg.push_back(len); start=a; len=b; } } if(len)seg.push_back(len); for(auto N:seg){ for(ll L=1,R;L<=N;L=R){ ll q=N/L; R=N/q+1; dp[L]+=q; dp[R]-=q; } } vector>temp; ll crr=0; for(auto[k,v]:dp){ crr+=v; temp.push_back({k,crr}); } for(auto x:a){ auto it=lower_bound(temp.begin(),temp.end(),make_pair((ll)x,(ll)1e18)); cout << (prev(it)->second) << '\n'; } }