Problem p04027 (python)

Fixed submission:
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()))
    # 部分点
    # 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):
    #             dp[i][j] += dp[i-1][j-k]*pow(a[i-1], k, MOD)
    #             if dp[i][j] >= MOD:
    #                 dp[i][j] -= MOD
    abc = [[0 for _ in range(401)] for _ in range(401)]
    # abc[i][j]: j**i
    for i in range(401):
        abc[0][i] = 1
    abc[0][0] = 0
    for i in range(1, 401):
        for j in range(1, 401):
            abc[j][i] = abc[j-1][i] * i % MOD
    
    for i in range(1, 401):
        for j in range(401):
            abc[j][i] += abc[j][i-1]
            if abc[j][i] >= MOD:
                abc[j][i] -= 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):
                accm = abc[k][b[i-1]] - abc[k][a[i-1]-1]
                if accm < 0:
                    accm += MOD
                dp[i][j] += dp[i-1][j-k] * accm % MOD
                if dp[i][j] >= MOD:
                    dp[i][j] -= MOD
    
    print(dp[n][c])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
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()

Buggy submission (verdict: Runtime Error):
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) % MOD
    print(dp[n][c])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
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
    
    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(a[i-1], k, MOD)) % MOD
    print(dp[n][c])


if __name__ == '__main__':
    main()