#include int main () { int n = 0; int m = 0; int a[200000] = {}; int b[200000] = {}; int res = 0; long long dp[301][900001] = {}; long long mod_num = 998244353LL; long long comb[301][301] = {}; long long cnt[301][301][301] = {}; long long prod[300][601] = {}; res = scanf("%d", &n); res = scanf("%d", &m); for (int i = 0; i < n; i++) { res = scanf("%d", a+i); } for (int i = 0; i < n; i++) { res = scanf("%d", b+i); } for (int i = 0; i <= 300; i++) { comb[i][0] = 1LL; comb[i][i] = 1LL; for (int j = 1; j < i; j++) { comb[i][j] = (comb[i-1][j-1]+comb[i-1][j])%mod_num; } } for (int i = 1; i <= 300; i++) { for (int j = 0; j <= 300; j++) { cnt[i][0][j] = comb[i][j]; } for (int j = 1; j <= 300; j++) { for (int k = 0; k < 300; k++) { cnt[i][j][k] = (cnt[i][j-1][k]+cnt[i][j-1][k+1])%mod_num; } if (i >= 300) { cnt[i][j][300] = 1LL; } } } for (int i = 0; i < m; i++) { for (int j = 0; j <= 600; j++) { prod[i][j] = 1LL; } } for (int i = 0; i < n; i++) { for (int j = 0; j <= 300; j++) { prod[i%m][j+300] *= cnt[a[i]][b[i]][j]; prod[i%m][j+300] %= mod_num; } for (int j = 1; j <= 300; j++) { prod[i%m][300-j] *= cnt[b[i]][a[i]][j]; prod[i%m][300-j] %= mod_num; } } dp[0][45000] = 1LL; for (int i = 0; i < m; i++) { int b = i+1; if (b > m-i-1) { b = m-i-1; } for (int j = -300*b; j <= 300*b; j++) { for (int k = -300; k <= 300; k++) { dp[i+1][j+45000] += dp[i][j+45000+k]*prod[i][k+300]; dp[i+1][j+45000] %= mod_num; } } } printf("%lld\n", dp[m][45000]); return 0; }