#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;

const int N=405;
const int mod=1e9+7;
int n,c,Max;
int a[N],b[N],sum[N][N],dp[N][N];

int main(void)
{
	scanf("%d%d",&n,&c);
	for(register int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	for(register int i=1;i<=n;++i)
		scanf("%d",&b[i]);
	for(register int i=0;i<N;++i)
		sum[i][0]=1;
	for(register int i=0;i<N;++i)
		for(register int j=1;j<=c;++j)
			sum[i][j]=1ll*sum[i][j-1]*i%mod;
	for(register int i=1;i<N;++i)
		for(register int j=0;j<=c;++j)
			sum[i][j]=1ll*(sum[i-1][j]+sum[i][j])%mod;
	dp[0][0]=1;
	for(register int i=1;i<=n;++i)
		for(register int j=0;j<=c;++j)
			for(register int k=0;k<=j;++k)
				dp[i][j]=1ll*(dp[i][j]+1ll*dp[i-1][j-k]*(sum[b[i]][k]-sum[a[i]-1][k]+mod)%mod)%mod;
	printf("%d\n",dp[n][c]);
	return 0;
}