stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

using namespace std;



long long f[405][405];

long long clz=1E9+7;

long long a[405],b[405];

long long n,c;

long long sm[405][405],p[405][405];



void init(){

    p[0][0]=1;

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

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

        

        scanf("%lld",&a[i]);

    }

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

        scanf("%lld",&b[i]);

    }

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

        p[i][0]=1;

        sm[i][0]=1;

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

            p[i][j]=(p[i][j-1]*i)%clz;

        }

    }

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

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

            sm[i][j]=(sm[i-1][j]+p[i][j])%clz;

        }

    }

    memset(f,0,sizeof(f));

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

                long long t=(sm[b[i]][k]-sm[a[i]-1][k]+clz)%clz;

                f[i][j]=(f[i][j]+f[i-1][j-k]*t)%clz;

            }

        }

    }

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

}



int main(){

    init();

    return 0;

}

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



const int mod = 1e9 + 7; 

const int MaxN = 4e2 + 5; 



int n, c; 

int l[MaxN], r[MaxN]; 

int f[MaxN][MaxN], pw[MaxN][MaxN]; 



inline void add(int &x, const int &y)

{

	x += y; 

	(x >= mod) ? (x -= mod) : 0; 

}



int main()

{

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

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

	

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

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

		scanf("%d", l + i); 

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

		scanf("%d", r + i); 

	

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

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

		{

			int now = 1; 

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

			{

				add(pw[i][k], now); 

				now = 1LL * now * j % 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][j - k] * pw[i][k]) % mod; 

	

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

	

	fclose(stdin); 

	fclose(stdout); 

	return 0; 

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



using namespace std ; 



#define N 500

#define ll long long

const ll mod = 1e9+7 ; 



ll n , m ;

ll a[ N ] , b[ N ] ;

ll sum[ N ][ N ] , l[ N ][ N ] ;

ll f[ N ][ N ] ;

//f[ i ][ j ]前i个人一共分了j个糖果 

//l[ i ][ j ]储存i的j次方

//sum[ i ][ j ]对l维护前缀和 



int main() {

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

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

        l[ i ][ 0 ] = 1 ;

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

            l[ i ][ j ] = l[ i ][ j - 1 ] * i  ;

            l[ i ][ j ] %= mod ;

        }

    }

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

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

            sum[ i ][ j ] += sum[ i - 1 ][ j ] + l[ i ][ j ] ;

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

            }

        } 

    } 

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

    return 0 ;

} 

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



const int mod = 1e9 + 7; 

const int MaxN = 4e2 + 5; 



int n, c; 

int l[MaxN], r[MaxN]; 

int f[MaxN][MaxN], pw[MaxN][MaxN]; 



inline void add(int &x, const int &y)

{

	x += y; 

	(x >= mod) ? (x -= mod) : 0; 

}



int main()

{

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

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

	

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

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

		scanf("%d", l + i); 

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

		scanf("%d", r + i); 

	

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

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

		{

			int now = 1; 

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

			{

				add(pw[i][k], now); 

				now = 1LL * now * j % 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][j - k] * pw[i][k]) % mod; 

	

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

	

	fclose(stdin); 

	fclose(stdout); 

	return 0; 

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

#define mod 1000000007

using namespace std;

int n,c,a[405],b[405],q[405][405],s[405][405],f[405][405],ans,mx;

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;

}

int main(){

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

		q[i][0]=1;

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

	}

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

		s[i][0]=1;

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

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

	}

	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;

	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]*((s[j-k][b[i]]-s[j-k][a[i]-1]+mod)%mod))%mod;

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

} 

//记s[i][j]为1-j所有数的i次方之和 

//记f[i][j]为前i个人分j个糖果的答案，对于f[i][j]，可以从f[i-1][k](0<=k<=j)转移，给i个人j-k个糖果， 

//f[i][j]+=f[i-1][k]*(s[j-k][b[i]]-s[j-k][a[i]-1]) 

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

#include <cstring>

#include <algorithm>

#define R register

using namespace std;

const int mod=1000000007;

const int MAXN=410;

int a[MAXN],b[MAXN],po[MAXN][MAXN];

int dp[MAXN][MAXN];



int add(int x,int y)

{return (x+y)%mod;}

int sub(int x,int y)

{return (x-y+mod)%mod;}

int mul(int x,int y)

{return 1LL*x*y%mod;}



int main()

{

	int n,m;

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

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

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

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

	{

		int t=1;

		po[i][0]=i;

		for(R int j=1;j<=m;++j)

		{

			t=mul(t,i);

			po[i][j]=add(po[i-1][j],t);

		}

	}

	dp[0][0]=1;

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

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

		for(R int k=0;k<=m;++k)

		{

			if(j+k>m)break;

			dp[i][k+j]=add(dp[i][k+j],mul(dp[i-1][k],sub(po[b[i]][j],po[a[i]-1][j])));

		}

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

	return 0;

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

#include <cstring>

#include <algorithm>

#define mod 1000000007

#define MN 405

using namespace std;

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

int n,m;



inline int read()

{

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

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

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

	return n*f;

}



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



int main()

{

	register int i,j,k;

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

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

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

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

		for (pro[i][0]=j=1;j<MN;++j)

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

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

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

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

				rw(sum[i][k],pro[j][k]);

	f[0][0]=1;

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

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

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

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

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

}

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

#include<algorithm>

#define MAXN 406

#define MOD 1000000007

using namespace std;

long long d[MAXN][MAXN];

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

long long ksm(long long a,int m)

{

	if(m==0) return 1;

	long long nex=ksm(a,m/2);

	nex=nex*nex%MOD;

	if(m%2==0) return nex;

	return nex*a%MOD;

}

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

	d[0][0]=1;

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

	{

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

		{

			long long sum=0;

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

				sum=(sum+ksm(1ll*k,j))%MOD;

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

				d[i][l]=(d[i][l]+d[i-1][l-j]*sum)%MOD;

		}

	}

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

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

#define mod 1000000007

using namespace std;

int n,c,a[405],b[405],q[405][405],s[405][405],f[405][405],ans;

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;

}

int main(){

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

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

		q[i][0]=1;

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

	}

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

		s[i][0]=1;

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

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

	}

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

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

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

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

}

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

#include<algorithm>

#define MAXN 406

#define MOD 1000000007

using namespace std;

long long d[MAXN][MAXN];

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

long long ksm(long long a,int m)

{

	if(m==0) return 1;

	long long nex=ksm(a,m/2);

	nex=nex*nex%MOD;

	if(m%2==0) return nex;

	return nex*a%MOD;

}

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

	d[0][0]=1;

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

	{

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

		{

			long long sum=0;

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

				sum=(sum+ksm(1ll*k,j))%MOD;

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

				d[i][l]=(d[i][l]+d[i-1][l-j]*sum)%MOD;

		}

	}

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

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

#define mod 1000000007

using namespace std;

int n,c,a[405],b[405],q[405][405],s[405][405],f[405][405],ans;

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;

}

int main(){

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

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

		q[i][0]=1;

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

	}

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

		s[i][0]=1;

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

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

	}

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

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

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

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

}

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

using namespace std;

const long long Mod=1e9+7;

int n,c,l[405],r[405];

long long G[405][405],f[405][405],a[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",&l[i]);

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

	for(long long i=1;i<=400;i++){G[i][0]=1;for(int j=1;j<=400;j++) G[i][j]=(G[i][j-1]*i)%Mod;}

	for(int i=1;i<=n;i++) for(int j=0;j<=c;j++) for(int u=l[i];u<=r[i];u++) f[i][j]=(f[i][j]+G[u][j])%Mod;

	a[0][0]=1;

	for(int i=1;i<=n;i++) for(int j=0;j<=c;j++) for(int k=0;k<=j;k++) a[i][j]=(a[i][j]+a[i-1][j-k]*f[i][k])%Mod;

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

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

#include <cstring>

#include <algorithm>

#define mod 1000000007

#define MN 405

using namespace std;

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

int n,m;



inline int read()

{

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

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

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

	return n*f;

}



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



int main()

{

	register int i,j,k;

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

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

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

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

		for (pro[i][0]=j=1;j<MN;++j)

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

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

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

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

				rw(sum[i][k],pro[j][k]);

	f[0][0]=1;

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

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

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

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

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

}

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

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

#define mod 1000000007

using namespace std;

int n,c,a[405],b[405],q[405][405],s[405][405],f[405][405],ans;

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;

}

int main(){

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

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

		q[i][0]=1;

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

	}

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

		s[i][0]=1;

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

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

	}

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

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

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

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

}

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

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

using namespace std;

const long long Mod=1e9+7;

int n,c,l[405],r[405];

