stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

#define il inline

#define rg register

using namespace std;

typedef long long ll;

const int O=510;

const ll mod=1e9+7;

il int gi(){

	int o=0,fl=1;char ch=getchar();

	while(!isdigit(ch)&&ch!='-')ch=getchar();

	if(ch=='-')fl=-1,ch=getchar();

	while(isdigit(ch))o=o*10+ch-'0',ch=getchar();

	return fl*o;

}

int n,c,a[O],b[O];

ll f[O][O],bin[O][O];

int main(){

	for(int i=1;i<O;++i)bin[i][0]=1;

	for(int i=1;i<O;++i)

		for(int j=1;j<O;++j)

			bin[i][j]=bin[i][j-1]*i%mod;

	for(int i=1;i<O;++i)

		for(int j=0;j<O;++j)

			bin[i][j]=(bin[i-1][j]+bin[i][j])%mod;

	n=gi();c=gi();

	for(int i=1;i<=n;++i)a[i]=gi();

	for(int i=1;i<=n;++i)b[i]=gi();

	f[0][0]=1;

	for(int i=1;i<=n;++i)

		for(int j=0;j<=c;++j)

			for(int k=0;k<=j;++k)

				(f[i][j]+=f[i-1][j-k]*((bin[b[i]][k]-bin[a[i]-1][k])%mod+mod)%mod)%=mod;

	printf("%lld\n",f[n][c]);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.642091593072963x):
#include <iostream>

#include <cstdio>

#define int long long

#define N 402

using namespace std;

const int mod=1000000007;

int n,c,a[N],b[N],sum[N][N],f[N][N],i,j,k;

int poww(int a,int b)

{

	int ans=1,base=a;

	while(b){

		if(b&1) ans=ans*base%mod;

		base=base*base%mod;

		b>>=1;

	}

	return ans%mod;

}

signed main()

{

	cin>>n>>c;

	for(i=1;i<=n;i++) cin>>a[i];

	for(i=1;i<=n;i++) cin>>b[i];

	for(i=1;i<=n;i++){

		if(a[i]>b[i]) swap(a[i],b[i]);

		for(j=0;j<=c;j++){

			for(k=a[i];k<=b[i];k++) sum[i][j]=(sum[i][j]+poww(k,j))%mod;

		}

	}

	for(i=0;i<=c;i++) f[1][i]=sum[1][i];

	for(i=2;i<=n;i++){

		for(j=0;j<=c;j++){

			for(k=0;k<=j;k++) f[i][j]=(f[i][j]+f[i-1][k]*sum[i][j-k]%mod)%mod;

		}

	}

	cout<<f[n][c]<<endl;

	return 0;

}
// Slower C++ solution:
#include<cstdio>

long long n,c,a[405],b[405],invs[405];

long long rankal[405][405],f[405][405];

const long long mod=1e9+7;

long long mmod(long long val,long long k){

	long long ans=1;

	for(;k;k>>=1){

		if(k&1) ans=ans*val%mod;

		val=val*val%mod;

	}

	return ans%mod;

}

long long inv(long long v){return mmod(v,mod-2);}

int main(){

	f[0][0]=1;

	long long pss=1,ans=0;

	scanf("%lld%lld",&n,&c);

	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);

	for(int i=1;i<=n;i++) scanf("%lld",&b[i]);

	for(int i=1;i<=400;i++)

		for(int j=0;j<=c;j++)

			rankal[i][j]=rankal[i-1][j]+mmod(i,j);

	//for(int i=0;i<=400;i++) f[i][0]=1;

	for(int i=1;i<=n;i++)

		for(int j=0;j<=c;j++)

			for(int k=j;k>=0;k--)

				f[i][j]=(f[i-1][j-k]*((rankal[b[i]][k]-rankal[a[i]-1][k]+mod)%mod)+f[i][j])%mod;

	printf("%lld\n",f[n][c]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.329782850396668x):
#include <cstdio>

#include <cstring>

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char c=getchar();

	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}

	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}

	return x*f;

}

const int mod(1e9+7),maxn(405);

int n,c;

ll sum[maxn],f[maxn][maxn];

int a[maxn],b[maxn];

