Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import numpy as np
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = np.zeros(c+1, dtype=np.int64)
    dp[0] = 1
    p = np.array([[pow(j, i, mod) for j in range(401)]
                  for i in range(401)], dtype=np.int64)
    for a, b in zip(A, B):
        q = np.sum(p[:, a:b+1], axis=1) % mod
        dp = np.array([sum(dp[i::-1]*q[:i+1] % mod)
                       for i in range(c+1)], dtype=np.int64) % mod
    print(dp[-1] % mod)


main()

Fixed submission:
def main():
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = [0]*(c+1)
    dp[0] = 1
    ans = 0

    p = [[0]*(401) for _ in [0]*401]  # p[i][j]でj^i
    for i in range(401):
        for j in range(401):
            p[i][j] = pow(j, i, mod)

    for a, b in zip(A, B):
        dp2 = [0]*(c+1)
        q = [0]*(c+1)
        for i in range(c+1):
            q[i] = sum(p[i][a:b+1]) % mod
        for i in range(c+1):
            temp = 0
            for j in range(i+1):
                temp += dp[i-j]*q[j]
            dp2[i] = temp % mod
        dp = dp2
    ans += dp[-1]
    print(ans % mod)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import numpy as np
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = np.zeros(c+1, dtype=np.int64)
    dp[0] = 1
    p = np.array([[pow(j, i, mod) for j in range(401)]
                  for i in range(401)], dtype=np.int64)
    for a, b in zip(A, B):
        q = np.sum(p[:, a:b+1], axis=1) % mod
        dp = [sum(dp[i::-1]*q[:i+1] % mod) % mod for i in range(c+1)]
    print(dp[-1] % mod)


main()

Fixed submission:
def main():
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = [0]*(c+1)
    dp[0] = 1
    ans = 0

    p = [[0]*(401) for _ in [0]*401]  # p[i][j]でj^i
    for i in range(401):
        for j in range(401):
            p[i][j] = pow(j, i, mod)

    for a, b in zip(A, B):
        dp2 = [0]*(c+1)
        q = [0]*(c+1)
        for i in range(c+1):
            q[i] = sum(p[i][a:b+1]) % mod
        for i in range(c+1):
            temp = 0
            for j in range(i+1):
                temp += dp[i-j]*q[j]
            dp2[i] = temp % mod
        dp = dp2
    ans += dp[-1]
    print(ans % mod)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = [0]*(c+1)
    dp[0] = 1
    ans = 0
    p = [[pow(j, i, mod) for j in range(401)] for i in range(401)]

    for a, b in zip(A, B):
        q = [sum(p[i][a:b+1]) % mod for i in range(c+1)]
        dp = [sum([dp[i-j]*q[j] for j in range(i+1)]) %
              mod for i in range(c+1)]
    ans += dp[-1]
    print(ans % mod)


main()


Fixed submission:
def main():
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = [0]*(c+1)
    dp[0] = 1
    ans = 0

    p = [[0]*(401) for _ in [0]*401]  # p[i][j]でj^i
    for i in range(401):
        for j in range(401):
            p[i][j] = pow(j, i, mod)

    for a, b in zip(A, B):
        dp2 = [0]*(c+1)
        q = [0]*(c+1)
        for i in range(c+1):
            q[i] = sum(p[i][a:b+1]) % mod
        for i in range(c+1):
            temp = 0
            for j in range(i+1):
                temp += dp[i-j]*q[j]
            dp2[i] = temp % mod
        dp = dp2
    ans += dp[-1]
    print(ans % mod)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = [0]*(c+1)
    dp[0] = 1
    ans = 0
    for a, b in zip(A, B):
        dp2 = [0]*(c+1)
        p = [sum([pow(x, i, mod) for x in range(a, b+1)]) %
             mod for i in range(c+1)]
        for i in range(c+1):
            dp2[i] = sum([dp[i-j]*p[j] for j in range(i+1)]) % mod
        dp = dp2
    ans += dp[-1]
    print(ans % mod)


main()

