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

using namespace std;

#define maxn 405

#define ll long long

#define p 1000000007

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

int n,m,a[maxn],b[maxn];

int main()

{

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

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

	{

		sum[i][0]=1;

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

			sum[i][j]=1ll*sum[i][j-1]*i%p;

	}

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

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

			sum[i][j]+=sum[i-1][j],sum[i][j]%=p;

	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]+=0ll+1ll*f[i-1][j-k]*(sum[b[i]][k]-sum[a[i]-1][k])%p;

				f[i][j]%=p;

			}

	printf("%lld\n",(f[n][m]%p+p)%p);

	return 0;

}

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

#include<cstdio>

#include<cstring>

#include<string>

#define mod 1000000007

#define ll long long

using namespace std;



ll qpow(ll x,ll t){

	ll ans=1;

	while(t){

		if(t&1)ans=(ans*x)%mod;

		x=(x*x)%mod;

		t>>=1;

	}

	return ans%mod;

}



ll n,c,a[410],b[410],dp[2][401][401];



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

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

			dp[1%2][j][k]=qpow(k,j)%mod;

			dp[1%2][j][0]+=dp[1][j][k];

			dp[1%2][j][0]%=mod;

		}

	

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

		

		memset(dp[i%2],0,sizeof(dp[i%2]));

		

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

			dp[(i)%2][0][k]=dp[(i-1)%2][0][0];

		

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

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

				dp[(i)%2][j][k]+=(k*dp[(i)%2][j-1][k])%mod;

				dp[(i)%2][j][k]%=mod;

				

				dp[(i)%2][j][k]+=dp[(i-1)%2][j][0];

				dp[(i)%2][j][k]%=mod;

			}

		}

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

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

				dp[(i)%2][j][0]=(dp[(i)%2][j][k]+dp[(i)%2][j][0])%mod;

	}

	

	cout<<dp[n%2][c][0]%mod;

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

using namespace std;

//#include<ext/rope>

//using namespace __gnu_cxx

//#include<ext/pb_ds/priority_queue.hpp>

//using namespace __gnu_pbds;

#define lowbit(x) (x&-x)

#define pb push_back

#define empb emplace_back

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

#define clr(a,b) memset(a,b,sizeof(a))

#define caze(T) for(cin>>T;T;T--)

#define inf (1<<29)

#define Endl ('\n')

#define fi first

#define se second

#define db double

#define ldb long double

#define ll long long

#define pii pair<int,int>

#define pil pair<int,ll>

#define pli pair<ll,int>

#define pll pair<ll,ll>

#define ull unsigned long long

#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

inline char nc() {

	#define SZ 1000000

	static char buf[SZ], *p1, *p2;

	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;

}

template<typename T>

inline int scan(T &x) {

	char c, sign=1; 

	while(!isdigit(c=nc())&&c!=EOF)if(c=='-')sign*=-1;

	if(c==EOF) return EOF;

	for(x = 0; isdigit(c); c = nc())

		x = (x<<1) + (x<<3) + (c&15);

	return x *= sign, 1;

}

template<typename T, typename...Args>

inline int scan(T &x, Args&...args) {

	return scan(x), scan(args...);

}

const int N=1<<9;

const int mod=1000000007;

int s[N][N];

int dp[N][N];

int l[N],r[N];

void upd(int &x,int y){x+=y;if(x>=mod)x-=mod;}

int sum(int k,int a,int b){int ret=s[k][b]-s[k][a-1]+mod;ret%=mod;return ret;}

int main()

{IOS;

	int n,k;cin>>n>>k;

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

		cin>>l[i];

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

		cin>>r[i];

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

		s[0][i]=1;

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

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

			s[i][j]=1LL*s[i-1][j]*j%mod;

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

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

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

	dp[0][0]=1;

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

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

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

				upd(dp[i][j],1LL*dp[i-1][j-o]*sum(o,l[i],r[i])%mod);

	cout<<dp[n][k]<<Endl;

}

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

#include<cstdio>

#include<cstring>

#include<string>

#define mod 1000000007

#define ll long long

using namespace std;



ll qpow(ll x,ll t){

	ll ans=1;

	while(t){

		if(t&1)ans=(ans*x)%mod;

		x=(x*x)%mod;

		t>>=1;

	}

	return ans%mod;

}



