#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << x << endl;
#else 
    #define dbg(x)
#endif

#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 410;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int C[MX][MX];
int a[MX];
int b[MX];

int add(int a, int b) {
    a += b;
    if (a >= MOD)
        return a - MOD;
    return a;
}

int sub(int a, int b) {
    a -= b;
    if (a < 0)
        return a + MOD;
    return a;
}

int mult(int a, int b) {
    return a * b % MOD;
}


int dp[MX][MX];
int sum[MX][MX];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    fi(1, MX) {
        int pw = 1;
        fj(0, MX) {
            sum[j][i] = add(sum[j][i - 1], pw);
            pw = mult(pw, i);
        }
    }
   /* dbg(sum[0][1]);
    dbg(sum[1][1]);
    dbg(sum[2][1]);
    dbg(sum[3][1]);*/
    int ans = 0;
    int n, c;
    cin >> n >> c;
    fi(1, n + 1) cin >> a[i];
    fi(1, n + 1) cin >> b[i];
    dp[0][0] = 1;
    fi(1, n + 1) {
        //dbg(i);
        rep(from, 0, c + 1) {
            rep(to, from, c + 1) {
                int pw = to - from;
                int s = sub(sum[pw][b[i]], sum[pw][a[i] - 1]);
                dp[i][to] = add(dp[i][to], mult(dp[i - 1][from], s));
            }
        }
        /*dbg(dp[i][0]);
        dbg(dp[i][1]);
        dbg(dp[i][2]);
        dbg(dp[i][3]);*/
    }   
    cout << dp[n][c] << '\n';
}

Measured memory_bytes: 6140