#include using namespace std; #define endl '\n' #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() #define spa << " " << #define lfs <= (ll)(m); i--) using ll = long long; using ld = long double; const ll MOD = 1e9+7; //const ll MOD = 998244353; const ll INF = 1e18; using P = pair; template void chmin(T &a,T b){if(a>b)a=b;} template void chmax(T &a,T b){if(a void ans(bool x,T1 y,T2 z){if(x)cout< void debug(vector>v,ll h,ll w){for(ll i=0;iv,ll h,ll w){for(ll i=0;i void debug(vectorv,ll n){if(n!=0)cout< vector>vec(ll x, ll y, T w){ vector>v(x,vector(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} template vectordx={1,0,-1,0,1,1,-1,-1}; vectordy={0,1,0,-1,1,-1,1,-1}; template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } int main(){ cin.tie(NULL); ios_base::sync_with_stdio(false); ll res=0,res1=INF,res2=-INF,buf=0; bool judge = true; ll m,n,mulx,addx,muly,addy,mod; cin>>m>>n>>mulx>>addx>>muly>>addy>>mod; vectordivnum(mod+1,0); vectorx(m),y(m),a(m),b(m); rep(i,0,m)cin>>x[i]; rep(i,0,m)cin>>y[i]; rep(i,0,m)cin>>a[i]; rep(i,0,m)cin>>b[i]; rep(i,0,m){ divnum[x[i]]+=y[i]; divnum[x[i]]&=(mod-1); } ll tmpx=x[m-1],tmpy=y[m-1]; rep(i,m,n){ tmpx=(tmpx*mulx+addx)&(mod-1); tmpy=(tmpy*muly+addy)&(mod-1); divnum[tmpx]+=tmpy; //divnum[tmpx]&=(mod-1); } rep(i,1,mod){ ll cnt=0; for(ll j=i+i;j