Problem p03003 (python)

Fixed submission:
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
dpleft = [0] * (M)
MOD = 10 ** 9 + 7
ndp = [1] * (M+1)
for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            ndp[m+1] = ndp[m] + dp[m+1]
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = ndp[m] + dpleft[m]
    dp = ndp[:]
print(dp[-1] % MOD)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
dpleft = [0] * (M)
MOD = 10 ** 9 + 7
ndp = [1] * (M+1)
for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            ndp[m+1] = ndp[m] + dp[m+1]
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = ndp[m] + dpleft[m]
    dp = ndp[:]
    print(dpleft)
print(dp[-1] % MOD)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
dpleft = [0] * (M)
MOD = 10 ** 9 + 7

ndp = [1] * (M+1)
for n in range(N):
    #ndp = [1]
    for m in range(M):
        if S[n] == T[m]:
            #ndp.append(ndp[-1] + dp[m+1])
            ndp[m+1] = ndp[m] + dp[m+1]
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = ndp[m] + dpleft[m]
            #ndp.append(ndp[m] + dpleft[m])
    dp = ndp[:]
    print(dpleft)
print(dp[-1] % MOD)

Buggy submission (verdict: Runtime Error):
import copy
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
dpleft = [0] * (M)
MOD = 10 ** 9 + 7

ndp = [1] * (M+1)
for n in range(N):
    #ndp = [1]
    for m in range(M):
        if S[n] == T[m]:
            #ndp.append(ndp[-1] + dp[m+1])
            ndp[m+1] = ndp[m] + dp[m+1]
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = ndp[m] + dpleft[m]
            #ndp.append(ndp[m] + dpleft[m])
    dp = copy.deepcopy(ndp)
    print(dpleft)
print(dp[-1] % MOD)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
dpleft = [0] * (M)
MOD = 10 ** 9 + 7
ndp = [1] * (M+1)
for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            ndp[m+1] = ndp[m] + dp[m+1])
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = ndp[m] + dpleft[m]
    dp = ndp
print(dp[-1] % MOD)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
a=[1]*(m+1)
for i in range(n):
    b=a[:]
    k=0
    for j in range(m):
        b[j]=(k+b[j])%(10**9+7)
        if s[i]==t[j]:
            k=(k+a[j])%(10**9+7)
    b[-1]=(k+b[-1])%(10**9+7)
    a=b[:]
print(a[-1]%(10**9+7))
~

Buggy submission (verdict: Runtime Error):
    n,m=map(int,input().split())
    s=list(map(int,input().split()))
    t=list(map(int,input().split()))
    a=[1]*(m+1)
    for i in range(n):
        b=a[:]
        k=0
        for j in range(m):
            b[j]=(k+b[j])%(10**9+7)
            if s[i]==t[j]:
                k=(k+a[j])%(10**9+7)
        b[-1]=(k+b[-1])%(10**9+7)
        a=b[:]
    print(a[-1]%(10**9+7))