qyliang/CodeNanoFix huggingface dataset:
Buggy code:
S = input().rstrip()
plus_minus = [1, -1]
A = int(S[0])
for i in plus_minus:
    total = int(S[0])
    B = i*int(S[1])
    for j in plus_minus:
        C = j*int(S[2])
        for k in plus_minus:
            D = k*int(S[3])
            total += B+C+D
            if total == 7:
                if B >= 0:
                    B = "+" + str(B)
                if C >= 0:
                    C = "+" + str(C)
                if D >= 0:
                    D = "+" + str(D)
                answer = str(A) + str(B) + str(C) + str(D) + "=7"
                print(answer)
                exit()

Fixed code:
S = input().rstrip()
plus_minus = [1, -1]
A = int(S[0])
for i in plus_minus:
    B = i*int(S[1])
    for j in plus_minus:
        C = j*int(S[2])
        for k in plus_minus:
            D = k*int(S[3])
            total = A+B+C+D
            if total == 7:
                if B >= 0:
                    B = "+" + str(B)
                if C >= 0:
                    C = "+" + str(C)
                if D >= 0:
                    D = "+" + str(D)
                answer = str(A) + str(B) + str(C) + str(D) + "=7"
                print(answer)
                exit()
Buggy code:
S = input()
opt = ['+', '-']

for i in opt:
    for j in opt:
        for k in opt:
            temp = S[0] + i + S[1] + j + S[2] + k + S[3]
            ans = eval(temp)
            if ans == 7:
                print(''.join(list(temp)), end = '')
                print('=7')
                break

Fixed code:
S = input()
opt = ['+', '-']

flag = 1
if flag:
    for i in opt:
        if flag:
            for j in opt:
                if flag:
                    for k in opt:
                        temp = S[0] + i + S[1] + j + S[2] + k + S[3]
                        ans = eval(temp)
                        if ans == 7:
                            flag = 0
                            break
                    
print(''.join(list(temp)), end = '')
print('=7')
Buggy code:
A = input()

def f(x):
    if x % 2 == 0:
        return 1
    else:
        return -1

