In AtCoder Kindergarten, there are N children numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to the children. Each child's happiness is determined by the number of candies they receive, based on their excitement level. The activity level of the kindergarten is the product of the happiness of all N children. The task is to calculate the sum of the activity levels for all possible ways to distribute C candies. The input consists of N, C, and arrays A and B. The output should be the value of a specific function modulo 10^9+7. The constraints are 1≤N≤400, 1≤C≤400, and 1≤A_i≤B_i≤400 (1≤i≤N). The problem has a partial score of 400 points for passing the test set satisfying A_i=B_i (1≤i≤N). The input format is N C A_1 A_2 ... A_N B_1 B_2 ... B_N, and the output is the value of a specific function modulo 10^9+7. The problem also includes sample inputs and outputs for illustration.

# Buggy version:
for _ in range(test_case):
import sys
from itertools import accumulate
readline = sys.stdin.readline
MOD = 10**9+7

N, C = map(int, readline().split())
A = [0] + list(map(int, readline().split()))
B = [0] + list(map(int, readline().split()))

acsq = [list(accumulate([pow(i, j, MOD) for i in range(max(B)+1)])) for j in range(C+1)]
dp = [[0]*(C+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1, N+1):
    a, b = A[i], B[i]
    for c in range(C+1):
        res = 0
        for j in range(c+1):
            res = (res + (acsq[c-j][b] - acsq[c-j][a-1])*dp[i-1][j]) % MOD
        dp[i][c] = res
print(dp[N][C])

# Fixed version:
import sys
from itertools import accumulate
readline = sys.stdin.readline
MOD = 10**9+7

N, C = map(int, readline().split())
A = [0] + list(map(int, readline().split()))
B = [0] + list(map(int, readline().split()))

acsq = []
lb = max(B)+1
for j in range(C+1):
    ac = [0]*lb
    ac[0] = 1
    for i in range(1, lb):
        ac[i] = (ac[i-1] + pow(i, j, MOD)) % MOD
    acsq.append(ac)
dp = [[0]*(C+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1, N+1):
    a, b = A[i], B[i]
    for c in range(C+1):
        res = 0
        for j in range(c+1):
            res = (res + (acsq[c-j][b] - acsq[c-j][a-1])*dp[i-1][j]) % MOD
        dp[i][c] = res
print(dp[N][C])

# Buggy version:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

MOD = pow(10, 9) + 7

def main():
    n, c = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    assert(a==b)
    dp = [[0 for _ in range(c+1)] for _ in range(n+1)]
    for i in range(n+1):
        dp[i][0] = 1
    pow_table = [[1 for _ in range(401)] for _ in range(n)]
    for i in range(1, 401):
        for j in range(n):
            pow_table[j][i] = pow_table[j][i-1]*a[j]%MOD
    
    for i in range(1, n+1):
        for j in range(1, c+1):
            for k in range(j+1):
                dp[i][j] += dp[i-1][j-k] * pow_table[i-1][k] % MOD
                if dp[i][j] >= MOD:
                    dp[i][j] -= MOD
    print(dp[n][c])


if __name__ == '__main__':
    main()


# Fixed version:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

MOD = pow(10, 9) + 7

def main():
    n, c = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    
    pow_table = [[0 for _ in range(401)] for _ in range(401)]
    # pow_table[i][j]: i^j
    for i in range(1, 401):
        pow_table[i][0] = 1
    
    for i in range(1, 401):
        for j in range(1, 401):
            pow_table[i][j] = pow_table[i][j-1] * i % MOD
    for i in range(1, 401):
        for j in range(401):
            pow_table[i][j] += pow_table[i-1][j]
            if pow_table[i][j] >= MOD:
                pow_table[i][j] -= MOD
    
    dp = [[0 for _ in range(c+1)] for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(1, n+1):
        for j in range(c+1):
            for k in range(j+1):
                ab = pow_table[b[i-1]][k] - pow_table[a[i-1]-1][k]
                if ab < 0:
                    ab += MOD
                dp[i][j] += dp[i-1][j-k] * ab % MOD
                if dp[i][j] >= MOD:
                    dp[i][j] -= MOD

    print(dp[n][c])


if __name__ == '__main__':
    main()

# Buggy version:
MOD = 10**9 + 7
n, m = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]

cumsum = [[1] * 410 for _ in range(410)]
for order in range(405):
    for i in range(1, 405):
        cumsum[order][i] = pow(i, order, MOD) + cumsum[order][i-1]
        cumsum[order][i] %= MOD

dp = [[0] * (m + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
    dp[i+1][0] = b[i] - a[i] + 1
for i in range(1, n+1):
    for j in range(1, m+1):
        for k in range(j+1):
            l = a[i - 1]
            r = b[i - 1]
            # print(j-k)
            x = (cumsum[j-k][r] - cumsum[j-k][l-1] + MOD) % MOD
            dp[i][j] += dp[i-1][k] * x 
        dp[i][j] %= MOD

print(dp[-1][-1])

# Fixed version:
MOD = 10**9 + 7
n, m = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]

cumsum = [[1] * 410 for _ in range(410)]
for order in range(405):
    for i in range(1, 405):
        cumsum[order][i] = pow(i, order, MOD) + cumsum[order][i-1]
        cumsum[order][i] %= MOD

dp = [[0] * (m + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(1, n+1):
    for j in range(0, m+1):
        for k in range(j+1):
            l = a[i - 1]
            r = b[i - 1]
            x = (cumsum[j-k][r] - cumsum[j-k][l-1] + MOD) % MOD
            dp[i][j] += dp[i-1][k] * x 
        dp[i][j] %= MOD

print(dp[-1][-1])