stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
/*

  mail: mleautomaton@foxmail.com

  author: MLEAutoMaton

  This Code is made by MLEAutoMaton

*/

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<queue>

#include<set>

#include<map>

#include<iostream>

using namespace std;

#define ll long long

#define REP(a,b,c) for(int a=b;a<=c;a++)

#define re register

#define int ll

#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)

inline int gi(){

	int f=1,sum=0;char ch=getchar();

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

	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}

	return f*sum;

}

const int N=410,Mod=1e9+7;

int a[N],b[N],n,sum[N][N],c,dp[N][N];

int val(int i,int Q){

	return (sum[Q][b[i]]-sum[Q][a[i]-1]+Mod)%Mod;

}

int qpow(int a,int b){

	int ret=1;

	while(b){

		if(b&1)ret=1ll*ret*a%Mod;b>>=1;

		a=1ll*a*a%Mod;

	}

	return ret;

}

signed main(){

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

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

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

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

			sum[i][j]=(sum[i][j-1]+qpow(j,i))%Mod;

	dp[0][0]=1;

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

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

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

				dp[i][j]=(dp[i][j]+1ll*dp[i-1][k]*val(i,j-k)%Mod)%Mod;

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

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define LL long long

using namespace std;

const int M=557,mod=1e9+7,mx=400;

LL read(){

	LL ans=0,f=1,c=getchar();

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

	while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}

	return ans*f;

}

LL n,c;

LL A[M],B[M],p[M][M],f[M][M];

int main(){

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

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

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

	for(int i=1;i<=mx;i++) p[i][0]=1;

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

		for(int j=1;j<=c;j++) p[i][j]=p[i][j-1]*i%mod;

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

		for(int j=0;j<=c;j++) p[i][j]=(p[i][j]+p[i-1][j])%mod;

	f[0][0]=1;

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

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

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

	f[i][j]=(f[i][j]+f[i-1][j-m]*(((p[B[i]][m]-p[A[i]-1][m])%mod+mod)%mod))%mod;

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

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstring>

#define int long long

#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)

using namespace std;



inline int read(){

	int sum=0,f=1;char ch=getchar();

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

	while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();}

	return f*sum;

}



const int N=405;

const int Mod=1000000007;

struct node{int l,r;}a[N];

int n,C,f[N][N],p[N];



signed main(){

	n=read();C=read();

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

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

	f[0][0]=1;

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

		for(int i=0;i<N;i++) p[i]=0;

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

			int ret=1;p[0]++;

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

				ret=ret*x%Mod;p[j]=(p[j]+ret)%Mod;

			}

		}

		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]*p[k]%Mod)%Mod;

			}

		}

	}

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

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define LL long long

using namespace std;

const int M=557,mod=1e9+7,mx=400;

LL read(){

	LL ans=0,f=1,c=getchar();

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

	while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}

	return ans*f;

}

LL n,c;

LL A[M],B[M],p[M][M],f[M][M];

int main(){

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

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

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

	for(int i=1;i<=mx;i++) p[i][0]=1;

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

		for(int j=1;j<=c;j++) p[i][j]=p[i][j-1]*i%mod;

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

		for(int j=0;j<=c;j++) p[i][j]=(p[i][j]+p[i-1][j])%mod;

	f[0][0]=1;

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

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

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

	f[i][j]=(f[i][j]+f[i-1][j-m]*(((p[B[i]][m]-p[A[i]-1][m])%mod+mod)%mod))%mod;

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

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef double db;

typedef long long ll;

typedef pair<int, int> pii;

#define fi first

#define se second

#define empb emplace_back

#define all(x) (x).begin(),(x).end()

#define lbd(a, x) lower_bound(all(a), x)

const int mod = 1e9 + 7;

int power_mod(int a, int b) {

	int res = 1;

	for(; b; b >>= 1, a = (ll) a * a % mod)

		if(b & 1) res = (ll) res * a % mod;

	return res;

}

#define sz(x) (int)(x).size()

const int N = 410;

int n, C;

int a[N], b[N], pw[N][N];

vector<int> multiply(const vector<int> &a, const vector<int> &b) {

	vector<int> c(sz(a) + sz(b));

	for(int i = 0; i < sz(a); i++)

		for(int j = 0; j < sz(b); j++)

			c[i + j] = (c[i + j] + (ll) a[i] * b[j]) % mod;

	if(c.size() > C + 1) c.resize(C + 1);

	return c;

}

vector<int> work(int l, int r) {

	if(l == r) {

		vector<int> ret(C + 1, 0);

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

			ret[i] = (pw[b[l]][i] - pw[a[l]-1][i] + mod) % mod;

		}

		return ret;

	}

	int mid = (l + r) >> 1;

	auto al = work(l, mid);

	auto ar = work(mid + 1, r);

	return multiply(al, ar);

}

int main() {

#ifdef local

	freopen("in.txt", "r", stdin);

#endif

	ios::sync_with_stdio(false);

	cin.tie(0), cout.tie(0);

	cin >> n >> C;

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

		cin >> a[i];

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

		cin >> b[i];

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

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

			pw[i][k] = power_mod(i, k);

			pw[i][k] = (pw[i][k] + pw[i - 1][k]) % mod;

		}

	}

	auto z = work(0, n - 1);

	cout << z[C] << '\n';

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define LL long long

using namespace std;

const int M=557,mod=1e9+7,mx=400;

LL read(){

	LL ans=0,f=1,c=getchar();

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

	while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}

	return ans*f;

}

LL n,c;

LL A[M],B[M],p[M][M],f[M][M];

int main(){

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

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

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

	for(int i=1;i<=mx;i++) p[i][0]=1;

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

		for(int j=1;j<=c;j++) p[i][j]=p[i][j-1]*i%mod;

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

		for(int j=0;j<=c;j++) p[i][j]=(p[i][j]+p[i-1][j])%mod;

	f[0][0]=1;

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

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

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

	f[i][j]=(f[i][j]+f[i-1][j-m]*(((p[B[i]][m]-p[A[i]-1][m])%mod+mod)%mod))%mod;

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

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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; 

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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; 

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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; 

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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; 

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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; 

} 

// Optimized solution to the same problem (faster):
#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; 

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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; 

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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; 

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

using namespace std;

long long N,C,a[405],b[405],c[405][405],f[405][405],tmp;

inline long long add(long long x,long long y){

	return ((x+y)<1000000007)?(x+y):(x+y-1000000007);

}

inline long long mul(long long x,long long y){

	return x*y%1000000007;

}

int main(){

	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<=N;i++)

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

			tmp=1;

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

				c[i][k]=add(c[i][k],tmp);

				tmp=mul(tmp,j);

			}

		}

	f[0][0]=1;

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

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

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

				f[i][j+k]=add(f[i][j+k],mul(f[i-1][k],c[i][j]));

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

	return 0;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem: