stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}

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

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

typedef long long ll;

const int MAXN = 400;

const int MOD = int(1E9) + 7;

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

ll Pow[MAXN + 5][MAXN + 5], D[MAXN + 5];

ll dp[MAXN + 5][MAXN + 5];

void init() {

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

		D[i] = 1;

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

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

			Pow[i][j] = Pow[i][j-1] + D[j];

			D[j] = D[j] * j % MOD;

		}

	}

}

int main() {

	init();

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

		dp[N][i] = (Pow[i][B[N]] - Pow[i][A[N]-1] + MOD) % MOD;

	for(int i=N-1;i>=1;i--) {

		for(int j=C;j>=0;j--) {

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

				dp[i][j] = (dp[i][j] + (Pow[k][B[i]] - Pow[k][A[i]-1] + MOD) % MOD * dp[i+1][j-k]) % MOD;

			}

		}

	}

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

}

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

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

#include<cstring>

const int MAXN=405,MOD=1000000007;



int N,C;

long long mpow[MAXN][MAXN],sum[MAXN][MAXN],dp[MAXN][MAXN];

int A[MAXN],B[MAXN];



int main()

{

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

	{

		mpow[i][0]=1;

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

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

	}

	

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

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

				sum[i][j]=(sum[i][j]+mpow[k][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]+dp[i-1][j-k]*sum[k][i]%MOD)%MOD;

	

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

	

	return 0;

}


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

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

#include<cstdio>

#include<cmath>

#include<cstring>



using namespace std;

#define ll long long

#define REP(i,e,s) for(register ll i=e; i<=s; i++)

#define DREP(i,e,s) for(register ll i=e; i>=s; i--)

#define DE(...) fprintf(stderr,__VA_ARGS__)

#define DEBUG(a) DE("DEBUG: %d\n",a)

#define int ll



int read() {

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

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

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

	return x*f;

}



const int MAXN=400+10,MOD=1e9+7;



int a[MAXN],b[MAXN],_pow[MAXN][MAXN],sum[MAXN][MAXN],f[MAXN][MAXN];



signed main() {

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

	REP(i,1,n) a[i]=read();

	REP(i,1,n) b[i]=read();

	

	REP(i,1,400) {

		_pow[i][0]=1;

		REP(j,1,400) _pow[i][j]=(_pow[i][j-1]*i)%MOD;

	}



	REP(i,1,400) REP(j,0,400) sum[i][j]=(sum[i][j]+sum[i-1][j]+_pow[i][j])%MOD;

	f[0][0]=1;	

	REP(i,1,n) REP(j,0,c) REP(k,0,j) f[i][j]=(f[i][j]+f[i-1][j-k]*(sum[b[i]][k]-sum[a[i]-1][k]+MOD)%MOD)%MOD;

	

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

	return 0;

}


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

#define MAXN 400+5

using namespace std;

typedef long long LL;

LL n,c,mod=1e9+7;

LL a[MAXN],b[MAXN];

LL f[MAXN][MAXN],s[MAXN][MAXN],sum[MAXN][MAXN];

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

	{

		s[i][0]=1;

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

		{

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

		}

	}

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

	{

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

		{

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

			}

		}

	}

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

	return 0;

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

typedef long long ll;

const int MAXN = 400;

const int MOD = int(1E9) + 7;

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

ll Pow[MAXN + 5][MAXN + 5], D[MAXN + 5];

ll dp[MAXN + 5][MAXN + 5];

void init() {

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

		D[i] = 1;

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

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

			Pow[i][j] = Pow[i][j-1] + D[j];

			D[j] = D[j] * j % MOD;

		}

	}

}

int main() {

	init();

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

		dp[N][i] = (Pow[i][B[N]] - Pow[i][A[N]-1] + MOD) % MOD;

	for(int i=N-1;i>=1;i--) {

		for(int j=C;j>=0;j--) {

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

				dp[i][j] = (dp[i][j] + (Pow[k][B[i]] - Pow[k][A[i]-1] + MOD) % MOD * dp[i+1][j-k]) % MOD;

			}

		}

	}

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

}

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



using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout << fixed << setprecision(15); 

    const int mod = 1000000007; 

    int n, m; 

    cin >> n >> m; 

    vector<int> a(n + 1), b(n + 1);

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

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

    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    vector<vector<int>> pw(n + 1, vector<int>(m + 1, 0)); 

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

        vector<int> tmp(b[i] - a[i] + 1, 1);  

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

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

                pw[i][j] = (pw[i][j] + tmp[k]) % mod; 

            }

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

                tmp[k] = 1ll * tmp[k] * (k + a[i]) % mod;

            } 

        }

    } 

    dp[0][0] = 1; 

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

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

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

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

            }

    cout << dp[n][m] << endl; 

    return 0; 

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

