#include #define whlie while #define pb push_back #define eb emplace_back #define fi first #define se second #define rep(i,N) for(int i = 0; i < (N); i++) #define repr(i,N) for(int i = (N) - 1; i >= 0; i--) #define rep1(i,N) for(int i = 1; i <= (N) ; i++) #define repr1(i,N) for(int i = (N) ; i > 0 ; i--) #define each(x,v) for(auto& x : v) #define all(v) (v).begin(),(v).end() #define sz(v) ((int)(v).size()) #define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++) #define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++) #define ini(...) int __VA_ARGS__; in(__VA_ARGS__) #define inl(...) ll __VA_ARGS__; in(__VA_ARGS__) #define ins(...) string __VA_ARGS__; in(__VA_ARGS__) using namespace std; void solve(); using ll = long long; using vl = vector; using vi = vector; using vvi = vector< vector >; constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1; struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya; template inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; } template ostream& operator <<(ostream& os, const pair &p) { os << p.first << " " << p.second; return os; } template istream& operator >>(istream& is, pair &p) { is >> p.first >> p.second; return is; } template ostream& operator <<(ostream& os, const vector &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; } template istream& operator >>(istream& is, vector &v) { for(auto &x : v) is >> x; return is; } void in(){} template void in(T &t,U &...u){ cin >> t; in(u...);} void out(){cout << "\n";} template void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);} templatevoid die(T x){out(x); exit(0);} #ifdef NyaanDebug #include "NyaanDebug.h" #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0) #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0) #else #define trc(...) #define trca(...) int main(){solve();} #endif using P = pair; using vp = vector

; //constexpr int MOD = /**/ 1000000007; //*/ 998244353; ///////////////// struct divisor_transform{ template static constexpr void zeta_transform(vector &a){ int N = a.size() - 1; vector sieve(N + 1, true); for(int p = 2; p <= N; p++) if(sieve[p]) for(int k = 1; k * p <= N; ++k) sieve[k * p] = false , a[k * p] += a[k]; } template static constexpr void mobius_transform(T &a){ int N = a.size() - 1; vector sieve(N + 1, true); for(int p = 2; p <= N; p++) if(sieve[p]) for(int k = N / p; k > 0; --k) sieve[k * p] = false , a[k * p] -= a[k]; } // verify // https://atcoder.jp/contests/arc064/submissions/7707249 template static constexpr void zeta_transform(map &a){ for(auto &x : a) for(auto &y : a){ if(x == y) break; if(x.first % y.first == 0) x.second += y.second; } } template static constexpr void mobius_transform(map &a){ for(auto &x : a) for(auto &y : a){ if(x == y) break; if(x.first % y.first == 0) x.second -= y.second; } } }; // verify // https://atcoder.jp/contests/agc038/submissions/7683063 // https://www.codechef.com/viewsolution/26767783 struct multiple_transform{ template static constexpr void zeta_transform(vector &a){ int N = a.size() - 1; vector sieve(N + 1, true); for(int p = 2; p <= N; ++p) if(sieve[p]) for(int k = N / p; k > 0; --k) sieve[k * p] = false , a[k] += a[k * p]; } template static constexpr void mobius_transform(vector &a){ int N = a.size() - 1; vector sieve(N + 1, true); for(int p = 2; p <= N; ++p) if(sieve[p]) for(int k = 1; k * p <= N; ++k) sieve[k * p] = false , a[k] -= a[k * p]; } template static constexpr void zeta_transform(map &a){ for(auto it=a.rbegin(); it!=a.rend(); it++) for(auto it2=a.rbegin(); it2!=it; it2++) if(it2->first % it->first == 0) it->second += it2->second; } template static constexpr void mobius_transform(map &a){ for(auto it=a.rbegin(); it!=a.rend(); it++) for(auto it2=a.rbegin(); it2!=it; it2++) if(it2->first % it->first == 0) it->second -= it2->second; } }; template static constexpr vector mobius_function(int N){ vector a(N + 1 , 0); a[1] = 1; divisor_transform::mobius_transform(a); return a; } template struct constexpr_mobius_function{ int mobius[N + 1] , sieve[N + 1]; constexpr constexpr_mobius_function(): mobius() , sieve(){ for(int i=1; i<=N; i++) sieve[i] = 1, mobius[i] = 0; mobius[1] = 1; for(int p = 2; p <= N; p++) if(sieve[p]) for(int k = N / p; k > 0; --k) sieve[k * p] = false , mobius[k * p] -= mobius[k]; } const int& operator[](int i)const{return mobius[i];} }; // N = 1000000 , pnum = 78498 template struct constexpr_prime{ int prime[pnum]; int sieve[N + 1]; constexpr_prime() : prime() , sieve() { for(int i=2;i<=N;i++) sieve[i]=1; int idx = 0; for(long long p = 2; p <= N; p++){ if(sieve[p]){ prime[idx++] = p; for(long long j = p * p; j <= N; j += p) sieve[j] = 0; } } } const long long& operator[](long long i) const{return prime[i];} }; // verify template static constexpr unordered_map divisor_zeta_transform(long long N, F f){ // factorization unordered_map factors; { long long M = N; for(long long i = 2; i * i <= M; i++) while(M % i == 0) factors[i]++ , M /= i; if(M != 1) factors[M]++; } unordered_map ret; ret.emplace(1 , 1); for(auto &d : factors){ auto ret2 = ret; T prev = 1; for(long long i = 1 , cur = d.first; i <= d.second; i++ , cur *= d.first){ T val = ( prev += f(cur) ); for(auto &x : ret) ret2.emplace(x.first*cur , x.second*val); } swap(ret , ret2); } return ret; } // verify // https://onlinejudge.u-aizu.ac.jp/status/users/NyaanNyaan/submissions/1/NTL_1_D/judge/3892694/C++14 // https://atcoder.jp/contests/abc020/submissions/7695313 template static constexpr unordered_map divisor_mobius_transform(long long N, F f){ // factorization unordered_map factors; { long long M = N; for(long long i = 2; i * i <= M; i++) while(M % i == 0) factors[i]++ , M /= i; if(M != 1) factors[M]++; } unordered_map ret; ret.emplace(1 , 1); for(auto &d : factors){ auto ret2 = ret; for(long long i = 1,cur = d.first , prev = 1; i <= d.second; i++ , cur *= d.first , prev *= d.first){ T val = f(cur) - f(prev); for(auto &x : ret) ret2.emplace(x.first*cur , x.second*val); } swap(ret , ret2); } return ret; } void solve(){ inl(M,N,mulx,addx,muly,addy,MOD); vl count(MOD + 1); { ll X,Y; { vl x(M); in(x); vl y(M); in(y); rep(i,M) count[x[i]] += y[i]; X = x[M-1], Y = y[M-1]; } for(int i=M; i