#include <bits/stdc++.h>
        #include<iostream>
        #include<cstdio>
        #include<vector>
        #include<queue>
        #include<map>
        #include<cstring>
        #include<string>
        #include <math.h>
        #include<algorithm>
        #include<functional>
       #define int long long
        #define inf  1000000007
        #define pa pair<int,int>
#define ll long long
        #define pal pair<ll,ll>
        #define ppa pair<int,pa>
        #define EPS (1e-10)
        #define equals(a,b) (fabs((a)-(b))<EPS)

        using namespace std;

        class Point{
        	public:
        	double x,y;
        	Point(double x=0,double y=0):x(x),y(y) {}
        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
        	Point operator * (double a) {return Point(x*a,y*a);}
        	Point operator / (double a) {return Point(x/a,y/a);}
        	double absv() {return sqrt(norm());}
        	double norm() {return x*x+y*y;}
        	bool operator < (const Point &p) const{
        		return x != p.x ? x<p.x: y<p.y;
        	}
        	bool operator == (const Point &p) const{
        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
        	}
        };
        typedef Point Vector;

        struct Segment{
        Point p1,p2;
        };

    double hen(Vector a){
    if(fabs(a.x)<EPS && a.y>0) return acos(0);
    else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
    else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
    else if(fabs(a.y)<EPS && a.x>0) return 0.0;
    else if(a.y>0) return acos(a.x/a.absv());
    else return 2*acos(0)+acos(-a.x/a.absv());

    }

        double dot(Vector a,Vector b){
        	return a.x*b.x+a.y*b.y;
        }
        double cross(Vector a,Vector b){
        	return a.x*b.y-a.y*b.x;
        }
        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};
        //----------------kokomade temple------------
/*        
        int par[100100],ranks[100100],kosuu[100100];     

void shoki(int n){
	for(int i=0;i<n;i++){
		par[i]=i;
		ranks[i]=0;
		kosuu[i]=1;
	}
}

int root(int x){
	return par[x]==x ? x : par[x]=root(par[x]);
}

bool same(int x,int y){
return root(x)==root(y);
}

void unite(int x,int y){
 x=root(x);
 y=root(y);
 if(x==y) return;
	if(ranks[x]<ranks[y]){
		par[x]=y;
		kosuu[y]+=kosuu[x];
	}
 else {
	par[y]=x;
 	kosuu[x]+=kosuu[y];
	if(ranks[x]==ranks[y]) ranks[x]=ranks[x]+1;
 }
}

int kazu(int x){
	return kosuu[root(x)];
}
*/

ll frac[100010];
ll inv[100010];
ll mod;
ll saikif(ll a,int n){
	if (n==0) return 1;
  if(n==1) return a%mod;
  else if(n%2==0){
    ll q=saikif(a,n/2);
    return (q*q)%mod;
  }
  else return (a*saikif(a,n-1))%mod;
}

void gyakugen(){
  frac[0]=1;
  for(int i=1;i<=100000;i++) frac[i]=(frac[i-1]*i)%mod;
  for(int i=0;i<=100000;i++) inv[i]=saikif(frac[i],mod-2);
}


int rui[1000][1000];
int dp[500][500]={0};

signed main(){
	mod=inf;
	for(int i=0;i<410;i++)	rui[i][0]=0;
	for(int i=0;i<410;i++){
		for(int j=1;j<=410;j++){
			rui[i][j] = (rui[i][j-1]+saikif(j,i))%inf;
			
		}
	}

	
	int n,c;
	mod=inf;
	cin>>n>>c;
	int a[500],b[500];
	for(int i=0;i<n;i++){
		cin>>a[i+1];
	}
	for(int i=0;i<n;i++){
		cin>>b[i+1];
	}
	ll p;
	dp[1][0]=b[1]-a[1]+1;
	for(int i=2;i<=n;i++) dp[i][0]=(dp[i-1][0]*(b[i]-a[i]+1))%mod;
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		
		for(int j=1;j<=c;j++){
			
			for(int k=0;k<=j;k++){
				p=(rui[k][b[i]]-rui[k][a[i]-1]+10*mod)%mod;
		//		cout<<p<<endl;
				dp[i][j] += dp[i-1][j-k]*p;
				dp[i][j] %=mod;
				
			}
		//	cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
		}
		
	}
	
	cout<<dp[n][c]<<endl;
	
	return 0;
        }


Measured memory_bytes: 4736