#include #include using namespace std; using namespace atcoder; constexpr int mod = 998244353; long long fac[200005], finv[200005], inv[200005]; void COMinit() { fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1; for (int i = 2; i < 200005; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } long long choose(int n,int k) { if(n < 0 || k < 0) return 0; if(n == 0) return 1; return COM(n+k-1,k-1); } int main() { COMinit(); ios::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vectorA(N),B(N); for(int i = 0; i < N; i++) { cin >> A[i]; } for(int i = 0; i < N; i++) { cin >> B[i]; } vector>dp(M,vector(601,1)); for(int i = 0; i < N; i++) { vectora(A[i]+1),b(B[i]+1); for(int j = 0; j <= A[i]; j++) { a[j] = COM(A[i],j); } for(int j = 0; j <= B[i]; j++) { b[j] = COM(B[i],j); } reverse(b.begin(),b.end()); vectorc = convolution(a,b); vectord(601); for(int j = 0; j <= A[i]+B[i]; j++) { d[300+j-B[i]] = c[j]; } for(int j = 0; j <= 600; j++) { dp[i%M][j] = 1ll*dp[i%M][j]*d[j]%mod; } } vectorid(M); iota(id.begin(),id.end(),0); while(id.size() > 1) { vectornxt; for(int i = 0; i+1 < id.size(); i += 2) { dp[id[i]] = convolution(dp[id[i]],dp[id[i+1]]); if(dp[id[i]].size() > 300*M+1) { dp[id[i]].resize(300*M+1); } nxt.push_back(id[i]); } if(id.size()%2) { nxt.push_back(id.back()); } id = nxt; } cout << dp[id[0]][300*M] << endl; }