#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = ll(1e9 + 7);

int A[500], B[500];
ll p[500][500]; // pow(x, y)
ll table[410][500];
ll dp[410][500];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	for(int i = 0; i < 500; i++) {
		p[i][0] = 1;
		for(int j = 1; j < 500; j++) {
			p[i][j] = (p[i][j - 1] * i) % MOD;
		}
	}

	int N, C;
	cin >> N >> C;
	for(int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for(int i = 0; i < N; i++) {
		cin >> B[i];
	}

	dp[0][0] = 1;
	for(int i = 0; i < N; i++) {
		for(int c = 0; c <= C; c++) {
			ll sum = 0;
			for(int x = A[i]; x <= B[i]; x++) {
				sum = (sum + p[x][c]) % MOD;
			}
			table[i][c] = sum;
		}
		for(int j = 0; j <= C; j++) {
			for(int c = 0; j + c <= C; c++) {
				dp[i + 1][j + c] = (dp[i + 1][j + c] + dp[i][j] * table[i][c] % MOD) % MOD;
			}
		}
	}
	cout << dp[N][C] << endl;
}