ll n,c,a[410],b[410],dp[2][401][401];



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

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

			dp[1%2][j][k]=qpow(k,j)%mod;

			dp[1%2][j][0]+=dp[1][j][k];

			dp[1%2][j][0]%=mod;

		}

	

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

		

		memset(dp[i%2],0,sizeof(dp[i%2]));

		

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

			dp[(i)%2][0][k]=dp[(i-1)%2][0][0];

		

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

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

				dp[(i)%2][j][k]+=(k*dp[(i)%2][j-1][k])%mod;

				dp[(i)%2][j][k]%=mod;

				

				dp[(i)%2][j][k]+=dp[(i-1)%2][j][0];

				dp[(i)%2][j][k]%=mod;

			}

		}

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

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

				dp[(i)%2][j][0]=(dp[(i)%2][j][k]+dp[(i)%2][j][0])%mod;

	}

	

	cout<<dp[n%2][c][0]%mod;

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

#include<iomanip>

#include<cstdio>

#include<cstdlib>

#include<cmath>

#include<cstring>

#include<ctime>

#include<vector>

#include<queue>

#include<map>

#include<deque>

#include<stack>

#include<algorithm>

#define N 405

using namespace std;

const int INF=0x7fffffff;

const double Pi=acos(-1);

const long long Mod=1e9+7;

long long A[N],B[N],P[N][N],Sum[N][N],F[N][N];

int main()

{

	int i,j,k,n,m;

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

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

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

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

	{

		P[i][0]=1;

		for(j=1;j<=400;j++)//P[i][j]=i^j

		{

			P[i][j]=P[i][j-1]*i%Mod;

		}

	}

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

	{

		Sum[0][j]=0;

		for(i=1;i<=400;i++)//Sum[i][j]=1^j+2^j+...+i^j 

		{

			Sum[i][j]=(Sum[i-1][j]+P[i][j])%Mod;

		}

	}

	F[0][0]=1;

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

	{

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

		{

			for(k=0;k<=j;k++)//Ã¶¾ÙµÚi¸öÈË·Ök¸ö 

			{

				long long Temp=(Sum[B[i]][k]-Sum[A[i]-1][k]+Mod)%Mod;

				F[i][j]=(F[i][j]+F[i-1][j-k]*Temp%Mod)%Mod;

			}

		}

	}

	printf("%lld\n",F[n][m]);

	return 0;

}


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

#include<cstdio>

#include<cstring>

#include<string>

#define mod 1000000007

#define ll long long

using namespace std;



ll qpow(ll x,ll t){

	ll ans=1;

	while(t){

		if(t&1)ans=(ans*x)%mod;

		x=(x*x)%mod;

		t>>=1;

	}

	return ans%mod;

}



ll n,c,a[410],b[410],dp[2][401][401];



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

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

			dp[1%2][j][k]=qpow(k,j)%mod;

			dp[1%2][j][0]+=dp[1][j][k];

			dp[1%2][j][0]%=mod;

		}

	

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

		

		memset(dp[i%2],0,sizeof(dp[i%2]));

		

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

			dp[(i)%2][0][k]=dp[(i-1)%2][0][0];

		

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

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

				dp[(i)%2][j][k]+=(k*dp[(i)%2][j-1][k])%mod;

				dp[(i)%2][j][k]%=mod;

				

				dp[(i)%2][j][k]+=dp[(i-1)%2][j][0];

				dp[(i)%2][j][k]%=mod;

			}

		}

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

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

				dp[(i)%2][j][0]=(dp[(i)%2][j][k]+dp[(i)%2][j][0])%mod;

	}

	

	cout<<dp[n%2][c][0]%mod;

}
// Slower C++ solution:
/*  ***  In The Name of God ... ***  */ 

#include <bits/stdc++.h>

 

using namespace std;

 

typedef long long ll;

typedef long double ld;

 

 

#define int long long

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



template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}

template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}



const int N = 400 + 10 , mod = 1e9 + 7 ;



int n , C , a [ N ] , b [ N ] , t [ N ] [ N ] , sum [ N ] [ N ] , dp [ N ] [ N ] ; 



int32_t main()

{

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

	cin >> n >> C ;

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

		cin >> a [ i ] ;

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

		cin >> b [ i ] ;

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

		t [ i ] [ 0 ] = 1 ;

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

			( t [ i ] [ j ] = t [ i ] [ j - 1 ] * i ) %= mod ; 

		}

	}

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

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

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

				sum [ i ] [ j ] += t [ k ] [ j ] , sum [ i ] [ j ] %= 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 - 1 ] [ j - k ] * sum [ i ] [ k ] % mod ) ;

				dp [ i ] [ j ] %= mod ; 

			}

		}

	}/*

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

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

			cout << i << ' ' << want << ' ' << dp [ i ] [ want ] << '\n' ; 

		}

		}*/

	cout << dp [ n ] [ C ] % mod << '\n' ; 

}


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

