#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 410, MOD = 1e9 + 7;
int dp[MAXN][MAXN], DP[MAXN], a[MAXN], b[MAXN];

int mul(int a, int b) {return (a * b) % MOD;}
int sum(int a, int b) {return (a + b) % MOD;}

int32_t main()
{
    int N, C; cin >> N >> C;
    for (int i = 1; i <= N; i++) cin >> a[i];
    for (int i = 1; i <= N; i++) cin >> b[i];
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int x = a[i]; x <= b[i]; x++) {
            memset(DP, 0, sizeof DP);
            DP[0] = dp[i - 1][0];
            for (int c = 1; c <= C; c++) DP[c] = sum(mul(DP[c - 1], x), dp[i - 1][c]);
            for (int c = 0; c <= C; c++) dp[i][c] = sum(dp[i][c], DP[c]);
        }
    }
    cout << dp[N][C] << "\n";
}
