Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
li = [[] for i in range(n)]

for i in range(n-1):
  a,b,dist = map(int,input().split())
  li[a-1].append((b-1,dist))
  li[b-1].append((a-1,dist))

q,k = map(int,input().split())
tdp = [-1]*n
tdp[k-1] = 0

def dfs(x):
  for node in li[x]:
    if tdp[node[0]] == -1:
      tdp[node[0]] = tdp[x] + node[1]
      dfs(node[0])

dfs(k-1)
for i in range(q):
  a,b = map(int,input().split())
  print(tdp[a-1]+tdp[b-1])

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
n = int(input())
li = [[] for i in range(n)]

for i in range(n-1):
  a,b,dist = map(int,input().split())
  li[a-1].append((b-1,dist))
  li[b-1].append((a-1,dist))

q,k = map(int,input().split())
tdp = [-1]*n
tdp[k-1] = 0

def dfs(x):
  for node in li[x]:
    if tdp[node[0]] == -1:
      tdp[node[0]] = tdp[x] + node[1]
      dfs(node[0])

dfs(k-1)
for i in range(q):
  a,b = map(int,input().split())
  print(tdp[a-1]+tdp[b-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
cnt = d = 0 
z = []
while True:
  cnt += 1
  if a[d] == 2:
    print(cnt)
    break
  elif a[d] in z:
    print(-1)
    break
  else:
    z.append(a[d])
    d = a[d] - 1


Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
cnt = d = 0 
while True:
  cnt += 1
  if a[d] == 2:
    print(cnt)
    break
  elif cnt >= 10**5:
    print(-1)
    break
  else:
    d = a[d] - 1
Buggy python submission (verdict: Runtime Error):
n = int(input())
an = [int(i) for i in input().split()]
score = [0]*9
ans = 0

for i in an:
  score[i//400] += 1

for i in score[:8]:
  if i:
    ans += 1
print(ans,ans+score[8])

Fixed submission:
input()
an = [int(i) for i in input().split()]
score = [0]*13
ans = 0

for i in an:
  score[i//400] += 1   
for i in score[:8]:
  if i:
    ans += 1

k = sum(score[8:])

if ans == 0 and k:
  print(1,k)
else:
  print(ans,ans+k)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())

if a == b == c:
  if a%2 = 0:
    print(-1)
    exit()
  else:
    print(0)
    exit()
ans = 0
while(a%2 == b%2 == c%2 == 0):
  temp_a = (b+c)//2
  temp_b = (a+c)//2
  temp_c = (b+a)//2
  ans += 1
  a = temp_a
  b = temp_b
  c = temp_c
print(ans)

Fixed submission:
a,b,c = map(int,input().split())

if a == b == c:
  if a%2 == 0:
    print(-1)
    exit()
  else:
    print(0)
    exit()
ans = 0
while(a%2 == b%2 == c%2 == 0):
  temp_a = (b+c)//2
  temp_b = (a+c)//2
  temp_c = (b+a)//2
  ans += 1
  a = temp_a
  b = temp_b
  c = temp_c
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
b = a[:]
s1 = s2 = 0
for i in range(n):
  c = sum(a[0:i+1])
  if (i % 2 == 0 and c <= 0):
    s1 += abs(c) + 1
    a[i] += abs(c) + 1
  elif(i % 2 == 1 and c >= 0):
    s1 += abs(c) + 1
    a[i] -= abs(c) + 1
for i in range(n):
  c = sum(b[0:i+1])
  if (i % 2 == 0 and c >= 0):
    s2 += abs(c) + 1
    b[i] -= abs(c) + 1
  elif (i % 2 == 1 and c <= 0):
    s2 += abs(c) + 1
    b[i] += abs(c) + 1
print(min(s1,s2))

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
s1 = s2 = su = 0
for i in range(n):
  su += a[i]
  if (i % 2 == 0 and su <= 0):
    s1 += abs(su) + 1
    su = 1
  elif(i % 2 == 1 and su >= 0):
    s1 += abs(su) + 1
    su = -1
su = 0
for i in range(n):
  su += a[i]
  if (i % 2 == 0 and su >= 0):
    s2 += abs(su) + 1
    su = -1
  elif (i % 2 == 1 and su <= 0):
    s2 += abs(su) + 1
    su = 1
print(min(s1,s2))
Buggy python submission (verdict: Runtime Error):
a = input()
a = a.split(" ")
for num in range(3):
    a[num] = int(a[num])
sum = sum(a)
if sum >= 22:
    print("bust")
else:
    print(win)

Fixed submission:
a = input()
a = a.split(" ")
sum = 0
for num in a:
    sum += int(num)
if sum >= 22:
    print("bust")
else:
    print("win")

Buggy python submission (verdict: Runtime Error):
a = input()
a = a.split(" ")
for num in range(3):
    a[num] = int(a[num])
sum = sum(a)
if sum >= 22:
    print("bust")]
else:
    print(win)

Fixed submission:
a = input()
a = a.split(" ")
sum = 0
for num in a:
    sum += int(num)
if sum >= 22:
    print("bust")
else:
    print("win")
Buggy python submission (verdict: Runtime Error):
S = list(input())
final_str = []
for key in S: 
    if key == "B":
      final_str = final_str[:-1]
    else:
      final_str.append(key)
print(''.join(final_str)

Fixed submission:
S = list(input())
final_str = []
for key in S: 
    if key == "B":
      final_str = final_str[:-1]
    else:
      final_str.append(key)
print(''.join(final_str))

Buggy python submission (verdict: Runtime Error):
S = list(input())
for key in S: 
    if key == "B":
      final_str = final_str[:-1]
    else:
      final_str.append(key)
print(''.join(final_str)

Fixed submission:
S = list(input())
final_str = []
for key in S: 
    if key == "B":
      final_str = final_str[:-1]
    else:
      final_str.append(key)
print(''.join(final_str))
Buggy python submission (verdict: Time Limit Exceeded):
import math

n,m = map(int,input().split())

a = sorted(list(map(int,input().split())),reverse=True)

for _ in range(m):
    #print(a)
    a[0] = a[0]/2
    i = 0
    #print("->{}".format(a))
    while i<n-1:
        if a[i]<a[i+1]:
            a[i],a[i+1] = a[i+1],a[i]
            i+=1
        else:
            break
    #print("->->{}".format(a))

a = list(map(math.floor,a))
#print()
#print(a)

print(sum(a))

Fixed submission:
import math
import heapq

n,m = map(int,input().split())

a = list(map(int,input().split()))
a = list(map(lambda x:x*(-1),a))
heapq.heapify(a)

for _ in range(m):
    max = heapq.heappop(a)
    max = max/2
    heapq.heappush(a,max)

a = list(map(lambda x:x*(-1),a))
a = list(map(math.floor,a))

print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
import math

n,m = map(int,input().split())

a = list(map(int,input().split()))

for _ in range(m):
    maxv = a.index(max(a))
    a[maxv] = a[maxv]/2

a = list(map(math.floor,a))

print(sum(a))

Fixed submission:
import math
import heapq

n,m = map(int,input().split())

a = list(map(int,input().split()))
a = list(map(lambda x:x*(-1),a))
heapq.heapify(a)

for _ in range(m):
    max = heapq.heappop(a)
    max = max/2
    heapq.heappush(a,max)

a = list(map(lambda x:x*(-1),a))
a = list(map(math.floor,a))

print(sum(a))
Buggy python submission (verdict: Runtime Error):
n = int(input())

print((n(n-1)//2))

Fixed submission:
n = int(input())

print((n*(n-1)//2))

Buggy python submission (verdict: Runtime Error):
n = int(input())

print(sum(list(range(n))))

Fixed submission:
n = int(input())

print((n*(n-1)//2))

Buggy python submission (verdict: Runtime Error):
n = int(input())

p = list(reversed(list(range(1,n+1))))

r = set(range(1,n+1))

m = []

for i in range(n):
    f = True
    a = 1
    b = 1
    while f:
        while (a*p[i]-b)<=n and f:
            if a*p[i]-b in r:
                r.remove(a*p[i]-b)
                m.append((a*p[i]-b)%p[i])
                f = False
                break
            a += 1
        b += 1

print(sum(m))


Fixed submission:
n = int(input())

print((n*(n-1)//2))
Buggy python submission (verdict: Runtime Error):
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = [l for l in A if l != maxa]

maxa2 = max(copy)

for i in A:
    if i == maxa:
        print(maxa2)
    else:
        print(maxa)

Fixed submission:
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = A[:]

copy.remove(maxa)

maxa2 = max(copy)

for i in A:
    if i == maxa:
        print(maxa2)
    else:
        print(maxa)

Buggy python submission (verdict: Runtime Error):
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = [l for l in A if l != maxa]

maxa2 = max(copy)

for i in A:
    if i == max:
        print(maxa2)
    else:
        print(maxa)

Fixed submission:
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = A[:]

copy.remove(maxa)

maxa2 = max(copy)

for i in A:
    if i == maxa:
        print(maxa2)
    else:
        print(maxa)

Buggy python submission (verdict: Runtime Error):
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = A[:]

while True:
    if maxa in copy:
        copy.remove(maxa)
    else:
        break

maxa2 = max(copy)

for i in A:
    if i == max:
        print(maxa2)
    else:
        print(maxa)

Fixed submission:
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = A[:]

copy.remove(maxa)

maxa2 = max(copy)

for i in A:
    if i == maxa:
        print(maxa2)
    else:
        print(maxa)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

for i in A:
    copy = A[:]
    copy.remove(i)
    print(max(copy))

Fixed submission:
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = A[:]

copy.remove(maxa)

maxa2 = max(copy)

for i in A:
    if i == maxa:
        print(maxa2)
    else:
        print(maxa)
Buggy python submission (verdict: Runtime Error):
n = int(input())

print((n(n-1)//2))

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

ans = 0
for i in range(n):
    if i%2==0:
        ans += a[i]
    else:
        ans -= a[i]

print(ans)
Buggy python submission (verdict: Runtime Error):
yukichi = -1
higuchi = -1
noguchi = -1


def check(n,y,a,b,c):

    if y/1000 == n:
        global yukichi,higuchi,noguchi
        yukichi = a
        higuchi = b
        noguchi = n

    else:
        if y>=0:
            check(n-1,y-10000,a+1,b,c)
            check(n-1,y-5000,a,b+1,c)


n,y = map(int,input().split())

check(n,y,0,0,0)

print("{} {} {}".format(yukichi,higuchi,noguchi))

Fixed submission:
n,y = map(int,input().split())
yukichi = -1
higuchi = -1
noguchi = -1
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            yukichi = i
            higuchi = j
            noguchi = n-i-j

print("{} {} {}".format(yukichi,higuchi,noguchi))

Buggy python submission (verdict: Runtime Error):
yukichi = -1
higuchi = -1
noguchi = -1


def check(n,y,a,b,c):
    if n==0:
        if y==0:
            global yukichi,higuchi,noguchi
            yukichi = a
            higuchi = b
            noguchi = c
            
    else:
        check(n-1,y-10000,a+1,b,c)
        check(n-1,y-5000,a,b+1,c)
        check(n-1,y-1000,a,b,c+1)


n,y = map(int,input().split())

check(n,y,0,0,0)

print("{} {} {}".format(yukichi,higuchi,noguchi))


Fixed submission:
n,y = map(int,input().split())
yukichi = -1
higuchi = -1
noguchi = -1
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            yukichi = i
            higuchi = j
            noguchi = n-i-j

print("{} {} {}".format(yukichi,higuchi,noguchi))
Buggy python submission (verdict: Runtime Error):
flag = False
def check(sen,l,s):
    if len(sen)<l:
        check(sen+"dream",l,s)
        check(sen+"dreamer",l,s)
        check(sen+"erase",l,s)
        check(sen+"eraser",l,s)
    else:
        if sen==s:
            global flag
            flag = True

s = input()

check("",len(s),s)

if flag:
    print("YES")
else:
    print("NO")


Fixed submission:
import re
s = input()
m = re.fullmatch(r"(dreamer|dream|erase|eraser)+", s)

if m:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
flag = False
def check(sen,l,s):
    if len(sen)<l:
        check(sen+"dream",l,s)
        check(sen+"dreamer",l,s)
        check(sen+"erase",l,s)
        check(sen+"eraser",l,s)
    else:
        if sen==s:
            global flag
            flag = True

s = input()

check("",len(s),s)

if flag:
    print("yes")
else:
    print("no")

Fixed submission:
import re
s = input()
m = re.fullmatch(r"(dreamer|dream|erase|eraser)+", s)

if m:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
flag = False
def check(sen,l,s):
    if len(sen)<l:
        check(sen+"dream",l,s)
        check(sen+"dreamer",l,s)
        check(sen+"erase",l,s)
        check(sen+"eraser",l,s)
    else:
        if sen==s:
            global flag
            flag = True

s = input()

check("",len(s),s)

if flag:
    print("yes")
else:
    print("no")

Fixed submission:
import re
s = input()
m = re.fullmatch(r"(dreamer|dream|erase|eraser)+", s)

if m:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy

N =int(input())
Ws = np.array([int(i) for i in input().split(" ")])

sub = np.sum(Ws)
# print("sub絶対値：{}".format(abs(sub)))
pre_sub = sub
for W in Ws:
  sub = sub - W*2
#   print("sub絶対値：{}".format(abs(sub)))
#   print("sub={}".format(sub))
  if abs(pre_sub) < abs(sub):
#     print("{}が最小".format(pre_sub))
    print(abs(pre_sub))
    break
  pre_sub = sub

Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np

N =int(input())
Ws = [int(i) for i in input().split(" ")]

sub_W = np.sum(Ws)
pre_sub = sub_W
for W in Ws:
  sub_W = sub_W - W*2
  if abs(pre_sub) < abs(sub_W):
    print(abs(pre_sub))
    break
  pre_sub = sub_W
Buggy python submission (verdict: Runtime Error):
D=["SUN","MON","TUE","WED","THU","FRY","SAT"]
S=input()

print(7-D.index(S))

Fixed submission:
D=["SUN","MON","TUE","WED","THU","FRI","SAT"]
S=input()

print(7-D.index(S))

Buggy python submission (verdict: Runtime Error):
D=["SUN","MON","TUE","WED","THU","FRY","SAT"]
S=input()

print(7-D.index(S))

Fixed submission:
D=["SUN","MON","TUE","WED","THU","FRI","SAT"]
S=input()

print(7-D.index(S))

Buggy python submission (verdict: Runtime Error):
D=["SUN","MON","TUE","WED","THU","FRY","SAT"]
S=input(int())

print(7-D.index(S))

Fixed submission:
D=["SUN","MON","TUE","WED","THU","FRI","SAT"]
S=input()

print(7-D.index(S))

Buggy python submission (verdict: Runtime Error):
D=["SUN","MON","TUE","WED","THU","FRY","SAT"]
S=input(int())

print(7-D.index(D))

Fixed submission:
D=["SUN","MON","TUE","WED","THU","FRI","SAT"]
S=input()

print(7-D.index(S))
Buggy python submission (verdict: Runtime Error):
import math

r=input(int())


print(math.pi*r*r/math.pi)

Fixed submission:
r=int(input())
print(r*r)
Buggy python submission (verdict: Runtime Error):
A=int(input())
B=int(input())

C=A*B

if C>81:
	print(-1)
elif C<1:
	print(-1)
else:
	print(C)

Fixed submission:
A,B=map(int,input().split())

if A<10 and B<10:
	print(A*B)
else:
	print(-1)

Buggy python submission (verdict: Runtime Error):
A=int(input())
B=int(input())

C=A*B

if C>81:
	print("-1")
elif C<1:
	print("-1")
else:
	print(C)

Fixed submission:
A,B=map(int,input().split())

if A<10 and B<10:
	print(A*B)
else:
	print(-1)
Buggy python submission (verdict: Runtime Error):
N=int(input())

if N%2==0:
	print(1/2)
else:
	print((n+1)/2)

Fixed submission:
N=int(input())

if N%2==0:
	print(1/2)
else:
	print((N+1)/(2*N))

Buggy python submission (verdict: Runtime Error):
n, k = input().split()
n = int(n) #友人の数
k = int(k) #基準の高さ
h = input().split()
result = 0
#各人の身長を基準の高さと比較
for i in range(n):
  if k <= int(h[i]):
    result += 1
  else:
    result -= 0
print(result)

Fixed submission:
N = input()
N = int(N)
if N%2 == 0:
  import math
  a = N/2/N  
  print('{:.6f}'.format(a))
else :
  a = (N+1)/2/N
  print('{:.6f}'.format(a))

Buggy python submission (verdict: Runtime Error):
n, k = input().split()
n = int(n) #友人の数
k = int(k) #基準の高さ
m = []
result = 0
for i in range(n):
  m.append(int(input()))
#各人の身長を基準の高さと比較
for i in range(len(m)):
  if k <= m[i]:
    result += 1
  else:
    result += 0
print(result)

Fixed submission:
N = input()
N = int(N)
if N%2 == 0:
  import math
  a = N/2/N  
  print('{:.6f}'.format(a))
else :
  a = (N+1)/2/N
  print('{:.6f}'.format(a))

Buggy python submission (verdict: Runtime Error):
n, k = input().split()
n = int(n) #友人の数
k = int(k) #基準の高さ
m = []
result = 0
for i in range(n):
  m.append(int(input().split()))
#各人の身長を基準の高さと比較
for i in range(len(m)):
  if k <= m[i]:
    result += 1
  else:
    result += 0
print(result)

Fixed submission:
N = input()
N = int(N)
if N%2 == 0:
  import math
  a = N/2/N  
  print('{:.6f}'.format(a))
else :
  a = (N+1)/2/N
  print('{:.6f}'.format(a))
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if c > (a - b):
	print(c - (a - b)
else:
    print(0)

Fixed submission:
a, b, c = map(int, input().split())
if c > (a - b):
	print(c - (a - b))
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
a, b, c = int(input().split())
x = c - (a - b)
print(x)


Fixed submission:
a, b, c = map(int, input().split())
if c > (a - b):
	print(c - (a - b))
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
a, b, c = int(input().split())
print(c - (a - b))


Fixed submission:
a, b, c = map(int, input().split())
if c > (a - b):
	print(c - (a - b))
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
a = int(input())

if a < 10:
  print(a)
elif a < 100:
  print(9)
elif a < 1000:
  print(a - 90)
elif a < 10000:
  print(910)
elif a < 100000:
  print(a - 90 - 9000)
elif a = 100000:
  print(90909)

Fixed submission:
a = int(input())

if a < 10:
  print(a)
elif a < 100:
  print(9)
elif a < 1000:
  print(a - 90)
elif a < 10000:
  print(909)
elif a < 100000:
  print(a - 90 - 9000)
elif a == 100000:
  print(90909)
Buggy python submission (verdict: Runtime Error):
N = int(input())
monster = list(map(int, input().split()))
hero = list(map(int, input().split()))

total = 0
i = -1

for i in range(N + 1):
    if i == 0:
        if monster[0] < hero[0]:
            total += monster[0]
            hero[0] -= monster[0]
            monster[0] = 0
        else:
            total += hero[0]
            monster[0] -= hero[0]
            hero[0] = 0
            
    elif i < N:
        if monster[i] < hero[i - 1]:
            total += monster[i]
            hero[i - 1] -= monster[i]
            monster[i] = 0
        else:
            total += hero[i - 1]
            monster[i] -= hero[i - 1]
            hero[i - 1] = 0
            
            if monster[i] < hero[i]:
                total += monster[i]
                hero[i] -= monster[i]
                monster[i] = 0
            else:
                total += hero[i]
                hero[i] = 0
                monster[i] -= hero[i]
    else:
        if monster[N] < hero[N - 1]:
            total += monster[N]
        else:
            total += hero[N - 1]

print(total)


Fixed submission:
a, b = map(int, input().split())

if a > b:
    c = b
    b = a
    a = c
    
if (b - a) % 2 == 1:
    print('IMPOSSIBLE')
else:
    print((b + a) // 2)

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

if a > b:
    c = b
    b = a
    a = c
    
if (b - a) % 2 == 1:
    print(IMPOSSIBLE)
else:
    print((b + a) // 2)

Fixed submission:
a, b = map(int, input().split())

if a > b:
    c = b
    b = a
    a = c
    
if (b - a) % 2 == 1:
    print('IMPOSSIBLE')
else:
    print((b + a) // 2)
Buggy python submission (verdict: Runtime Error):
h, w = [int(i) for i in input().split()]
k = []
wl = []
  
for i in range(0, 10):
  k.append([int(i) for i in input().split()])
for i in range(0, h):
  wl.append([int(i) for i in input().split()])


n = {1:0}

while len(n) < 10:
  c = 1000
  mn = 10
  for a in n.keys():
    a2 = int(a)
    for b in range(0, 10):
      if not b in n:
        if k[b][a2] + n[a] < c:
          c = k[b][a2] + n[a]
          mn = b
  n[mn] = c

ans = 0
for a in range(0, h):
  for b in range(0, w):
    if wl[a][b] != -1:
      ans += n[wl[a][b]]

print(ans)
      

Fixed submission:
s = input()
if s[1] == s[2] and s[2] == s[3]:
  print("Yes")
else:
  if s[0] == s[1] and s[1] == s[2]:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
h, w = [int(i) for i in input().split()]
k = []
wl = []
  
for i in range(0, 10):
  k.append([int(i) for i in input().split()])
for i in range(0, h):
  wl.append([int(i) for i in input().split()])
 
 
n = {1:0}
 
while len(n) < 10:
  c = 1000
  mn = 10
  for a in n.keys():
    a2 = int(a)
    for b in range(0, 10):
      if not b in n:
        if k[b][a2] + n[a] < c:
          c = k[b][a2] + n[a]
          mn = b
  n[mn] = c
 
ans = 0
for a in range(0, h):
  for b in range(0, w):
    if wl[a][b] != -1:
      ans += n[wl[a][b]]
 
print(ans)
      

Fixed submission:
h, w = [int(i) for i in input().split()]
k = []
wl = []
  
for i in range(0, 10):
  k.append([int(i) for i in input().split()])
for i in range(0, h):
  wl.append([int(i) for i in input().split()])
 
 
n = {1:0}
 
while len(n) < 10:
  c = 1000
  mn = 10
  for a in n.keys():
    a2 = int(a)
    for b in range(0, 10):
      if not b in n:
        if k[b][a2] + n[a] <= c:
          c = k[b][a2] + n[a]
          mn = b
  n[mn] = c
 
ans = 0
for a in range(0, h):
  for b in range(0, w):
    if wl[a][b] != -1:
      ans += n[wl[a][b]]
 
print(ans)

Buggy python submission (verdict: Runtime Error):
h, w = [int(i) for i in input().split()]
k = []
wl = []
  
for i in range(0, 10):
  k.append([int(i) for i in input().split()])
for i in range(0, h):
  wl.append([int(i) for i in input().split()])


n = {1:0}

while len(n) < 10:
  c = 1000
  mn = 10
  for a in n.keys():
    a2 = int(a)
    for b in range(0, 10):
      if not b in n:
        if k[b][a2] + n[a] < c:
          c = k[b][a2] + n[a]
          mn = b
  n[mn] = c

ans = 0
for a in range(0, h):
  for b in range(0, w):
    ans += n[wl[a][b]]

print(ans)
      

Fixed submission:
h, w = [int(i) for i in input().split()]
k = []
wl = []
  
for i in range(0, 10):
  k.append([int(i) for i in input().split()])
for i in range(0, h):
  wl.append([int(i) for i in input().split()])
 
 
n = {1:0}
 
while len(n) < 10:
  c = 1000
  mn = 10
  for a in n.keys():
    a2 = int(a)
    for b in range(0, 10):
      if not b in n:
        if k[b][a2] + n[a] <= c:
          c = k[b][a2] + n[a]
          mn = b
  n[mn] = c
 
ans = 0
for a in range(0, h):
  for b in range(0, w):
    if wl[a][b] != -1:
      ans += n[wl[a][b]]
 
print(ans)
Buggy python submission (verdict: Runtime Error):
s1 = input()
s2 = input()

x, y, z = [int(i) for i in s1.split()]
l = [int(i) for i in s2.split()]
 
if x = 1:
  print(abs(z - l[x-1]))
else:
  if abs(z - l[x-1]) > abs(l[x-1] - l[x-2]):
    print(abs(z - l[x-1]))
  else:
    print(abs(l[x-1] - l[x-2]))

Fixed submission:
s = input()

a, b = s.split()
if a.isdigit():
  a = int(a)
else:
  a = ord(a) - 50

if b.isdigit():
  b = int(b)
else:
  b = ord(b) - 50

if a < b:
  print("<")
elif a > b:
  print(">")
else:
  print("=")

Buggy python submission (verdict: Runtime Error):
x, y, z = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
 
if x = 1:
  print(abs(z - l[x-1]))
else:
  if abs(z - l[x-1]) > abs(l[x-1] - l[x-2]):
    print(abs(z - l[x-1]))
  else:
    print(abs(l[x-1] - l[x-2]))

Fixed submission:
s = input()

a, b = s.split()
if a.isdigit():
  a = int(a)
else:
  a = ord(a) - 50

if b.isdigit():
  b = int(b)
else:
  b = ord(b) - 50

if a < b:
  print("<")
elif a > b:
  print(">")
else:
  print("=")

Buggy python submission (verdict: Runtime Error):
a, b = input().split
if a.isdigit():
  a = int(a)
else:
  a = ord(a) - 50

if b.isdigit():
  b = int(b)
else:
  b = ord(b) - 50

if a > b:
  print("<")
elif a < b:
  print(">")
else:
  print("=")


Fixed submission:
s = input()

a, b = s.split()
if a.isdigit():
  a = int(a)
else:
  a = ord(a) - 50

if b.isdigit():
  b = int(b)
else:
  b = ord(b) - 50

if a < b:
  print("<")
elif a > b:
  print(">")
else:
  print("=")