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

using namespace std;



typedef long long LL;



const LL MOD = 1e9+7;



inline LL dmod(LL x){

	return x%MOD;

}



int n,c;



LL pang[405][405];

LL ps[405][405];



void pre(){

	for(int i=0;i<=400;i++) pang[i][0] = 1LL;

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

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

			pang[i][j] = dmod(pang[i][j-1]*(LL)i);

		}

	}

	for(int i=0;i<=400;i++) ps[0][i] = pang[0][i];

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

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

			ps[i][j] = dmod(ps[i-1][j] + pang[i][j]);

		}

	}

}



//int n,c;

int A[405],B[405];



LL memo[405][405];



LL dp(int id, int sisa){

	if(id > n){

		if(sisa == 0) return 1LL;

		else return 0LL;

	}

	LL &ret = memo[id][sisa];

	if(ret!=-1) return ret;

	ret = 0LL;

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

		ret = dmod(ret+dmod(dp(id+1,sisa-i)*dmod(ps[B[id]][i] - ps[A[id]][i]+MOD)));

	}

	return ret;

}



int main(){

	pre();

//	for(int i=0;i<=5;i++){

//		for(int j=0;j<=5;j++){

//			cout << ps[i][j] << " ";

//		}

//		cout << endl;

//	}

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

	cin >> n >> c;

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

		cin >> A[i];

		A[i]--;

	}

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

		cin >> B[i];

	}

	LL ans = dp(1,c);

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.857004415384699x):
#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;

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

using namespace std;



typedef long long LL;



const LL MOD = 1e9+7;



inline LL dmod(LL x){

	return x%MOD;

}



int n,c;



LL pang[405][405];

LL ps[405][405];



void pre(){

	for(int i=0;i<=400;i++) pang[i][0] = 1LL;

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

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

			pang[i][j] = dmod(pang[i][j-1]*(LL)i);

		}

	}

	for(int i=0;i<=400;i++) ps[0][i] = pang[0][i];

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

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

			ps[i][j] = dmod(ps[i-1][j] + pang[i][j]);

		}

	}

}



//int n,c;

int A[405],B[405];



LL memo[405][405];



LL dp(int id, int sisa){

	if(id > n){

		if(sisa == 0) return 1LL;

		else return 0LL;

	}

	LL &ret = memo[id][sisa];

	if(ret!=-1) return ret;

	ret = 0LL;

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

		ret = dmod(ret+dmod(dp(id+1,sisa-i)*dmod(ps[B[id]][i] - ps[A[id]][i]+MOD)));

	}

	return ret;

}



int main(){

	pre();

//	for(int i=0;i<=5;i++){

//		for(int j=0;j<=5;j++){

//			cout << ps[i][j] << " ";

//		}

//		cout << endl;

//	}

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

	cin >> n >> c;

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

		cin >> A[i];

		A[i]--;

	}

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

		cin >> B[i];

	}

	LL ans = dp(1,c);

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 15.039529575199875x):
#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;

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



using namespace std;

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

#define REP(i,a,b) REPP(i,a,b,1)

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

#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) REP(i,0,(int)a-1)

#define FORD(i,a) REV(i,(int)a-1,0)

#define PB push_back

#define POB pop_back

#define FI first

#define SE second

#define MP make_pair

typedef long long ll;

typedef unsigned long long ull;

typedef pair < int , int > pii;

typedef vector < int > vi;

typedef vector < pii > vii;

typedef vector < ll > vl;

typedef pair < ll , ll > pll;



const double PI = acos(-1);

const double EPS = 1e-9;

const ll MOD = 1e9 + 7;

const int INF = 1e9;

	



ll addMod(ll a, ll b){

	if(a + b >= MOD) return a + b - MOD;

	return a + b;

}



ll mulMod(ll a, ll b){

	return (a*b)%MOD;

}



ll fast(ll a, ll b){

	if(b == 0) return 1;

	ll tmp = fast(a,b/2);

	tmp = mulMod(tmp,tmp);

	if(b%2 == 1) tmp = mulMod(tmp,a);

	return tmp;

}



ll GCD(ll a, ll b){

	if(a > b) return GCD(b,a);

	if(a == 0) return b;

	return GCD(b%a,a);

}



//////////////////////////////////////////////