#include<cctype>

#include<cstring>

#include<algorithm>

#include<vector>

using std::vector;

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

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

#define reg register

typedef long long ll;

inline int read(){

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

    for(;!isdigit(ch);f=ch=='-'?-1:1,ch=getchar());

    for(;isdigit(ch);x=x*10+(ch^48),ch=getchar());

    return x*f;

}

const int mod=1e9+7;

int n,c;

int a[405],b[405],f[405][405];

ll prod[405][405];

inline ll qpow(ll a,ll b){

    reg ll res=1;

    while(b){

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

        a=a*a%mod;b>>=1;

    }

    return res;

}

int main(){

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

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

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

        b[i]=read();prod[i][0]=b[i]-a[i]+1;

        for(reg int j=1;j<=c;j++)

            for(reg int k=a[i];k<=b[i];k++)prod[i][j]=(prod[i][j]+qpow(k,j))%mod;

    }

    f[0][0]=1;

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

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

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

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

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

    return 0;

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

using namespace std;

inline int read(){

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

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

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

	return x*f;

}

#define mod 1000000007

#define MN 405

long long f[MN][MN],pw[MN][MN],qz[MN][MN];

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

void add(long long &x,long long y){x+=y;if(x>mod)x-=mod;}

long long Abs(long long x){if(x<0) x+=mod;return x;}

int main(){

	register int i,j,k;

	for(i=1;i<=400;i++) pw[i][0]=1;

	

	for(i=1;i<=400;i++)for(j=1;j<=400;j++) pw[i][j]=(pw[i][j-1]*i)%mod;

	for(i=1;i<=400;i++)for(j=0;j<=400;j++) qz[i][j]=(qz[i-1][j]+pw[i][j])%mod;

	

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

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

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

	

	f[0][0]=1;

	

	for(i=1;i<=n;i++)for(j=0;j<=c;j++)for(k=j;k>=0;k--){

		add(f[i][j],f[i-1][k]*Abs(qz[b[i]][j-k]-qz[a[i]-1][j-k])%mod);

	}

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

	return 0;

}

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

#include<cctype>

#include<cstring>

#include<algorithm>

#include<vector>

using std::vector;

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

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

#define reg register

typedef long long ll;

inline int read(){

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

    for(;!isdigit(ch);f=ch=='-'?-1:1,ch=getchar());

    for(;isdigit(ch);x=x*10+(ch^48),ch=getchar());

    return x*f;

}

const int mod=1e9+7;

int n,c;

int a[405],b[405],f[405][405];

ll prod[405][405];

inline ll qpow(ll a,ll b){

    reg ll res=1;

    while(b){

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

        a=a*a%mod;b>>=1;

    }

    return res;

}

int main(){

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

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

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

        b[i]=read();prod[i][0]=b[i]-a[i]+1;

        for(reg int j=1;j<=c;j++)

            for(reg int k=a[i];k<=b[i];k++)prod[i][j]=(prod[i][j]+qpow(k,j))%mod;

    }

    f[0][0]=1;

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

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

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

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

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

    return 0;

}
// Slower C++ solution:
/*  ***  In The Name of God ... ***  */ 

#include <bits/stdc++.h>

 

using namespace std;

 

typedef long long ll;

typedef long double ld;

 

 

#define int long long

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



template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}

template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}



const int N = 400 + 10 , mod = 1e9 + 7 ;



int n , C , a [ N ] , b [ N ] , t [ N ] [ N ] , sum [ N ] [ N ] , dp [ N ] [ N ] ; 



int32_t main()

{

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

	cin >> n >> C ;

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

		cin >> a [ i ] ;

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

		cin >> b [ i ] ;

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

		t [ i ] [ 0 ] = 1 ;

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

			( t [ i ] [ j ] = t [ i ] [ j - 1 ] * i ) %= mod ; 

		}

	}

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

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

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

				sum [ i ] [ j ] += t [ k ] [ j ] , sum [ i ] [ j ] %= 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 - 1 ] [ j - k ] * sum [ i ] [ k ] % mod ) ;

				dp [ i ] [ j ] %= mod ; 

			}

		}

	}/*

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

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

			cout << i << ' ' << want << ' ' << dp [ i ] [ want ] << '\n' ; 

		}

		}*/

	cout << dp [ n ] [ C ] % mod << '\n' ; 

}


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

