#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll commemo[1000][1000];
ll dp[500][500];
ll bsum[500][500];

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

int main()
{
    ll n, c;
    cin >> n >> c;
    ll a[500], b[500];
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) cin >> b[i];
    for(int j = 0; j <= c; j++){
        for(int i = 1; i <= 400; i++){
            bsum[i][j] = (bsum[i - 1][j] + modpow(i, j)) % 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][k] * ((bsum[b[i]][j - k] + MOD - bsum[a[i] - 1][j - k])) % MOD) % MOD;
            }
        }
    }
    cout << dp[n][c] << endl;
}