void init(){

	n=read(),c=read();

	for (int i(1);i<=n;++i) a[i]=read();

	for (int i(1);i<=n;++i) b[i]=read();

	f[0][0]=1;

}



void calc(int a,int b){

	memset(sum,0,sizeof(sum));

	for (int i(a);i<=b;++i){

		ll t=1;

		for (int j(0);j<=c;++j){

			sum[j]=sum[j]+t,sum[j]%=mod;

			t=t*i%mod;

		}

	}

}



signed main(){

	init();

	for (int i(1);i<=n;++i){

		calc(a[i],b[i]);

		for (int j(0);j<=c;++j)

			for (int k(0);k<=j;++k)

				f[i][j]=(f[i][j]+f[i-1][j-k]*sum[k])%mod;

	}

	printf("%d\n",f[n][c]);					 

	return 0; 

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<algorithm>

#define MAXN 400

#define MO 1000000007

using namespace std;

int A[MAXN+5],B[MAXN+5];

int sum[MAXN+5][MAXN+5];

int dp[MAXN+5][MAXN+5];

int tot[MAXN+5];

int N,C;

void prepare()

{

	for(int i=1;i<=N;i++)

	{

		sum[i][0]=B[i]-A[i]+1;

		for(int j=A[i];j<=B[i];j++)

			tot[j]=1;

		for(int k=1;k<=C;k++)

			for(int x=A[i];x<=B[i];x++)

			{

				tot[x]=1LL*tot[x]*x%MO;

				sum[i][k]=(1LL*sum[i][k]+tot[x])%MO;

			}

	}

}

int DFS(int pos,int res)

{

	if(pos==1)

	{

		return sum[pos][res];

	}

	if(dp[pos][res]!=-1)

		return dp[pos][res];

	int ret=0;

	for(int k=0;k<=res;k++)

		ret=(1LL*ret+1LL*DFS(pos-1,res-k)*sum[pos][k]%MO)%MO;

	dp[pos][res]=ret;

	return ret;

}

int main()

{

	memset(dp,-1,sizeof(dp));

	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]);

	prepare();

	int ans=DFS(N,C);

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.229620045756424x):
#include <cstdio>

#include <cstring>

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char c=getchar();

	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}

	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}

	return x*f;

}

const int mod(1e9+7),maxn(405);

int n,c;

ll sum[maxn],f[maxn][maxn];

int a[maxn],b[maxn];

void init(){

	n=read(),c=read();

	for (int i(1);i<=n;++i) a[i]=read();

	for (int i(1);i<=n;++i) b[i]=read();

	f[0][0]=1;

}



void calc(int a,int b){

	memset(sum,0,sizeof(sum));

	for (int i(a);i<=b;++i){

		ll t=1;

		for (int j(0);j<=c;++j){

			sum[j]=sum[j]+t,sum[j]%=mod;

			t=t*i%mod;

		}

	}

}



signed main(){

	init();

	for (int i(1);i<=n;++i){

		calc(a[i],b[i]);

		for (int j(0);j<=c;++j)

			for (int k(0);k<=j;++k)

				f[i][j]=(f[i][j]+f[i-1][j-k]*sum[k])%mod;

	}

	printf("%d\n",f[n][c]);					 

	return 0; 

}
// Slower C++ solution:
#include<cstdio>

#define min(a,b) (a<b?a:b)

#define max(a,b) (a>b?a:b)

int n,c;

const long long mod=1e9+7;

int A[405],B[405];

long long matmod(long long val,long long k){

	long long ret=1;

	for(;k;k>>=1){

		if(k&1) ret=(val*ret)%mod;

		val=(val*val)%mod;

	}

	return ret;

}

void add(long long &des,long long sor){des+=sor;des%=mod;return ;}

long long sum[405][405],f[405][405];

int main(){

	//freopen("candies.in","r",stdin);

	//freopen("candies.out","w",stdout);

	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]);

	for(int i=0;i<=c;i++){

		for(int j=1;j<=400;j++)

			add(sum[i][j],sum[i][j-1]+matmod(j*1ll,i*1ll));

	}

	f[0][0]=1;

	for(int i=1;i<=n;i++){

		for(int j=0;j<=c;j++)

			for(int k=0;k<=j;k++)

				add(f[i][j],f[i-1][j-k]*(sum[k][B[i]]-sum[k][max(A[i]-1,0)]+mod)%mod);

	}

	printf("%lld\n",f[n][c]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.4594811874096147x):