#include<iostream>

#include<cstring>

#define RG register

#define ll long long

using namespace std;

const int N=404;

const ll mod=1e9+7;

int n,m,a[N],b[N],maxx;

ll dp[N][N],mult[N][N],sum[N][N];

inline ll read(){

	char ch=getchar(); ll x=0, f=1;

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

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

	return x*f;}

inline int mx(int a,int b){return a>b ? a : b;}

int main()

{

//	freopen("Children and Candies.in","r",stdin);

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

	n=read(); m=read();

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

	for(RG int i=1;i<=n;i++) b[i]=read(), maxx=mx(maxx,b[i]);

	for(RG int i=1;i<=maxx;i++)

	{

		mult[i][0]=1;

		for(RG int j=1;j<=m;j++) mult[i][j]=mult[i][j-1]*i%mod;

	}

	for(RG int i=1;i<=maxx;i++)

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

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

	dp[0][0]=1;

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

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

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

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

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

	//fclose(stdin); fclose(stdout);

	return 0;

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

using namespace std;

inline int read(){

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

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

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

	return x*f;

}

#define mod 1000000007

#define MN 405

long long f[MN][MN],pw[MN][MN],qz[MN][MN];

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

void add(long long &x,long long y){x+=y;if(x>mod)x-=mod;}

long long Abs(long long x){if(x<0) x+=mod;return x;}

int main(){

	register int i,j,k;

	for(i=1;i<=400;i++) pw[i][0]=1;

	

	for(i=1;i<=400;i++)for(j=1;j<=400;j++) pw[i][j]=(pw[i][j-1]*i)%mod;

	for(i=1;i<=400;i++)for(j=0;j<=400;j++) qz[i][j]=(qz[i-1][j]+pw[i][j])%mod;

	

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

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

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

	

	f[0][0]=1;

	

	for(i=1;i<=n;i++)for(j=0;j<=c;j++)for(k=j;k>=0;k--){

		add(f[i][j],f[i-1][k]*Abs(qz[b[i]][j-k]-qz[a[i]-1][j-k])%mod);

	}

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

	return 0;

}

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

#include<iostream>

#include<cstring>

#define RG register

#define ll long long

using namespace std;

const int N=404;

const ll mod=1e9+7;

int n,m,a[N],b[N],maxx;

ll dp[N][N],mult[N][N],sum[N][N];

inline ll read(){

	char ch=getchar(); ll x=0, f=1;

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

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

	return x*f;}

inline int mx(int a,int b){return a>b ? a : b;}

int main()

{

//	freopen("Children and Candies.in","r",stdin);

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

	n=read(); m=read();

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

	for(RG int i=1;i<=n;i++) b[i]=read(), maxx=mx(maxx,b[i]);

	for(RG int i=1;i<=maxx;i++)

	{

		mult[i][0]=1;

		for(RG int j=1;j<=m;j++) mult[i][j]=mult[i][j-1]*i%mod;

	}

	for(RG int i=1;i<=maxx;i++)

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

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

	dp[0][0]=1;

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

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

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

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

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

	//fclose(stdin); fclose(stdout);

	return 0;

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

using namespace std;

inline int read(){

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

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

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

	return x*f;

}

#define mod 1000000007

#define MN 405

long long f[MN][MN],pw[MN][MN],qz[MN][MN];

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

void add(long long &x,long long y){x+=y;if(x>mod)x-=mod;}

long long Abs(long long x){if(x<0) x+=mod;return x;}

int main(){

	register int i,j,k;

	for(i=1;i<=400;i++) pw[i][0]=1;

	

	for(i=1;i<=400;i++)for(j=1;j<=400;j++) pw[i][j]=(pw[i][j-1]*i)%mod;

	for(i=1;i<=400;i++)for(j=0;j<=400;j++) qz[i][j]=(qz[i-1][j]+pw[i][j])%mod;

	

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

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

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

	

	f[0][0]=1;

	

	for(i=1;i<=n;i++)for(j=0;j<=c;j++)for(k=j;k>=0;k--){

		add(f[i][j],f[i-1][k]*Abs(qz[b[i]][j-k]-qz[a[i]-1][j-k])%mod);

	}

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

	return 0;

}

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

#include <cstring>

#include <algorithm>

using namespace std;

typedef long long LL;

const int mod=1e9+7;

const int maxn=410;

int n,c;

LL p1[maxn][maxn],p2[maxn][maxn],dp[maxn][maxn];

LL a[maxn],b[maxn];



void _init() {

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

        p1[i][0]=p2[i][0]=1;

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

            p1[i][j]=(p1[i][j-1]*i)%mod;

    }

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

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

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

}



int main() {

    _init();

    while (scanf("%d%d",&n,&c)!=EOF) {

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

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

        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++) {

                    LL t=(p2[b[i]][k]-p2[a[i]-1][k]+mod)%mod;

                    dp[i][j]=(dp[i][j]+dp[i-1][j-k]*t)%mod;

                }



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

    }

    return 0;

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

using namespace std;

inline int read(){

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

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

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

	return x*f;

}

#define mod 1000000007

#define MN 405

long long f[MN][MN],pw[MN][MN],qz[MN][MN];

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

void add(long long &x,long long y){x+=y;if(x>mod)x-=mod;}

long long Abs(long long x){if(x<0) x+=mod;return x;}

int main(){

	register int i,j,k;

	for(i=1;i<=400;i++) pw[i][0]=1;

	

	for(i=1;i<=400;i++)for(j=1;j<=400;j++) pw[i][j]=(pw[i][j-1]*i)%mod;

	for(i=1;i<=400;i++)for(j=0;j<=400;j++) qz[i][j]=(qz[i-1][j]+pw[i][j])%mod;

	

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

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

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

	

	f[0][0]=1;

	

	for(i=1;i<=n;i++)for(j=0;j<=c;j++)for(k=j;k>=0;k--){

		add(f[i][j],f[i-1][k]*Abs(qz[b[i]][j-k]-qz[a[i]-1][j-k])%mod);

	}

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

	return 0;

}

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

#include<cstring>

#include<algorithm>

const int maxn=410;

typedef long long ll;

int n,c;

const ll MOD=1e9+7;

ll a[maxn],b[maxn],f[maxn][maxn];

ll pwr[maxn][maxn],pre[maxn][maxn];

void preload()

{

    pre[0][0]=1;

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

    {

        pwr[i][0]=1;

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

        {

            pwr[i][j]=(pwr[i][j-1]%MOD*i)%MOD;

        }

    }

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

    {

        pre[i][0]=1;

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

        {

            pre[i][j]=(pwr[i][j]+pre[i-1][j])%MOD;

        }

    }

}

int main()

{

    preload();

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

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

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

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

            {

                ll tmp=((pre[b[i]][k]-pre[a[i]-1][k])%MOD+MOD)%MOD;

                f[i][j]=(f[i][j]+f[i-1][j-k]*tmp)%MOD;

            }

        }

    }

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

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

