#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a>m>>n>>mulX>>addX>>mulY>>addY>>MOD; vector xs(m),ys(m),as(m),bs(m); for(int i=0;i>xs[i]; for(int i=0;i>ys[i]; for(int i=0;i>as[i]; for(int i=0;i>bs[i]; for(int i=0;i0;j-=i) zs[j/i]+=zs[j]; } ll sum=0; for(int i=0;i