#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

#define MAX 2007
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void fact() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; ++i){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long comb(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
// mod. m での a の逆元 a^{-1} を計算する
//ただしmとaが互いにその時のみ
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
vector<vector<ll>> mpow(401, vector<ll>(401, 0));
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    return mpow[a][n];
}

// a^n mod を計算する
long long modpow2(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

inline void calc(){
    for(ll i=0;i<401;++i)
        for(ll j=0;j<401;++j){
            mpow[i][j]=modpow2(i,j,MOD);
        }
}
#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    calc();
    fact();
    ll N;
    cin >> N;
    ll C;
    cin >> C;
    vector<ll> A(N,0);
    vector<ll> B(N,0);
    for(ll i=0;i<N;++i)cin>>A[i];
    for(ll i=0;i<N;++i)cin>>B[i];
    //dp[i][j]は右i以降だけ見てj個配ったとき
    vector<vector<ll>> dp(N, vector<ll>(C+1, 0));
    for(ll i=0;i<=C;++i){
        for(ll j=A[N-1];j<=B[N-1];++j){
            dp[N-1][i]+=modpow(j,i,MOD);
            dp[N-1][i]%=MOD;
        }
    }
    for(ll i=N-2;i>=0;--i){
        vector<ll> zyou(C+1,0);
        for(ll k=0;k<=C;++k){ 
            for(ll j=A[i];j<=B[i];++j){
                zyou[k]+=modpow(j,k,MOD);
                zyou[k]%=MOD;
            }
        }
        for(ll k=0;k<=C;++k){
            for(ll j=0;j<=k;++j){
                dp[i][k]+=dp[i+1][j]*zyou[k-j]%MOD;
                dp[i][k]%=MOD;
            }
        }
    }

    prt(dp[0][C]);


    return 0;
}



Measured memory_bytes: 5840