Fixed submission:
def main():
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = [0]*(c+1)
    dp[0] = 1
    ans = 0

    p = [[0]*(401) for _ in [0]*401]  # p[i][j]でj^i
    for i in range(401):
        for j in range(401):
            p[i][j] = pow(j, i, mod)

    for a, b in zip(A, B):
        dp2 = [0]*(c+1)
        q = [0]*(c+1)
        for i in range(c+1):
            q[i] = sum(p[i][a:b+1]) % mod
        for i in range(c+1):
            temp = 0
            for j in range(i+1):
                temp += dp[i-j]*q[j]
            dp2[i] = temp % mod
        dp = dp2
    ans += dp[-1]
    print(ans % mod)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = [0]*(c+1)
    dp[0] = 1
    ans = 0
    for a, b in zip(A, B):
        dp2 = [0]*(c+1)
        p = [sum([pow(x, i, mod) for x in range(a, b+1)]) %
             mod for i in range(c+1)]
        for i in range(c+1):
            dp2[i] = sum([dp[i-j]*p[j] for j in range(i+1)]) % mod
        dp = dp2
    ans += dp[-1]
    print(ans % mod)


main()

Fixed submission:
def main():
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = [0]*(c+1)
    dp[0] = 1
    ans = 0

    p = [[0]*(401) for _ in [0]*401]  # p[i][j]でj^i
    for i in range(401):
        for j in range(401):
            p[i][j] = pow(j, i, mod)

    for a, b in zip(A, B):
        dp2 = [0]*(c+1)
        q = [0]*(c+1)
        for i in range(c+1):
            q[i] = sum(p[i][a:b+1]) % mod
        for i in range(c+1):
            temp = 0
            for j in range(i+1):
                temp += dp[i-j]*q[j]
            dp2[i] = temp % mod
        dp = dp2
    ans += dp[-1]
    print(ans % mod)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = [0]*(c+1)
    dp[0] = 1
    ans = 0
    for a, b in zip(A, B):
        dp2 = [0]*(c+1)
        p = [0]*(c+1)
        for i in range(c+1):
            temp = 0
            for x in range(a, b+1):
                temp += pow(x, i, mod)
            p[i] = temp % mod
        for i in range(c+1):
            for j in range(i+1):
                temp = 0
                dp2[i] += dp[i-j]*p[j]
            dp2[i] = dp2[i] % mod
        dp = dp2
    ans += dp[-1]
    print(ans % mod)


main()

Fixed submission:
def main():
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = [0]*(c+1)
    dp[0] = 1
    ans = 0

    p = [[0]*(401) for _ in [0]*401]  # p[i][j]でj^i
    for i in range(401):
        for j in range(401):
            p[i][j] = pow(j, i, mod)

    for a, b in zip(A, B):
        dp2 = [0]*(c+1)
        q = [0]*(c+1)
        for i in range(c+1):
            q[i] = sum(p[i][a:b+1]) % mod
        for i in range(c+1):
            temp = 0
            for j in range(i+1):
                temp += dp[i-j]*q[j]
            dp2[i] = temp % mod
        dp = dp2
    ans += dp[-1]
    print(ans % mod)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = [0]*(c+1)
    dp[0] = 1
    ans = 0
    for a, b in zip(A, B):
        dp2 = [0]*(c+1)
        p = [0]*(c+1)
        for i in range(c+1):
            temp = 0
            for x in range(a, b+1):
                temp += pow(x, i, mod)
            p[i] = temp % mod
        for i in range(c+1):
            for j in range(i+1):
                temp = 0
                dp2[i] += dp[i-j]*p[j]
            dp2[i] = dp2[i] % mod
        dp = dp2
    ans += dp[-1]
    print(ans % mod)


main()

Fixed submission:
def main():
    mod = 10**9+7
    n, c = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    dp = [0]*(c+1)
    dp[0] = 1
    ans = 0

    p = [[0]*(401) for _ in [0]*401]  # p[i][j]でj^i
    for i in range(401):
        for j in range(401):
            p[i][j] = pow(j, i, mod)

    for a, b in zip(A, B):
        dp2 = [0]*(c+1)
        q = [0]*(c+1)
        for i in range(c+1):
            q[i] = sum(p[i][a:b+1]) % mod
        for i in range(c+1):
            temp = 0
            for j in range(i+1):
                temp += dp[i-j]*q[j]
            dp2[i] = temp % mod
        dp = dp2
    ans += dp[-1]
    print(ans % mod)


main()