#include #include using namespace std; using namespace atcoder; #define rep(i, n) for (int i=0; i coef[310]; vector rec(int l, int r) { if (l==r) return coef[l]; int m = (l+r)/2; vector res1 = rec(l, m); vector res2 = rec(m+1, r); vector res = convolution(res1, res2); return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; int A[N], B[N]; rep(i, N) cin >> A[i]; rep(i, N) cin >> B[i]; Cinit(); int offset = 300; rep(i, M) { coef[i].resize(601); rep(j, 601) coef[i][j] = 1ll; } rep(i, M) { for (int j=i; j a(A[j]+1, 0), b(B[j]+1, 0); rep(k, A[j]+1) a[k] = C(A[j], k)%MOD; rep(k, B[j]+1) b[k] = C(B[j], B[j]-k)%MOD; vector conv = convolution(a, b); for (int k=0; k<601; k++) { if (-B[j]<=k-offset && k-offset<=A[j]) { coef[i][k] *= conv[k-offset+B[j]]; coef[i][k] %= MOD; } else coef[i][k] = 0ll; } } } vector res = rec(0, M-1); cout << res[M*offset] << endl; }