#include <bits/stdc++.h>

using namespace std;

const long long r = 1e9 + 7;

long long p[401][401], sum[401][401], d[401][401];
int a[401], b[401];

int main() {
	for (int i = 1; i <= 400; ++i) {
		p[i][0] = 1;
		for (int j = 1; j <= 400; ++j)
			p[i][j] = p[i][j - 1] * i % r;
	}
	for (int i = 0; i <= 400; ++i)
		for (int j = 1; j <= 400; ++j)
			sum[i][j] = (sum[i][j - 1] + p[j][i]) % r;

	int n, c;
	scanf("%d %d", &n, &c);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &b[i]);

	d[0][0] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= c; ++j)
			for (int k = 0; k <= j; ++k)
				d[i][j] = (d[i][j] + d[i - 1][j - k] * (sum[k][b[i]] - sum[k][a[i] - 1] + r)) % r;

	printf("%lld", d[n][c]);

	return 0;
}