B = []
for i in range(8):
    if int(A[0]) + f(i//4) * int(A[1]) + f(i//2) * int(A[2]) + f(i) * int(A[3]) == 7:
        if f(i//4) == 1:
            B.append('+')
        else:
            B.append('-')
        if f(i//2) == 1:
            B.append('+')
        else:
            B.append('-')
        if f(i) == 1:
            B.append('+')
        else:
            B.sppend('-')
        flag = 1
        break
        
if flag == 1:
    print('{}{}{}{}{}{}{}{}'.format(A[0], B[0], A[1], B[1], A[2], B[2], A[3], '=7'))

Fixed code:
A = input()

def f(x):
    if x % 2 == 0:
        return 1
    else:
        return -1

B = []
for i in range(8):
    if int(A[0]) + f(i//4) * int(A[1]) + f(i//2) * int(A[2]) + f(i) * int(A[3]) == 7:
        if f(i//4) == 1:
            B.append('+')
        else:
            B.append('-')
        if f(i//2) == 1:
            B.append('+')
        else:
            B.append('-')
        if f(i) == 1:
            B.append('+')
        else:
            B.append('-')
        flag = 1
        break
        
if flag == 1:
    print('{}{}{}{}{}{}{}{}'.format(A[0], B[0], A[1], B[1], A[2], B[2], A[3], '=7'))
Buggy code:
S = input()
if int(S[0])+int(S[1])+int(S[2])+int(S[3])==7:
    print(f'{S[0]}+{S[1]}+{S[2]}+{S[3]}==7')
elif int(S[0])+int(S[1])+int(S[2])-int(S[3])==7:
    print(f'{S[0]}+{S[1]}+{S[2]}-{S[3]}==7')
elif int(S[0])+int(S[1])-int(S[2])+int(S[3])==7:
    print(f'{S[0]}+{S[1]}-{S[2]}+{S[3]}==7')
elif int(S[0])-int(S[1])+int(S[2])+int(S[3])==7:
    print(f'{S[0]}-{S[1]}+{S[2]}+{S[3]}==7')
elif int(S[0])+int(S[1])-int(S[2])-int(S[3])==7:
    print(f'{S[0]}+{S[1]}-{S[2]}-{S[3]}==7')
elif int(S[0])-int(S[1])+int(S[2])-int(S[3])==7:
    print(f'{S[0]}-{S[1]}+{S[2]}-{S[3]}==7')
elif int(S[0])-int(S[1])-int(S[2])+int(S[3])==7:
    print(f'{S[0]}-{S[1]}-{S[2]}+{S[3]}==7')
else:
    print(f'{S[0]}-{S[1]}-{S[2]}-{S[3]}==7')

Fixed code:
S = input()
if int(S[0])+int(S[1])+int(S[2])+int(S[3])==7:
    print(f'{S[0]}+{S[1]}+{S[2]}+{S[3]}=7')
elif int(S[0])+int(S[1])+int(S[2])-int(S[3])==7:
    print(f'{S[0]}+{S[1]}+{S[2]}-{S[3]}=7')
elif int(S[0])+int(S[1])-int(S[2])+int(S[3])==7:
    print(f'{S[0]}+{S[1]}-{S[2]}+{S[3]}=7')
elif int(S[0])-int(S[1])+int(S[2])+int(S[3])==7:
    print(f'{S[0]}-{S[1]}+{S[2]}+{S[3]}=7')
elif int(S[0])+int(S[1])-int(S[2])-int(S[3])==7:
    print(f'{S[0]}+{S[1]}-{S[2]}-{S[3]}=7')
elif int(S[0])-int(S[1])+int(S[2])-int(S[3])==7:
    print(f'{S[0]}-{S[1]}+{S[2]}-{S[3]}=7')
elif int(S[0])-int(S[1])-int(S[2])+int(S[3])==7:
    print(f'{S[0]}-{S[1]}-{S[2]}+{S[3]}=7')
else:
    print(f'{S[0]}-{S[1]}-{S[2]}-{S[3]}=7')
Buggy code:
def dfs(i, s, sum):
    if i == 3:
        if sum == 7:
            print(s + "=7")
            exit()
    dfs(i + 1, s + "+" + abcd[i + 1], sum + int(abcd[i + 1]))
    dfs(i + 1, s + "-" + abcd[i + 1], sum - int(abcd[i + 1]))
abcd = input()
dfs(0, abcd[0], int(abcd[0]))

Fixed code:
def dfs(i, s, sum):
    if i == 3:
        if sum == 7:
            print(s + "=7")
            exit()
    else:
        dfs(i + 1, s + "+" + abcd[i + 1], sum + int(abcd[i + 1]))
        dfs(i + 1, s + "-" + abcd[i + 1], sum - int(abcd[i + 1]))
abcd = input()
dfs(0, abcd[0], int(abcd[0]))
Buggy code:
n = input()

def dfs(i, f, s):
    if i == 3:
        if s==7:
            return f+"=7"
    return dfs(i+1, f+"+"+n[i+1], s+int(n[i+1])) or dfs(i+1, f+"-"+n[i+1], s-int(n[i+1]))

print(dfs(0, n[0], int(n[0])))

Fixed code:
n = input()

def dfs(i, f, s):
    if i == 3:
        if s==7:
            return f+"=7"
        else:
            return ''
    return dfs(i+1, f+"+"+n[i+1], s+int(n[i+1])) or dfs(i+1, f+"-"+n[i+1], s-int(n[i+1]))

print(dfs(0, n[0], int(n[0])))
Buggy code:
a, b, c, d = [int(i) for i in input()]
ops = ["+++", "++-", "+-+", "+--", "-++", "-+-", "--+", "---"]


for op in ops:
    s = a
    print(op)
    for i, n in enumerate([b, c, d]):
        op = list(op)
        if op[i] == "+":
            s += n
        else:
            s -= n
    if s == 7:
        print(str(a) + op[0] + str(b) + op[1] + str(c) + op[2] + str(d) + "=7")
        break

Fixed code:
a, b, c, d = [int(i) for i in input()]
ops = ["+++", "++-", "+-+", "+--", "-++", "-+-", "--+", "---"]

for op in ops:
    s = a
    for i, n in enumerate([b, c, d]):
        op = list(op)
        if op[i] == "+":
            s += n
        else:
            s -= n
    if s == 7:
        print(str(a) + op[0] + str(b) + op[1] + str(c) + op[2] + str(d) + "=7")
        break
Buggy code:
l=[int(x) for x in list(input())]
if l[0]+l[1]+l[2]+l[3]==7: print('{}+{}+{}+{}=7'.format(l[0],l[1],l[2],l[3])
elif l[0]+l[1]+l[2]-l[3]==7: print('{}+{}+{}-{}=7'.format(l[0],l[1],l[2],l[3])
elif l[0]+l[1]-l[2]+l[3]==7: print('{}+{}-{}+{}=7'.format(l[0],l[1],l[2],l[3])
elif l[0]+l[1]-l[2]-l[3]==7: print('{}+{}-{}-{}=7'.format(l[0],l[1],l[2],l[3])
elif l[0]-l[1]+l[2]+l[3]==7: print('{}-{}+{}+{}=7'.format(l[0],l[1],l[2],l[3])
elif l[0]-l[1]+l[2]-l[3]==7: print('{}-{}+{}-{}=7'.format(l[0],l[1],l[2],l[3])
elif l[0]-l[1]-l[2]+l[3]==7: print('{}-{}-{}+{}=7'.format(l[0],l[1],l[2],l[3])
elif l[0]-l[1]-l[2]-l[3]==7: print('{}-{}-{}-{}=7'.format(l[0],l[1],l[2],l[3])


Fixed code:
l=[int(x) for x in list(input())]
if l[0]+l[1]+l[2]+l[3]==7: print('{}+{}+{}+{}=7'.format(l[0],l[1],l[2],l[3]))
elif l[0]+l[1]+l[2]-l[3]==7: print('{}+{}+{}-{}=7'.format(l[0],l[1],l[2],l[3]))
elif l[0]+l[1]-l[2]+l[3]==7: print('{}+{}-{}+{}=7'.format(l[0],l[1],l[2],l[3]))
elif l[0]+l[1]-l[2]-l[3]==7: print('{}+{}-{}-{}=7'.format(l[0],l[1],l[2],l[3]))
elif l[0]-l[1]+l[2]+l[3]==7: print('{}-{}+{}+{}=7'.format(l[0],l[1],l[2],l[3]))
elif l[0]-l[1]+l[2]-l[3]==7: print('{}-{}+{}-{}=7'.format(l[0],l[1],l[2],l[3]))
elif l[0]-l[1]-l[2]+l[3]==7: print('{}-{}-{}+{}=7'.format(l[0],l[1],l[2],l[3]))
elif l[0]-l[1]-l[2]-l[3]==7: print('{}-{}-{}-{}=7'.format(l[0],l[1],l[2],l[3]))
Buggy code:
import re
s = input()

def sum_p(res, i):
    if i == 3:
        res += s[i]
        a = sum(list(map(int, re.split('[+, *]', res))))
        if a == 7:
            res = res.replace("*", "")
            print(res+"=7")
    elif i == 0:
        res1 = res+s[i]+"+"
        sum_p(res1, i+1)
        res2 = res+s[i]+"*"+"-"
        sum_p(res2, i+1)
    else:
        sum_p(res+s[i]+"+", i+1)
        sum_p(res+s[i]+"*"+"-", i+1)

sum_p("", 0)

Fixed code:
import re
s = input()
ans = []

def sum_p(res, i):
    if i == 3:
        res += s[i]
        a = sum(list(map(int, re.split('[+, *]', res))))
        if a == 7:
            res = res.replace("*", "")
            ans.append(res+"=7")
    elif i == 0:
        res1 = res+s[i]+"+"
        sum_p(res1, i+1)
        res2 = res+s[i]+"*"+"-"
        sum_p(res2, i+1)
    else:
        sum_p(res+s[i]+"+", i+1)
        sum_p(res+s[i]+"*"+"-", i+1)

sum_p("", 0)
print(ans[0])
Buggy code:
import sys
N = list(map(int, input()))
op = ['+','-']
for i in op:
    tmp = 0 
    ans = []
    for j in op:
        for k in op:
            if i == '+':
                tmp = N[0] + N[1]
                ans.append('+')
            else:
                tmp = N[0] - N[1]
                ans.append('-')

            if j == '+':
                tmp += N[2]
                ans.append('+')
            else:
                tmp -= N[2]    
                ans.append('-')

            print(k)
            if k == '+':
                tmp += N[3]
                ans.append('+')
            else:
                tmp -= N[3]
                ans.append('-')

            if tmp == 7:
                print(str(N[0])+ans[0]+str(N[1])+ans[1]+str(N[2])+ans[2]+str(N[3])+"=7")
                sys.exit()
            else:
                tmp = 0
                ans = []

Fixed code:
import sys
N = list(map(int, input()))
op = ['+','-']
for i in op:
    tmp = 0 
    ans = []
    for j in op:
        for k in op:
            if i == '+':
                tmp = N[0] + N[1]
                ans.append('+')
            else:
                tmp = N[0] - N[1]
                ans.append('-')

            if j == '+':
                tmp += N[2]
                ans.append('+')
            else:
                tmp -= N[2]    
                ans.append('-')

            if k == '+':
                tmp += N[3]
                ans.append('+')
            else:
                tmp -= N[3]
                ans.append('-')

            if tmp == 7:
                print(str(N[0])+ans[0]+str(N[1])+ans[1]+str(N[2])+ans[2]+str(N[3])+"=7")
                sys.exit()
            else:
                tmp = 0
                ans = []
Buggy code:
nums = list(map(int, list(input())))

flag = 7
while flag >= 0:
    S = []
    total = nums[0]
    for i, bit in enumerate(bin(flag)[2:], 1):
        if int(bit):
            total += nums[i]
            S.append("+")
        else:
            total -= nums[i]
            S.append("-")
    if total == 7:
        break
    
    flag -= 1

print(f"{nums[0]}{S[0]}{nums[1]}{S[1]}{nums[2]}{S[2]}{nums[3]}=7")

Fixed code:
nums = list(map(int, list(input())))

flag = 7
while flag >= 0:
    S = []
    total = nums[0]
    bin_str = format(flag, "03b")
    for i, bit in enumerate(bin_str, 1):
        if int(bit):
            total += nums[i]
            S.append("+")
        else:
            total -= nums[i]
            S.append("-")
    if total == 7:
        break
    
    flag -= 1
print(f"{nums[0]}{S[0]}{nums[1]}{S[1]}{nums[2]}{S[2]}{nums[3]}=7")
Buggy code:
import copy

H,W = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(10)]
cntA = {}
for _ in range(H):
  for a in map(int,input().split()):
    if a not in cntA:
      cntA[a] = 1
    else:
      cntA[a] += 1

dp = copy.deepcopy(C)

for j in range(10):
  for i in range(10):
    for k in range(10):
      dp[i][j] = min(dp[i][j], dp[i][k]+C[k][j])
      
ans = 0
for key, num in cntA.items():
  if key not in [-1,1]:
    ans += dp[key][1]*num
print(ans)

Fixed code:
H,W = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(10)]
cntA = {}
for _ in range(H):
  for a in map(int,input().split()):
    if a not in cntA:
      cntA[a] = 1
    else:
      cntA[a] += 1

for k in range(10):
  for i in range(10):
    for j in range(10):
      C[i][j] = min(C[i][j], C[i][k]+C[k][j])
      
ans = 0
for key, num in cntA.items():
  if key not in [-1,1]:
    ans += C[key][1]*num
print(ans)
Buggy code:
# python3
# utf-8

import itertools

rows_nr, cols_nr = (int(x) for x in input().split())
d1___d2___cost = []
for i in range(10):
    d1___d2___cost_i___j = [int(x) for x in input().split()]
    d1___d2___cost.append(d1___d2___cost_i___j)
r_c___value = []
for row in range(rows_nr):
    c___value = [int(x) for x in input().split()]
    r_c___value.append(c___value)

f = d1___d2___cost
for i, v, u in itertools.product(range(10), repeat=3):
    f[u][v] = min(f[u][v], f[u][i] + f[i][v])
ans = 0
for row in r_c___value:
    for value in row:
        if value == '-1':
            continue
        ans += f[value][1]
print(ans)


Fixed code:
# python3
# utf-8

import itertools

rows_nr, cols_nr = (int(x) for x in input().split())
d1___d2___cost = []
for i in range(10):
    d1___d2___cost_i___j = [int(x) for x in input().split()]
    d1___d2___cost.append(d1___d2___cost_i___j)
r_c___value = []
for row in range(rows_nr):
    c___value = [int(x) for x in input().split()]
    r_c___value.append(c___value)

f = d1___d2___cost
for i, v, u in itertools.product(range(10), repeat=3):
    f[u][v] = min(f[u][v], f[u][i] + f[i][v])
ans = 0
for row in r_c___value:
    for value in row:
        if value == -1:
            continue
        ans += f[value][1]
print(ans)
Buggy code:
# 078-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
h,w=IL()
c=[IL() for i in range(10)]
a=[IL() for i in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])
    
ans=0
for i in range(h):
    for j in range(w):
        if a[i][j]==-1:
            continue
        ans+=c[a[i][j]][1]

Fixed code:
# 078-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
h,w=IL()
c=[IL() for i in range(10)]
a=[IL() for i in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])
    
ans=0
for i in range(h):
    for j in range(w):
        if a[i][j]==-1:
            continue
        ans+=c[a[i][j]][1]
print(ans)
Buggy code:
h,w=map(int,input().split())
ans=[float("inf") for i in range(10)]
p=[]
a=[]
for i in range(10):
    p.append(list(map(int,input().split())))
for i in range(h):
    a.append(list(map(int,input().split())))
for i in range(10):
    for j in range(10):
        for k in range(10):
            p[j][k]=min(p[j][i]+p[i][k],p[j][k])
ans=float("inf")
for i in range(10):
    tmp=0
    for j in range(h):
        for k in range(w):
            if a[j][k]!=-1:
                tmp+=p[a[j][k]][i]
    if tmp<ans:
        ans=tmp
print(ans)

Fixed code:
h,w=map(int,input().split())
ans=[float("inf") for i in range(10)]
p=[]
a=[]
for i in range(10):
    p.append(list(map(int,input().split())))
for i in range(h):
    a.append(list(map(int,input().split())))
for i in range(10):
    for j in range(10):
        for k in range(10):
            p[j][k]=min(p[j][i]+p[i][k],p[j][k])
ans=float("inf")
tmp=0
for j in range(h):
    for k in range(w):
        if a[j][k]!=-1:
            tmp+=p[a[j][k]][1]
print(tmp)
Buggy code:
h,w=map(int,input().split())
ll=[list(map(int,input().split())) for i in range(10)]

for i in range(10**3-1):
    for i in range(10):
        for j in range(10):
            if i!=j:
                ll[i][j]=min(ll[i][j],min(ll[i][o]+tra[o][j] for o in range(10) if o!=i and o!=j))
ans=0
for i in range(h):
    for j in map(int,input().split()):
        if j==-1 or j==1:continue
        ans+=ll[j][1]
print(ans)

Fixed code:
h,w=map(int,input().split())
tra=[list(map(int,input().split())) for i in range(10)]
ll=[[tra[i][j] for j in range(10)] for i in range(10)]
for i in range(10**3-1):
    for i in range(10):
        for j in range(10):
            if i!=j:
                ll[i][j]=min(ll[i][j],min(ll[i][o]+tra[o][j] for o in range(10) if o!=i and o!=j))
ans=0
for i in range(h):
    for j in map(int,input().split()):
        if j==-1 or j==1:continue
        ans+=ll[j][1]
print(ans)
Buggy code:

def search(start: int, visited: list, power: list, min_power: int, min_powers: int) -> int:
    minimum = 10**4
    if min_powers[start] != -1:
        return min_powers[start] + min_power
    if visited[1] == True:
        #print(f'{min_power=}')
        return min_power
    for i, v in enumerate(visited):
        if not v:
            visited[i] = True
            min_power += power[start][i]

            #min_powers[i] = search(i,visited,power,min_power,min_powers)
            minimum = min(minimum, search(i,visited,power,min_power,min_powers))

            visited[i] = False
            min_power -= power[start][i]
            #print(f'{minimum=}')
    return minimum


H, W = map(int, input().split())

power = [[] for _ in range(10)]

for i in range(10):
    power[i] = list(map(int, input().split()))

world = [[] for _ in range(H)]

for i in range(H):
    world[i] = list(map(int, input().split()))

min_powers = [-1] * 10
visited = [False] * 10

#print(f'{power[8][4]=}')
for i in range(10):
    min_power = 0
    visited[i] = True
    min_powers[i] = search(i,visited,power,min_power,min_powers)
    visited[i] = False
    #visited = [False] * 10
for i in range(10):
    #pass
    print(f'{i=}, {min_powers[i]=}')
ans = 0
for wor in world:
    for w in wor:
        if w != -1:
            ans += min_powers[w]

print(ans)


Fixed code:

def search(start: int, visited: list, power: list, min_power: int, min_powers: int) -> int:
    minimum = 10**4
    if min_powers[start] != -1:
        return min_powers[start] + min_power
    if visited[1] == True:
        #print(f'{min_power=}')
        return min_power
    for i, v in enumerate(visited):
        if not v:
            visited[i] = True
            min_power += power[start][i]

            #min_powers[i] = search(i,visited,power,min_power,min_powers)
            minimum = min(minimum, search(i,visited,power,min_power,min_powers))

            visited[i] = False
            min_power -= power[start][i]
            #print(f'{minimum=}')
    return minimum


H, W = map(int, input().split())

power = [[] for _ in range(10)]

for i in range(10):
    power[i] = list(map(int, input().split()))

world = [[] for _ in range(H)]

for i in range(H):
    world[i] = list(map(int, input().split()))

min_powers = [-1] * 10
visited = [False] * 10

#print(f'{power[8][4]=}')
for i in range(10):
    min_power = 0
    visited[i] = True
    min_powers[i] = search(i,visited,power,min_power,min_powers)
    visited[i] = False
    #visited = [False] * 10
for i in range(10):
    pass
    #print(f'{i=}, {min_powers[i]=}')
ans = 0
for wor in world:
    for w in wor:
        if w != -1:
            ans += min_powers[w]

print(ans)
Buggy code:
#dp=[[0 for j in range(10)] for i in range(10)]
import numpy as np

h,w=map(int,input().split())
dp=np.zeros((10,10))
for i in range(10):
    s=list(map(int,input().split()))
    for j in range(10):
        dp[i][j]=s[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(h):
    s=list(map(int,input().split()))
    for j in range(w):
        if s[j]!=-1 and s[j]!=1:
            c+=dp[s[j]][1]
print(c)


Fixed code:
dp=[[0 for j in range(10)] for i in range(10)]
import numpy as np

h,w=map(int,input().split())
dp=np.array(dp)
for i in range(10):
    s=list(map(int,input().split()))
    for j in range(10):
        dp[i][j]=s[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(h):
    s=list(map(int,input().split()))
    for j in range(w):
        if s[j]!=-1 and s[j]!=1:
            c+=dp[s[j]][1]
print(c)
Buggy code:
h,w = map(int,input().split())
C = [list(map(int,input().split())) for i in range(10)]
A = [list(map(int,input().split())) for i in range(h)]
INF = float('inf')
cost = 0
D = [[INF]*10 for i in range(10)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            D[i][j] = min(C[i][j],C[i][k]+C[k][j])

for y in range(h):
    for x in range(w):
        if A[y][x] == -1 or A[y][x] == 1:
            continue
        else:
            cost += D[A[y][x]][1]
print(cost)


Fixed code:
h,w = map(int,input().split())
C = [list(map(int,input().split())) for i in range(10)]
A = [list(map(int,input().split())) for i in range(h)]
inf = float('inf')
cost = 0
D = [[inf]*10 for i in range(10)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            D[i][j] = min(C[i][j],C[i][k]+C[k][j])
for k in range(10):
    for i in range(10):
        for j in range(10):
            D[i][j] = min(D[i][j],D[i][k]+D[k][j])

for y in range(h):
    for x in range(w):
        if A[y][x] == -1 or A[y][x] == 1:
            continue
        else:
            cost += D[A[y][x]][1]

print(cost)
Buggy code:
H,W = map(int, input().split())
c, A = [], []
num = [0] * 10
for _ in range(10):
    ci = list(map(int, input().split()))
    ci[0], ci[1] = ci[1], ci[0]
    c.append(ci)
for _ in range(H):
    A += list(map(int, input().split()))
for i in [0] + list(range(2, 10)):
    num[i] += A.count(i)

c = [[0]] + c[:1] + c[2:]
num[0], num[1] = num[1], num[0]

dp = [[10000 for i in range(10)] for j in range(10)]
dp[1][1] = c[1][0]
for i in range(2, 10):
    dp[i][i] = min(c[i][0], min(c[i][j] + dp[i-1][j] for j in range(i-1, 0, -1)))
    for j in range(1, i):
        dp[i][j] = min(dp[i-1][j], c[j][i] + dp[i][i])

print(sum(dp[9][i] * num[i] for i in range(1,10)))

Fixed code:
H,W = map(int, input().split())
c, A = [], []
num = [0] * 10
for _ in range(10):
    ci = list(map(int, input().split()))
    ci[0], ci[1] = ci[1], ci[0]
    c.append(ci)
for _ in range(H):
    A += list(map(int, input().split()))
for i in [0] + list(range(2, 10)):
    num[i] += A.count(i)

c = [[0]] + c[:1] + c[2:]
num[0], num[1] = num[1], num[0]

dp = [[c[i][0] for i in range(10)]] + [[10000 for i in range(10)] for j in range(9)]
for i in range(1, 10):
    for j in range(1, 10):
            dp[i][j] = min(c[j][k] + dp[i-1][k] for k in range(1, 10))

print(sum(dp[9][i] * num[i] for i in range(1,10)))
Buggy code:
h,w=map(int, input().split())
c=[list(map(int, input().split())) for i in range(10)]
al=[list(map(int, input().split())) for i in range(h)]
ans=0
for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])
for i in al:
    for j in i:
        ans+=c[j][1]
print(ans)

Fixed code:
h,w=map(int, input().split())
c=[list(map(int, input().split())) for i in range(10)]
al=[list(map(int, input().split())) for i in range(h)]
ans=0
for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])
ans=0
for i in al:
    for j in i:
        if j==-1:continue
        ans+=c[j][1]
print(ans)