#include<cstring>

const int MAXN=405,MOD=1000000007;



int N,C;

long long mpow[MAXN][MAXN],sum[MAXN][MAXN],dp[MAXN][MAXN];

int A[MAXN],B[MAXN];



int main()

{

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

	{

		mpow[i][0]=1;

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

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

	}

	

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

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

				sum[i][j]=(sum[i][j]+mpow[k][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]+dp[i-1][j-k]*sum[k][i]%MOD)%MOD;

	

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

	

	return 0;

}


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



using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout << fixed << setprecision(15); 

    const int mod = 1000000007; 

    int n, m; 

    cin >> n >> m; 

    vector<int> a(n + 1), b(n + 1);

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

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

    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    vector<vector<int>> pw(n + 1, vector<int>(m + 1, 0)); 

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

        vector<int> tmp(b[i] - a[i] + 1, 1);  

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

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

                pw[i][j] = (pw[i][j] + tmp[k]) % mod; 

            }

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

                tmp[k] = 1ll * tmp[k] * (k + a[i]) % mod;

            } 

        }

    } 

    dp[0][0] = 1; 

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

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

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

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

            }

    cout << dp[n][m] << endl; 

    return 0; 

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

#include<cstdio>

#include<cmath>

#include<cstring>



using namespace std;

#define ll long long

#define REP(i,e,s) for(register ll i=e; i<=s; i++)

#define DREP(i,e,s) for(register ll i=e; i>=s; i--)

#define DE(...) fprintf(stderr,__VA_ARGS__)

#define DEBUG(a) DE("DEBUG: %d\n",a)

#define int ll



int read() {

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

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

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

	return x*f;

}



const int MAXN=400+10,MOD=1e9+7;



int a[MAXN],b[MAXN],_pow[MAXN][MAXN],sum[MAXN][MAXN],f[MAXN][MAXN];



signed main() {

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

	REP(i,1,n) a[i]=read();

	REP(i,1,n) b[i]=read();

	

	REP(i,1,400) {

		_pow[i][0]=1;

		REP(j,1,400) _pow[i][j]=(_pow[i][j-1]*i)%MOD;

	}



	REP(i,1,400) REP(j,0,400) sum[i][j]=(sum[i][j]+sum[i-1][j]+_pow[i][j])%MOD;

	f[0][0]=1;	

	REP(i,1,n) REP(j,0,c) REP(k,0,j) f[i][j]=(f[i][j]+f[i-1][j-k]*(sum[b[i]][k]-sum[a[i]-1][k]+MOD)%MOD)%MOD;

	

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

	return 0;

}


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



using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout << fixed << setprecision(15); 

    const int mod = 1000000007; 

    int n, m; 

    cin >> n >> m; 

    vector<int> a(n + 1), b(n + 1);

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

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

    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    vector<vector<int>> pw(n + 1, vector<int>(m + 1, 0)); 

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

        vector<int> tmp(b[i] - a[i] + 1, 1);  

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

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

                pw[i][j] = (pw[i][j] + tmp[k]) % mod; 

            }

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

                tmp[k] = 1ll * tmp[k] * (k + a[i]) % mod;

            } 

        }

    } 

    dp[0][0] = 1; 

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

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

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

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

            }

    cout << dp[n][m] << endl; 

    return 0; 

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

#define MAXN 400+5

using namespace std;

typedef long long LL;

LL n,c,mod=1e9+7;

LL a[MAXN],b[MAXN];

LL f[MAXN][MAXN],s[MAXN][MAXN],sum[MAXN][MAXN];

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

	{

		s[i][0]=1;

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

		{

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

		}

	}

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

	{

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

		{

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

			}

		}

	}

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

	return 0;

}


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



using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout << fixed << setprecision(15); 

    const int mod = 1000000007; 

    int n, m; 

    cin >> n >> m; 

    vector<int> a(n + 1), b(n + 1);

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

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

    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    vector<vector<int>> pw(n + 1, vector<int>(m + 1, 0)); 

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

        vector<int> tmp(b[i] - a[i] + 1, 1);  

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

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

                pw[i][j] = (pw[i][j] + tmp[k]) % mod; 

            }

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

                tmp[k] = 1ll * tmp[k] * (k + a[i]) % mod;

            } 

        }

    } 

    dp[0][0] = 1; 

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

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

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

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

            }

    cout << dp[n][m] << endl; 

    return 0; 

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

using namespace std;

typedef long long ll;

const ll mod=1e9+7;