#define ll long long

using namespace std;

const int N = 401;

const int mod = 1e9 + 7;

inline int add(ll x, ll y) {return (x + y) % mod;}

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

inline int sub(ll x, ll y) {return (x - y + mod) % mod;}

int dp[N][N], sum[N][N], A[N], B[N];



int main()

{

    int n, c; 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 y = 1; y <= 400; y++)

        for (int x = 0, v = 1; x <= 400; x++, v = mul(v, y)) sum[x][y] = v;

    for (int x = 0; x <= 400; x++)

        for (int y = 1; y <= 400; y++) sum[x][y] = add(sum[x][y], sum[x][y - 1]);

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

    dp[0][c] = 1;

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

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

            for (int k = j; k <= c; k++) if (dp[i - 1][k] != -1)

            {

                if (dp[i][j] == -1) dp[i][j] = 0;

                int use = k - j;

                dp[i][j] = add(dp[i][j], mul(dp[i - 1][k], sub(sum[use][B[i]], sum[use][A[i] - 1])));

            }

    printf("%d\n", dp[n][0]);

    return 0;

}

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

#include<cstring>

#include<algorithm>

const int maxn=410;

typedef long long ll;

int n,c;

const ll MOD=1e9+7;

ll a[maxn],b[maxn],f[maxn][maxn];

ll pwr[maxn][maxn],pre[maxn][maxn];

void preload()

{

    pre[0][0]=1;

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

    {

        pwr[i][0]=1;

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

        {

            pwr[i][j]=(pwr[i][j-1]%MOD*i)%MOD;

        }

    }

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

    {

        pre[i][0]=1;

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

        {

            pre[i][j]=(pwr[i][j]+pre[i-1][j])%MOD;

        }

    }

}

int main()

{

    preload();

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

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

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

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

            {

                ll tmp=((pre[b[i]][k]-pre[a[i]-1][k])%MOD+MOD)%MOD;

                f[i][j]=(f[i][j]+f[i-1][j-k]*tmp)%MOD;

            }

        }

    }

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

}