#include <cstdio>

#include <cstring>

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char c=getchar();

	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}

	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}

	return x*f;

}

const int mod(1e9+7),maxn(405);

int n,c;

ll sum[maxn],f[maxn][maxn];

int a[maxn],b[maxn];

void init(){

	n=read(),c=read();

	for (int i(1);i<=n;++i) a[i]=read();

	for (int i(1);i<=n;++i) b[i]=read();

	f[0][0]=1;

}



void calc(int a,int b){

	memset(sum,0,sizeof(sum));

	for (int i(a);i<=b;++i){

		ll t=1;

		for (int j(0);j<=c;++j){

			sum[j]=sum[j]+t,sum[j]%=mod;

			t=t*i%mod;

		}

	}

}



signed main(){

	init();

	for (int i(1);i<=n;++i){

		calc(a[i],b[i]);

		for (int j(0);j<=c;++j)

			for (int k(0);k<=j;++k)

				f[i][j]=(f[i][j]+f[i-1][j-k]*sum[k])%mod;

	}

	printf("%d\n",f[n][c]);					 

	return 0; 

}
// Slower C++ solution:
#include <iostream> 

#include <cstdio> 

#include <cstdlib> 

#include <cstring> 

#include <cmath> 

#include <algorithm> 

using namespace std; 



const int Mod = 1e9 + 7;

const int MAX_N = 405; 

int N, C, A[MAX_N], B[MAX_N]; 

int f[MAX_N][MAX_N], sum[MAX_N][MAX_N]; 

int fpow(int x, int y) { 

	int res = 1; 

	while (y) {

		if (y & 1) res = 1ll * res * x % Mod; 

		x = 1ll * x * x % Mod; 

		y >>= 1; 

	} 

	return res; 

} 

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); 

	for (int i = 1; i <= N; i++) 

		for (int j = A[i]; j <= B[i]; j++) 

			for (int k = 0; k <= C; k++) sum[i][k] = (sum[i][k] + fpow(j, k)) % Mod;

	f[0][0] = 1; 

	for (int i = 1; i <= N; i++) { 

		for (int j = 0; j <= C; j++) { 

			for (int k = 0; k <= j; k++) { 

				f[i][j] = (f[i][j] + 1ll * f[i - 1][k] * sum[i][j - k]) % Mod; 

			} 

		} 

	} 

	printf("%d\n", f[N][C]); 

    return 0; 

} 

// Faster C++ solution for the same problem (measured speedup: 5.025585766619778x):
#include <cstdio>

#include <cstring>

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char c=getchar();

	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}

	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}

	return x*f;

}

const int mod(1e9+7),maxn(405);

int n,c;

ll sum[maxn],f[maxn][maxn];

int a[maxn],b[maxn];

void init(){

	n=read(),c=read();

	for (int i(1);i<=n;++i) a[i]=read();

	for (int i(1);i<=n;++i) b[i]=read();

	f[0][0]=1;

}



void calc(int a,int b){

	memset(sum,0,sizeof(sum));

	for (int i(a);i<=b;++i){

		ll t=1;

		for (int j(0);j<=c;++j){

			sum[j]=sum[j]+t,sum[j]%=mod;

			t=t*i%mod;

		}

	}

}



