Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
inf = float("inf")
dp = [[inf]*100 for _ in [0]*100]
for i in range(N):dp[i][i] = 0
d = [list(map(int, input().split())) for i in range(10)]
m = [list(map(int, input().split())) for i in range(N)]
ans = 0
 
for i in range(10):
    for j in range(10):
        dp[i][j] = d[i][j]
for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
c=0

print(c)

Fixed submission:
N, M = map(int, input().split())
inf = float("inf")
dp = [[inf]*100 for _ in [0]*100]
for i in range(10):dp[i][i] = 0
d = [list(map(int, input().split())) for i in range(10)]
m = [list(map(int, input().split())) for i in range(N)]
ans = 0
 
for i in range(10):
    for j in range(10):
        dp[i][j] = d[i][j]
for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
c=0
for i in range(N):
    for j in range(M):
        if m[i][j] != 1 :
            if m[i][j] != -1 :
                c+=dp[m[i][j]][1]
print(c)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
inf = float("inf")
dp = [[inf]*100 for _ in [0]*100]
for i in range(N):dp[i][i] = 0
d = [list(map(int, input().split())) for i in range(10)]
m = [list(map(int, input().split())) for i in range(N)]
ans = 0
 
for i in range(10):
    for j in range(10):
        dp[i][j] = d[i][j]
for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
c=0
for i in range(N):
    for j in range(M):
        if m[i][j] != 1 :
            if m[i][j] != -1 :
                c+=dp[m[i][j]][1]
print(c)

Fixed submission:
N, M = map(int, input().split())
inf = float("inf")
dp = [[inf]*100 for _ in [0]*100]
for i in range(10):dp[i][i] = 0
d = [list(map(int, input().split())) for i in range(10)]
m = [list(map(int, input().split())) for i in range(N)]
ans = 0
 
for i in range(10):
    for j in range(10):
        dp[i][j] = d[i][j]
for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
c=0
for i in range(N):
    for j in range(M):
        if m[i][j] != 1 :
            if m[i][j] != -1 :
                c+=dp[m[i][j]][1]
print(c)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
inf = float("inf")
dp = [[inf]*10 for _ in [0]*10]
for i in range(N):dp[i][i] = 0
d = [list(map(int, input().split())) for i in range(10)]
m = [list(map(int, input().split())) for i in range(N)]
ans = 0
 
for i in range(10):
    for j in range(10):
        dp[i][j] = d[i][j]
for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
c=0
for i in range(N):
    for j in range(M):
        if m[i][j] != 1 :
            if m[i][j] != -1 :
                c+=dp[m[i][j]][1]
print(c)

Fixed submission:
N, M = map(int, input().split())
inf = float("inf")
dp = [[inf]*100 for _ in [0]*100]
for i in range(10):dp[i][i] = 0
d = [list(map(int, input().split())) for i in range(10)]
m = [list(map(int, input().split())) for i in range(N)]
ans = 0
 
for i in range(10):
    for j in range(10):
        dp[i][j] = d[i][j]
for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
c=0
for i in range(N):
    for j in range(M):
        if m[i][j] != 1 :
            if m[i][j] != -1 :
                c+=dp[m[i][j]][1]
print(c)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
inf = float("inf")
dp = [[inf]*10 for _ in [0]*10]
for i in range(N):dp[i][i] = 0
d = [list(map(int, input().split())) for i in range(10)]
m = [list(map(int, input().split())) for i in range(N)]
ans = 0
 
for i in range(10):
    for j in range(10):
        dp[i][j] = d[i][j]
for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
c=0
for i in range(N):
    for j in range(M):
        if m[i][j] != 1 and m[i][j] != -1 :
            c+=dp[m[i][j]][1]
print(c)

Fixed submission:
N, M = map(int, input().split())
inf = float("inf")
dp = [[inf]*100 for _ in [0]*100]
for i in range(10):dp[i][i] = 0
d = [list(map(int, input().split())) for i in range(10)]
m = [list(map(int, input().split())) for i in range(N)]
ans = 0
 
for i in range(10):
    for j in range(10):
        dp[i][j] = d[i][j]
for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
c=0
for i in range(N):
    for j in range(M):
        if m[i][j] != 1 :
            if m[i][j] != -1 :
                c+=dp[m[i][j]][1]
print(c)