long long G[405][405],f[405][405],a[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",&l[i]);

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

	for(long long i=1;i<=400;i++){G[i][0]=1;for(int j=1;j<=400;j++) G[i][j]=(G[i][j-1]*i)%Mod;}

	for(int i=1;i<=n;i++) for(int j=0;j<=c;j++) for(int u=l[i];u<=r[i];u++) f[i][j]=(f[i][j]+G[u][j])%Mod;

	a[0][0]=1;

	for(int i=1;i<=n;i++) for(int j=0;j<=c;j++) for(int k=0;k<=j;k++) a[i][j]=(a[i][j]+a[i-1][j-k]*f[i][k])%Mod;

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

}

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

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

#define mod 1000000007

using namespace std;

int n,c,a[405],b[405],q[405][405],s[405][405],f[405][405],ans;

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;

}

int main(){

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

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

		q[i][0]=1;

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

	}

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

		s[i][0]=1;

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

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

	}

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

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

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

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

}

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

#define int long long

#define rg register

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

using namespace std;

const int mod=1e9+7;

int read(){

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

    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();

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

    return f*x;

}

int f[401][401];//第i个为j用了k颗

int a[401],b[404],c[404][404];

int ksm(int a,int b){

	int ans=1;

	while(b){

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

		a=a*a%mod;

		b>>=1;

	}

	return ans;

}

main(){

    //file("");

	int n=read(),C=read(),ans=0;

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

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

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

				c[i][k]=(c[i][k]+ksm(j,k))%mod;

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

		f[1][j]=c[1][j];

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

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

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

				f[i][k]=(f[i][k]+f[i-1][l]*c[i][k-l])%mod;

		ans=(ans+f[n][C])%mod;

	cout<<ans;

    return 0;

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

using namespace std;

const long long Mod=1e9+7;

int n,c,l[405],r[405];

long long G[405][405],f[405][405],a[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",&l[i]);

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

	for(long long i=1;i<=400;i++){G[i][0]=1;for(int j=1;j<=400;j++) G[i][j]=(G[i][j-1]*i)%Mod;}

	for(int i=1;i<=n;i++) for(int j=0;j<=c;j++) for(int u=l[i];u<=r[i];u++) f[i][j]=(f[i][j]+G[u][j])%Mod;

	a[0][0]=1;

	for(int i=1;i<=n;i++) for(int j=0;j<=c;j++) for(int k=0;k<=j;k++) a[i][j]=(a[i][j]+a[i-1][j-k]*f[i][k])%Mod;

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

}

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

#define int long long

#define rg register

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

using namespace std;

const int mod=1e9+7;

int read(){

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

    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();

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

    return f*x;

}

int f[401][401];//第i个为j用了k颗

int a[401],b[404],c[404][404];

int ksm(int a,int b){

	int ans=1;

	while(b){

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

		a=a*a%mod;

		b>>=1;

	}

	return ans;

}

main(){

    //file("");

	int n=read(),C=read(),ans=0;

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

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

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

				c[i][k]=(c[i][k]+ksm(j,k))%mod;

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

		f[1][j]=c[1][j];

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

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

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

				f[i][k]=(f[i][k]+f[i-1][l]*c[i][k-l])%mod;

		ans=(ans+f[n][C])%mod;

	cout<<ans;

    return 0;

}
// Slower C++ solution:
/*--------------------------------

  Author: The Ace Bee

  Blog: www.cnblogs.com/zsbzsb

  This code is made by The Ace Bee

--------------------------------*/

#include <algorithm>

#include <iostream>

#include <cstring>

#include <cstdlib>

#include <cstdio>

#include <cctype>

#include <cmath>

#include <ctime>

#define rg register

using namespace std;

template < typename T > inline void read(T& s) {

	s = 0; int f = 0; char c = getchar();

	while (!isdigit(c)) f |= (c == '-'), c = getchar();

	while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();

	s = f ? -s : s;

}



typedef long long LL;

const int p = 1000000007;

const int _ = 410;



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

LL pw[_][_], f[_][_];



int main() {

	read(n), read(c);

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

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



	for (rg int i = 1; i < _; ++i) pw[i][0] = 1ll;

	for (rg int i = 1; i < _; ++i)

		for (rg int j = 1; j < _; ++j)

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

	

	for (rg int i = 1; i < _; ++i)

		for (rg int j = 0; j < _; ++j)

			pw[i][j] = (pw[i][j] + pw[i - 1][j]) % p;



	f[0][0] = 1;

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

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

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

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



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

	

	return 0;

}


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

}