signed main(){

	init();

	for (int i(1);i<=n;++i){

		calc(a[i],b[i]);

		for (int j(0);j<=c;++j)

			for (int k(0);k<=j;++k)

				f[i][j]=(f[i][j]+f[i-1][j-k]*sum[k])%mod;

	}

	printf("%d\n",f[n][c]);					 

	return 0; 

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define il inline

#define rg register

using namespace std;

typedef long long ll;

const int O=510;

const ll mod=1e9+7;

il int gi(){

	int o=0,fl=1;char ch=getchar();

	while(!isdigit(ch)&&ch!='-')ch=getchar();

	if(ch=='-')fl=-1,ch=getchar();

	while(isdigit(ch))o=o*10+ch-'0',ch=getchar();

	return fl*o;

}

int n,c,a[O],b[O];

ll f[O][O],bin[O][O];

int main(){

	for(int i=1;i<O;++i)bin[i][0]=1;

	for(int i=1;i<O;++i)

		for(int j=1;j<O;++j)

			bin[i][j]=bin[i][j-1]*i%mod;

	for(int i=1;i<O;++i)

		for(int j=0;j<O;++j)

			bin[i][j]=(bin[i-1][j]+bin[i][j])%mod;

	n=gi();c=gi();

	for(int i=1;i<=n;++i)a[i]=gi();

	for(int i=1;i<=n;++i)b[i]=gi();

	f[0][0]=1;

	for(int i=1;i<=n;++i)

		for(int j=0;j<=c;++j)

			for(int k=0;k<=j;++k)

				(f[i][j]+=f[i-1][j-k]*((bin[b[i]][k]-bin[a[i]-1][k])%mod+mod)%mod)%=mod;

	printf("%lld\n",f[n][c]);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 23.50776076923891x):
#include <cstdio>

#include <cstring>

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char c=getchar();

	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}

	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}

	return x*f;

}

const int mod(1e9+7),maxn(405);

int n,c;

ll sum[maxn],f[maxn][maxn];

int a[maxn],b[maxn];

void init(){

	n=read(),c=read();

	for (int i(1);i<=n;++i) a[i]=read();

	for (int i(1);i<=n;++i) b[i]=read();

	f[0][0]=1;

}



void calc(int a,int b){

	memset(sum,0,sizeof(sum));

	for (int i(a);i<=b;++i){

		ll t=1;

		for (int j(0);j<=c;++j){

			sum[j]=sum[j]+t,sum[j]%=mod;

			t=t*i%mod;

		}

	}

}



signed main(){

	init();

	for (int i(1);i<=n;++i){

		calc(a[i],b[i]);

		for (int j(0);j<=c;++j)

			for (int k(0);k<=j;++k)

				f[i][j]=(f[i][j]+f[i-1][j-k]*sum[k])%mod;

	}

	printf("%d\n",f[n][c]);					 

	return 0; 

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#define int long long

#define N 402

using namespace std;

const int mod=1000000007;

int n,c,a[N],b[N],sum[N][N],f[N][N],i,j,k;

int poww(int a,int b)

{

	int ans=1,base=a;

	while(b){

		if(b&1) ans=ans*base%mod;

		base=base*base%mod;

		b>>=1;

	}

	return ans%mod;

}

signed main()

{

	cin>>n>>c;

	for(i=1;i<=n;i++) cin>>a[i];

	for(i=1;i<=n;i++) cin>>b[i];

	for(i=1;i<=n;i++){

		if(a[i]>b[i]) swap(a[i],b[i]);

		for(j=0;j<=c;j++){

			for(k=a[i];k<=b[i];k++) sum[i][j]=(sum[i][j]+poww(k,j))%mod;

		}

	}

	for(i=0;i<=c;i++) f[1][i]=sum[1][i];

	for(i=2;i<=n;i++){

		for(j=0;j<=c;j++){

			for(k=0;k<=j;k++) f[i][j]=(f[i][j]+f[i-1][k]*sum[i][j-k]%mod)%mod;

		}

	}

	cout<<f[n][c]<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.064045010296164x):
#include <cstdio>

#include <cstring>

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char c=getchar();

	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}

	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}

	return x*f;

}

const int mod(1e9+7),maxn(405);

int n,c;

ll sum[maxn],f[maxn][maxn];

int a[maxn],b[maxn];

void init(){

	n=read(),c=read();

	for (int i(1);i<=n;++i) a[i]=read();

	for (int i(1);i<=n;++i) b[i]=read();

	f[0][0]=1;

}



void calc(int a,int b){

	memset(sum,0,sizeof(sum));

	for (int i(a);i<=b;++i){

		ll t=1;

		for (int j(0);j<=c;++j){

			sum[j]=sum[j]+t,sum[j]%=mod;

			t=t*i%mod;

		}

	}

}



