#include using namespace std; using namespace atcoder; using mint = atcoder::modint998244353; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, M, r = 600; cin >> N >> M; vector A(N), B(N); for(auto &&v:A)cin >> v; for(auto &&v:B)cin >> v; vector> comb(r + 1), tb(M + 1, vector(r + 1, 1)); for(int i = 1; i <= r; i++){ comb[i].resize(i + 1); comb[i][0] = comb[i][i] = 1; for(int j = 1; j < i; j++) comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]; } for(int i = 0; i < N; i++){ int rem = i % M; for(int j = -B[i]; j <= A[i]; j++) tb[rem][j + 300] *= comb[A[i] + B[i]][B[i] + j]; for(int j = A[i] + 1; j <= 300; j++) tb[rem][j + 300] = 0; for(int j = B[i] + 1; j <= 300; j++) tb[rem][-j + 300] = 0; } vector dp(1, 1); for(int i = 0, s = 300 * M + 1; i < M; i++){ dp = convolution(dp, tb[i]); if(dp.size() > s) dp.resize(s); } cout << dp.back().val() << '\n'; }