import sys input = sys.stdin.readline N,M=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) mod=998244353 FACT=[1] for i in range(1,2*10**5+1): FACT.append(FACT[-1]*i%mod) FACT_INV=[pow(FACT[-1],mod-2,mod)] for i in range(2*10**5,0,-1): FACT_INV.append(FACT_INV[-1]*i%mod) FACT_INV.reverse() def Combi(a,b): if 0<=b<=a: return FACT[a]*FACT_INV[b]%mod*FACT_INV[a-b]%mod else: return 0 PLUS=[[1]*601 for i in range(M)] for i in range(N): k=i%M a=A[i] b=B[i] for j in range(601): p=j-300 # bの方がaよりp多い score=0 for x in range(a+1): y=x+p if 0<=y<=b: score+=Combi(a,x)*Combi(b,y) score%=mod PLUS[k][j]=PLUS[k][j]*score%mod DP=[0]*(2*300*300+1) DP[300*300]=1 for i in range(M): NDP=[0]*(2*300*300+1) for j in range(2*300*300+1): if DP[j]==0: continue for k in range(601): p=k-300 if 0<=j+p<2*300*300: NDP[j+p]=(NDP[j+p]+DP[j]*PLUS[i][k])%mod DP=NDP print(DP[300*300])