#include<cstdio>
typedef long long LL;
const int N=405,md=1e9+7;
int n,c,A[N],B[N],dp[N];
int pre[N][N],pw[N];
inline void upd(int&a){a+=a>>31&md;}
int main(){
	scanf("%d%d",&n,&c);
	for(int i=1;i<=n;++i)scanf("%d",A+i);
	for(int i=1;i<=n;++i)scanf("%d",B+i);
	dp[0]=1;
	for(int i=1;i<=400;++i)pw[i]=1;
	for(int i=0;i<=c;++i){
		int*P=pre[i];
		for(int j=1;j<=400;++j)upd(P[j]=P[j-1]+pw[j]-md),pw[j]=(LL)pw[j]*j%md;
	}
	for(int i=1;i<=n;++i){
		for(int C=c;~C;--C){
			int d=0;
			for(int j=0;j<=C;++j)
			d=(d+(LL)dp[C-j]*(pre[j][B[i]]-pre[j][A[i]-1]+md))%md;
			dp[C]=d;
		}
	}
	printf("%d\n",dp[c]);
	return 0;
}