#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair P; typedef pair PP; const ll MOD=1e9+7; int main(){ int N,M; cin>>N>>M; vector L(N),R(N),X(N),Y(N); ll maxR=0; for(int i=0;i>L[i]>>R[i]>>X[i]>>Y[i]; maxR=max(1LL*R[i],maxR); } ll K=maxR+1; vector A(M); for(int i=0;i>A[i]; const ll T=max(1LL,(ll)sqrt(N)); const ll MAXA=100000+10; vector cnt(MAXA+1); vector> imos(T,vector(MAXA+1,0)); for(int i=0;i=T){ ll left=1LL*(L[i]-Y[i]+x-1)/x*x; for(ll t=left+y;t<=R[i];t+=X[i]){ cnt[t]++; } }else{ //x=0){ imos[x][v]+=imos[x][v-x]; } } } vector num(MAXA+1,0); for(int x=0;x ans(M); for(int i=0;i