#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
const  int mod = 1e9 + 7;
/*
 
First f(x1, x2,...,xN) is specifically considered to have a meaningful value. Kindergarten activities
Considering the power formula, the distribution of C candies to N people depends on the variable xi.
It seems to be what variable is assigned to which degree in the polynomial (total degree is C)
It Then f becomes the collection of N-ary C-ary monomials.
(Example: If N=3,C=3 and put x=x1,y=x2,z=x3 for easy viewing,
f(x,y,z)=x3+y3+z3+x2y+x2z+y2x+y2z+z2x+z2y+xyz)
First, consider the partial points. x1,x2,...,xN are given (as Ai=Bi), so f(x1,x2,...,xN)
You should do it.
Since N and C are large, we cannot enumerate all monomials. Consider the following DP
Get dp[i][j]= "sum of monomial values ​​of degree j using variables x1 to xi"
Using the previous example,

Actually, this value is held instead of the expression.
dp[N][C] is the answer.
To calculate dp, first set dp[0][0]=1 and the transition is dp[i+1][j]= sum {dp[i][j-k]* xik} (k=0~j)
Becomes (That is, depending on how many orders are used in the variable xi)
Then, the calculation amount is O(NC2), and N=C=400, so it is in time.
The same DP is used for the perfect score method.

To consider the value of ΣΣ・・・Σf (written as above for simplicity), first, the degree of xi is ci
The monomial Πxi
Considering what happens when Σ is taken for ci, ΣΣ・・・Σ (Πxici) = Π (Σxici)
(Π is i=1 to N). (Example: ΣΣ(x2y) = (Σx2) * (Σy) )That is, add each variable separately
It will be the same as the product after combining them. This expands the expression that actually takes the product
It can be understood from the fact that each term of Σ of the original monomial comes out.
Then, in the end, the coefficient to be multiplied when the k-th order is consumed by xi in the DP equation of the partial points is given by xi
From k,Aik + (Ai+1)k + ・・・ + Bi
If you change to k, you can get the answer even if the score is perfect. In advance, nature
If you want to calculate the cumulative sum of 0 to C power of number up to 400, which is the upper limit of Ai.Bi (call it X),
Since the coefficient of is obtained by O(1), this previous calculation is O(CX) and DP is O(NC2), after all
O(CX + NC2) Will give you the answer.

*/
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

vector<ll> mult(vector<ll>& a, vector<ll>& b){
	int n = (int)a.size();
	vector<ll> c(n);
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j+i < n ; j++){
			c[i+j]+=a[i]*b[j];
			c[i+j]%=mod;
		}
	}
	return c;
}

void test_case(){
	int n , c; cin >> n >> c;
	vector<ll> a(n),b(n);
	for(auto &x:a)
		cin >> x;
	for(auto &x:b)
		cin >> x;
	vector<vector<ll>> hash(n,vector<ll>(c+1,0));
	for(int i = 0 ; i < n ; i++){
		hash[i][0] = b[i] - a[i] + 1;
		for(int j = 1 ; j <= c ; j++){
			for(int k = a[i] ; k <= b[i] ; k++){
				hash[i][j]+=binpow(k,j,mod);
			}
			hash[i][j]%=mod;
		}
	}
	for(int i = 1 ; i < n ; i++){
		hash[i] = mult(hash[i-1],hash[i]);
	}
	cout<<hash[n-1][c] <<"\n";
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 1536