const int maxn=405;

ll c[maxn][maxn],sum[maxn][maxn];

ll a[maxn],b[maxn];

ll dp[maxn][maxn];

void init()

{

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

    {

        c[i][0]=1;c[i][1]=i;

        for(int j=2;j<maxn;j++)

        {

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

        }

    }

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

    {

        sum[0][i]=c[0][i];

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

        {

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

        }

    }

}

int main()

{

    init();

    int n,c;

    while(~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]);

        memset(dp,0,sizeof(dp));

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

                }

            }

        }

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

    }

}




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



using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout << fixed << setprecision(15); 

    const int mod = 1000000007; 

    int n, m; 

    cin >> n >> m; 

    vector<int> a(n + 1), b(n + 1);

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

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

    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    vector<vector<int>> pw(n + 1, vector<int>(m + 1, 0)); 

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

        vector<int> tmp(b[i] - a[i] + 1, 1);  

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

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

                pw[i][j] = (pw[i][j] + tmp[k]) % mod; 

            }

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

                tmp[k] = 1ll * tmp[k] * (k + a[i]) % mod;

            } 

        }

    } 

    dp[0][0] = 1; 

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

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

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

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

            }

    cout << dp[n][m] << endl; 

    return 0; 

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

using namespace std;

typedef long long ll;

const ll mod=1e9+7;

const int maxn=405;

ll c[maxn][maxn],sum[maxn][maxn];

ll a[maxn],b[maxn];

ll dp[maxn][maxn];

void init()

{

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

    {

        c[i][0]=1;c[i][1]=i;

        for(int j=2;j<maxn;j++)

        {

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

        }

    }

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

    {

        sum[0][i]=c[0][i];

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

        {

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

        }

    }

}

int main()

{

    init();

    int n,c;

    while(~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]);

        memset(dp,0,sizeof(dp));

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

                }

            }

        }

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

    }

}




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

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef unsigned int uint;

typedef pair<int,int> pii;

const int maxn=404;

const ll modn=1e9+7;

const int inf=2e9+7;

const double PI = acos(-1.0);

const double eps=1e-8;

inline int lowbit(int x){return x&-x;}

inline ll lowbit(ll x) {return x&-x;}

inline int CountOneBinary(ll num){int ans=0;while(num){if(num&1) ans+=1;num>>=1;}return ans;}

inline void read(int &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}

inline void read(ll &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}

inline ll qpow(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x%modn;x=x*x%modn;y>>=1;}return ans;}

inline double qpow(double x,ll y){double ans=1;while(y){if(y&1) ans=ans*x;x=x*x;y>>=1;}return ans;}

ll n,c,a[maxn],b[maxn],x[maxn][maxn],dp[maxn][maxn],pre[maxn][maxn];

inline ll mod(const ll &tmp)

{

    return (tmp%modn+modn)%modn;

}

int main()

{

    for(ll i=1;i<maxn;i++)

    {

        x[i][0]=1;

        x[i][1]=i;

        for(ll j=2;j<maxn;j++) x[i][j]=x[i][j-1]*i%modn;

    }

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

    {

        for(int j=0;j<maxn;j++) pre[i][j]=(pre[i-1][j]+x[i][j])%modn;

    }

    while(scanf("%lld%lld",&n,&c)==2)

    {

        memset(dp,0,sizeof(dp));dp[0][0]=1;

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

            {

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

                {

                    dp[i][j]=(dp[i][j]+dp[i-1][j-k]*mod(pre[b[i]][k]-pre[a[i]-1][k]))%modn;

                }

            }

        }

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

    }

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

using namespace std;

typedef long long ll;

const ll mod=1e9+7;

const int maxn=405;

ll c[maxn][maxn],sum[maxn][maxn];

ll a[maxn],b[maxn];

ll dp[maxn][maxn];

void init()

{

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

    {

        c[i][0]=1;c[i][1]=i;

        for(int j=2;j<maxn;j++)

        {

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

        }

    }

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

    {

        sum[0][i]=c[0][i];

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

        {

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

        }

    }

}

int main()

{

    init();

    int n,c;

    while(~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]);

        memset(dp,0,sizeof(dp));

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

                }

            }

        }

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

    }

}




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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

const int maxn = 500;

ll sum[maxn][maxn], power[maxn][maxn];

ll a[maxn], b[maxn];

ll dp[maxn][maxn];



void init() {

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

        power[i][0] = 1;

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

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

    }

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

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

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

}



int main() {

    int n, c;

    cin >> n >> c;

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

        cin >> a[i];

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

        cin >> b[i];

    init();

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

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

            }

    cout << dp[n][c];

}