const int N = 400;



int n,m;

ll dp[N + 5][N + 5];

ll tot[N + 5][N + 5];

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



ll solve(int idx, int rem){

	if(idx == n+1){

		if(rem == 0) return 1;

		return 0;

	}

	ll& ret = dp[idx][rem];

	if(ret != -1) return ret;

	ret = 0;

	FOR(i,rem+1){

		ret = addMod(ret, mulMod(solve(idx+1,rem-i), addMod(tot[i][B[idx]], MOD - tot[i][A[idx]-1])));

	}

	return ret;

	

}

int main(){

	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

	FOR(i,N+2){

		FOR(j,N+2){

			tot[i][j] = (i == 0) ? 1 : mulMod(tot[i-1][j], (ll)j);

		}

	}

	FOR(i,N+2){

		tot[i][0] = 0;

		REP(j,1,N){

			tot[i][j] = addMod(tot[i][j], tot[i][j-1]);

		}

	}

	cin >> n >> m;

	REP(i,1,n) cin >> A[i];

	REP(i,1,n) cin >> B[i];

	memset(dp,-1,sizeof dp);

	cout << solve(1,m) << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 13.216989980974715x):
#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;

}
// Slower C++ solution:
/*

  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;

}


// Faster C++ solution for the same problem (measured speedup: 3.8458977049556213x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 3.0259104080299957x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 3.89927725133284x):
#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;

}
// 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: 1.7197204302307199x):
#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;

}
// 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.178218257697844x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=405;

const int mod=1e9+7;

int a[N],b[N];

int n,c;

ll ans=0;

ll ksm(ll x,ll y){

    ll res=1;

    while(y){

        if(y&1){

            res=(res*x)%mod;

        }

        x=(x*x)%mod;

        y>>=1;

    }

    return res;

}

ll sum[N][N];

ll hjb[N][N];

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 j=0;j<=c;j++)

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

                sum[1][j]=(sum[1][j]+ksm(k,j))%mod;

        /*for(int i=2;i<=n;i++){

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

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

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

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

                    }

                }

            }

        }*/

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

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

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

                    hjb[i][l]=(hjb[i][l]+ksm(k,l))%mod;

                }

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

                    sum[i][j]=(sum[i][j]+hjb[i][l]*sum[i-1][j-l]%mod)%mod;

                }

            }

        }

        ans=0;

        ans=sum[n][c];

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

}
// 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: 3.9544610800198936x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=405;

const int mod=1e9+7;

int a[N],b[N];

int n,c;

ll ans=0;

ll ksm(ll x,ll y){

    ll res=1;

    while(y){

        if(y&1){

            res=(res*x)%mod;

        }

        x=(x*x)%mod;

        y>>=1;

    }

    return res;

}

ll sum[N][N];

ll hjb[N][N];

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 j=0;j<=c;j++)

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

                sum[1][j]=(sum[1][j]+ksm(k,j))%mod;

        /*for(int i=2;i<=n;i++){

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

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

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

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

                    }

                }

            }

        }*/

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

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

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

                    hjb[i][l]=(hjb[i][l]+ksm(k,l))%mod;

                }

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

                    sum[i][j]=(sum[i][j]+hjb[i][l]*sum[i-1][j-l]%mod)%mod;

                }

            }

        }

        ans=0;

        ans=sum[n][c];

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

}
// 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.299479037699958x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=405;

const int mod=1e9+7;

int a[N],b[N];

int n,c;

ll ans=0;

ll ksm(ll x,ll y){

    ll res=1;

    while(y){

        if(y&1){

            res=(res*x)%mod;

        }

        x=(x*x)%mod;

        y>>=1;

    }

    return res;

}

ll sum[N][N];

ll hjb[N][N];

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 j=0;j<=c;j++)

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

                sum[1][j]=(sum[1][j]+ksm(k,j))%mod;

        /*for(int i=2;i<=n;i++){

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

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

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

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

                    }

                }

            }

        }*/

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

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

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

                    hjb[i][l]=(hjb[i][l]+ksm(k,l))%mod;

                }

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

                    sum[i][j]=(sum[i][j]+hjb[i][l]*sum[i-1][j-l]%mod)%mod;

                }

            }

        }

        ans=0;

        ans=sum[n][c];

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

}