signed main(){

	init();

	for (int i(1);i<=n;++i){

		calc(a[i],b[i]);

		for (int j(0);j<=c;++j)

			for (int k(0);k<=j;++k)

				f[i][j]=(f[i][j]+f[i-1][j-k]*sum[k])%mod;

	}

	printf("%d\n",f[n][c]);					 

	return 0; 

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define il inline

#define rg register

using namespace std;

typedef long long ll;

const int O=510;

const ll mod=1e9+7;

il int gi(){

	int o=0,fl=1;char ch=getchar();

	while(!isdigit(ch)&&ch!='-')ch=getchar();

	if(ch=='-')fl=-1,ch=getchar();

	while(isdigit(ch))o=o*10+ch-'0',ch=getchar();

	return fl*o;

}

int n,c,a[O],b[O];

ll f[O][O],bin[O][O];

int main(){

	for(int i=1;i<O;++i)bin[i][0]=1;

	for(int i=1;i<O;++i)

		for(int j=1;j<O;++j)

			bin[i][j]=bin[i][j-1]*i%mod;

	for(int i=1;i<O;++i)

		for(int j=0;j<O;++j)

			bin[i][j]=(bin[i-1][j]+bin[i][j])%mod;

	n=gi();c=gi();

	for(int i=1;i<=n;++i)a[i]=gi();

	for(int i=1;i<=n;++i)b[i]=gi();

	f[0][0]=1;

	for(int i=1;i<=n;++i)

		for(int j=0;j<=c;++j)

			for(int k=0;k<=j;++k)

				(f[i][j]+=f[i-1][j-k]*((bin[b[i]][k]-bin[a[i]-1][k])%mod+mod)%mod)%=mod;

	printf("%lld\n",f[n][c]);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.692407712033196x):
#include <algorithm>

#include <iostream>

#include <cstring>

#include <cstdio>

#define mod 1000000007

#define N 1005

using namespace std;



int n, m, a[N], b[N], f[N][N], cost[N][N], ans; 



template < typename T >

inline T read()

{

	T x = 0, w = 1; char c = getchar();

	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }

	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();

	return x * w; 

}



int fpow(int x, int y)

{

	int res = 1;

	while(y)

	{

		if(y & 1) res = 1ll * res * x % mod;

		x = 1ll * x * x % mod;

		y >>= 1; 

	}

	return res; 

}



int main()

{

	n = read <int> (), m = read <int> (); 

	for(int i = 1; i <= n; i++)

		a[i] = read <int> ();

	for(int i = 1; i <= n; i++)

		b[i] = read <int> ();

	for(int i = 1; i <= n; i++)

		for(int j = 0; j <= m; j++)

			for(int k = a[i]; k <= b[i]; k++)

				cost[i][j] = (1ll * cost[i][j] + fpow(k, j)) % mod;

	f[0][0] = 1; 

	for(int i = 1; i <= n; i++)

		for(int j = 0; j <= m; j++)

			for(int k = 0; k <= j; k++)

				f[i][j] = (1ll * f[i][j] + 1ll * f[i - 1][k] * cost[i][j - k] % mod) % mod; 

	printf("%d\n", f[n][m]); 

	return 0; 

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>



using namespace std;



const int mod = 1e9 + 7;

int f[405][405], a[405][405], l[405], r[405], n, c, b[405][405], ans;



inline int read()

{

	char ch; int res;

	while (ch = getchar(), ch < '0' || ch > '9');

	res = ch - 48;

	while (ch = getchar(), ch >= '0' && ch <= '9')

	res = res * 10 + ch - 48;

	return res;

}



int main()

{

//	freopen("candy.in", "r", stdin);

//	freopen("candy.out", "w", stdout);

	int i, j, k;

	n = read(); c = read();

	for (i = 1; i <= n; i++) l[i] = read();

	for (i = 1; i <= n; i++) r[i] = read();

	for (i = 1; i <= n; i++)

	for (int x = l[i]; x <= r[i]; x++)

	{

		int y = 1;

		for (j = 0; j <= c; j++)

		{

			a[i][j] = (a[i][j] + y) % mod;

			y = 1ll * y * x % mod;

		}

	}

	f[0][0] = 1;

	for (i = 1; i <= n; i++)

	for (j = 0; j <= c; j++)

	for (k = 0; k <= j; k++)

	f[i][j] = (f[i][j] + 1ll * f[i - 1][k] * a[i][j - k]) % mod;

	cout << f[n][c] << endl;

	fclose(stdin);

	fclose(stdout);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.999110424279881x):
#include <cstdio>

#include <cstring>

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char c=getchar();

	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}

	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}

	return x*f;

}

const int mod(1e9+7),maxn(405);

int n,c;

ll sum[maxn],f[maxn][maxn];

int a[maxn],b[maxn];

void init(){

	n=read(),c=read();

	for (int i(1);i<=n;++i) a[i]=read();

	for (int i(1);i<=n;++i) b[i]=read();

	f[0][0]=1;

}



void calc(int a,int b){

	memset(sum,0,sizeof(sum));

	for (int i(a);i<=b;++i){

		ll t=1;

		for (int j(0);j<=c;++j){

			sum[j]=sum[j]+t,sum[j]%=mod;

			t=t*i%mod;

		}

	}

}



signed main(){

	init();

	for (int i(1);i<=n;++i){

		calc(a[i],b[i]);

		for (int j(0);j<=c;++j)

			for (int k(0);k<=j;++k)

				f[i][j]=(f[i][j]+f[i-1][j-k]*sum[k])%mod;

	}

	printf("%d\n",f[n][c]);					 

	return 0; 

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define F(i,a,b) for(int i=(a);i<=(b);++i)

#define F2(i,a,b) for(int i=(a);i<(b);++i)

#define dF(i,a,b) for(int i=(a);i>=(b);--i)

#define dF2(i,a,b) for(int i=(a);i>(b);--i)

#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)

using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;



#define M 1000000007

int n,C;

int a[401],b[401];

int c[401][401],f[401][401];

void P(int&x,ll y){x=(x+y)%M;}



int main(){

	scanf("%d%d",&n,&C);

	F(i,1,n) scanf("%d",a+i);

	F(i,1,n) scanf("%d",b+i);

	f[0][0]=1;

	F(i,1,n){

		F(k,a[i],b[i]){

			int K=1;

			F(j,0,C){

				P(c[i][j],K);

				K=(ll)K*k%M;

			}

		}

		F(j,0,C){

			F(k,0,j){

				P(f[i][j],(ll)c[i][k]*f[i-1][j-k]);

			}

		}

	} printf("%d",f[n][C]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.61589136801884x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define mod 1000000007

#define MN 405

using namespace std;

inline int in(){

    int x=0;bool f=0;char c;

    for (;(c=getchar())<'0'||c>'9';f=c=='-');

    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');

    return f?-x:x;

}

int f[MN][MN],sum[MN][MN],a[MN],b[MN];

int n,c,mx;

inline int qpow(int x,int k){

	int res=1;

	while (k){

		if (k&1) res=(1ll*res*x)%mod;

		x=(1ll*x*x)%mod;k>>=1;

	}return res;

}

int main()

{

	n=in();c=in();

	for (int i=1;i<=n;++i) a[i]=in(),mx=max(mx,a[i]);

	for (int i=1;i<=n;++i) b[i]=in(),mx=max(mx,b[i]); 

	for (int i=0;i<=c;++i)

	for (int j=1;j<=mx;++j) sum[i][j]=(sum[i][j-1]+qpow(j,i))%mod;

	f[0][0]=1;

	for (int i=1;i<=n;++i){

		int I=i&1;memset(f[I],0,sizeof(f[I]));

		for (int j=0;j<=c;++j)

		for (int k=0;k<=j;++k) f[I][j]=(1ll*f[I][j]+(1ll*f[I^1][k]*((1ll*sum[j-k][b[i]]+mod-sum[j-k][a[i]-1])%mod)%mod)%mod)%mod;

	}printf("%d",f[n&1][c]);return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define F(i,a,b) for(int i=(a);i<=(b);++i)

#define F2(i,a,b) for(int i=(a);i<(b);++i)

#define dF(i,a,b) for(int i=(a);i>=(b);--i)

#define dF2(i,a,b) for(int i=(a);i>(b);--i)

#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)

using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;



#define M 1000000007

int n,C;

int a[401],b[401];

int c[401][401],f[401][401];

void P(int&x,ll y){x=(x+y)%M;}



int main(){

	scanf("%d%d",&n,&C);

	F(i,1,n) scanf("%d",a+i);

	F(i,1,n) scanf("%d",b+i);

	f[0][0]=1;

	F(i,1,n){

		F(k,a[i],b[i]){

			int K=1;

			F(j,0,C){

				P(c[i][j],K);

				K=(ll)K*k%M;

			}

		}

		F(j,0,C){

			F(k,0,j){

				P(f[i][j],(ll)c[i][k]*f[i-1][j-k]);

			}

		}

	} printf("%d",f[n][C]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.943598735932643x):
#include <stdio.h>

#include <string.h>

#include <algorithm>

#define R register

typedef long long ll;

inline int read(){

	R int x; R bool f; R char c;

	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');

	for (x=c^'0'; (c=getchar())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0'));

	return f?-x:x;

}

#define P 1000000007 

inline int plu(int x,int y){return (x+=y)>=P?x-P:x;}

inline int mul(int x,int y){return (ll)x*y%P;}

#define MN 405

int f[MN][MN],g[MN][MN],n,C,A[MN],B[MN];

int main(){

	n=read(),C=read();f[0][0]=1;

	for (R int i=1; i<=n; ++i) A[i]=read();	

	for (R int i=1; i<=n; ++i) B[i]=read();

	for (R int i=1; i<=n; ++i)

		for (R int j=A[i]; j<=B[i]; ++j)

			for (R int k=0,x=1; k<=C; ++k,x=mul(x,j))

				g[i][k]=plu(g[i][k],x);

	for (R int i=1; i<=n; ++i)

		for (R int j=0; j<=C; ++j)

			for (R int k=0; k<=C-j; ++k)

				f[i][k+j]=plu(f[i][k+j],mul(f[i-1][k],g[i][j]));

	printf("%d\n",f[n][C]);return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define F(i,a,b) for(int i=(a);i<=(b);++i)

#define F2(i,a,b) for(int i=(a);i<(b);++i)

#define dF(i,a,b) for(int i=(a);i>=(b);--i)

#define dF2(i,a,b) for(int i=(a);i>(b);--i)

#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)

using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;



#define M 1000000007

int n,C;

int a[401],b[401];

int c[401][401],f[401][401];

void P(int&x,ll y){x=(x+y)%M;}



int main(){

	scanf("%d%d",&n,&C);

	F(i,1,n) scanf("%d",a+i);

	F(i,1,n) scanf("%d",b+i);

	f[0][0]=1;

	F(i,1,n){

		F(k,a[i],b[i]){

			int K=1;

			F(j,0,C){

				P(c[i][j],K);

				K=(ll)K*k%M;

			}

		}

		F(j,0,C){

			F(k,0,j){

				P(f[i][j],(ll)c[i][k]*f[i-1][j-k]);

			}

		}

	} printf("%d",f[n][C]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.0096637274739706x):
#include<cstdio>

#define min(a,b) (a<b?a:b)

#define max(a,b) (a<b?a:b)

int n,c;

const long long mod=1e9+7;

int A[405],B[405];

long long matmod(long long val,long long k){

	long long ret=1;

	for(;k;k>>=1){

		if(k&1) ret=(val*ret)%mod;

		val=(val*val)%mod;

	}

	return ret;

}

void add(long long &des,long long sor){des+=sor;des%=mod;return ;}

long long sum[405][405],f[405][405];

int main(){

	//freopen("candies.in","r",stdin);

	//freopen("candies.out","w",stdout);

	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]);

	for(int i=0;i<=c;i++){

		for(int j=1;j<=400;j++)

			add(sum[i][j],sum[i][j-1]+matmod(j*1ll,i*1ll));

	}

	f[0][0]=1;

	for(int i=1;i<=n;i++){

		for(int j=0;j<=c;j++)

			for(int k=0;k<=j;k++)

				add(f[i][j],f[i-1][j-k]*(sum[k][B[i]]-sum[k][A[i]-1]+mod)%mod);

	}

	printf("%lld\n",f[n][c]);

	return 0;

}