### BUGGY CODE ###

import itertools
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


def ModInt(mod):
    class _ModInt:
        def __init__(self, value):
            self.value = value % mod

        def __add__(self, other):
            if isinstance(other, _ModInt):
                return _ModInt(self.value + other.value)
            else:
                return _ModInt(self.value + other)

        def __sub__(self, other):
            if isinstance(other, _ModInt):
                return _ModInt(self.value - other.value)
            else:
                return _ModInt(self.value - other)

        def __radd__(self, other):
            return self.__add__(other)

        def __mul__(self, other):
            if isinstance(other, _ModInt):
                return _ModInt(self.value * other.value)
            else:
                return _ModInt(self.value * other)

        def __truediv__(self, other):
            # TODO: 実装
            raise NotImplementedError()

        def __repr__(self):
            return str(self.value)

    return _ModInt


MI = ModInt(MOD)
# 解説AC
N, C = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))

A = np.array(A)
B = np.array(B)


def test_happy(X, counts):
    ret = 1
    for x, c in zip(X, counts):
        ret *= pow(x, c, MOD)
        ret %= MOD
    return ret


def test_f(C, X):
    N = len(X)
    ret = 0
    for sp in itertools.combinations_with_replacement(range(C + 1), N - 1):
        g = [0] + list(sp) + [C]
        counts = [g2 - g1 for g1, g2 in zip(g, g[1:])]
        ret += test_happy(X, counts)
        ret %= MOD
    return ret


def f_partial(X):
    # 部分点
    # dp[c][i]: 各項の次数が c で、i 番目の子供まで見たときの f(X) の値
    dp = np.zeros((C + 1, N), dtype=int)
    dp[0] = 1
    p = 1
    for c in range(1, C + 1):
        p = p * X[0] % MOD
        dp[c, 0] = p
    for i in range(1, N):
        for c in range(1, C + 1):
            dp[c, i] = (dp[c, i - 1] + dp[c - 1, i] * X[i]) % MOD
    return dp[C, -1]


def solve():
    # P[n][c]: n^c
    P = np.empty((B.max() + 1, C + 1), dtype=object)
    P[:] = MI(1)
    P[0] = MI(0)
    P[:, 0] = MI(1)
    for c in range(1, C + 1):
        P[:, c] = P[:, c - 1] * np.arange(len(P))

    # S[i][c]: X[i]^c (A[i]<=X[i]<=B[i]) の合計
    cs = P.cumsum(axis=0)
    S = cs[B] - cs[A - 1]

    # dp[c][i]: 各項の次数が c で、i 番目の子供まで見たときの f(X) の値
    dp = np.empty((C + 1, N), dtype=object)
    dp[:, 0] = S[0]
    for i in range(1, N):
        for c in range(C + 1):
            dp[c, i] = np.dot(dp[:c + 1, i - 1], S[i, c::-1])
    return dp[C, -1]


# print(f_partial([1, 1]))
# print(f_partial([1, 2]))
# print(f_partial([2, 1]))
# print(f_partial([2, 2]))
print(solve())


### FIXED CODE ###

import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


def ModInt(mod):
    class _ModInt:
        def __init__(self, value):
            self.value = value % mod

        def __add__(self, other):
            if isinstance(other, _ModInt):
                return _ModInt(self.value + other.value)
            else:
                return _ModInt(self.value + other)

        def __sub__(self, other):
            if isinstance(other, _ModInt):
                return _ModInt(self.value - other.value)
            else:
                return _ModInt(self.value - other)

        def __radd__(self, other):
            return self.__add__(other)

        def __mul__(self, other):
            if isinstance(other, _ModInt):
                return _ModInt(self.value * other.value)
            else:
                return _ModInt(self.value * other)

        def __truediv__(self, other):
            # TODO: 実装
            raise NotImplementedError()

        def __repr__(self):
            return str(self.value)

    return _ModInt


MI = ModInt(MOD)
# 解説AC
N, C = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))


def solve():
    # P[n][c]: n^c
    P = [[1] * (C + 1) for _ in range(max(B) + 1)]
    P[0] = [MI(0)] * (C + 1)
    for i in range(1, len(P)):
        for c in range(1, C + 1):
            P[i][c] = P[i][c - 1] * i

    # cs[n][c]: 0^c + 1^c + ... + n^c
    cs = [[0] * (C + 1) for _ in range(max(B) + 1)]
    for c in range(C + 1):
        s = 0
        for i in range(len(P)):
            s += P[i][c]
            cs[i][c] = s

    # S[i][c]: X[i]^c (A[i]<=X[i]<=B[i]) の合計
    S = [[0] * (C + 1) for _ in range(N)]
    for i in range(N):
        for c in range(C + 1):
            S[i][c] = cs[B[i]][c] - cs[A[i] - 1][c]

    # dp[c]: 各項の次数が c で、i 番目の子供まで見たときの f(X) の値
    dp = S[0][:]
    for i in range(1, N):
        for c in reversed(range(C + 1)):
            s = 0
            for j in range(c + 1):
                s += dp[c - j] * S[i][j]
            dp[c] = s
    return dp[-1]


# print(f_partial([1, 1]))
# print(f_partial([1, 2]))
# print(f_partial([2, 1]))
# print(f_partial([2, 2]))
print(solve())