Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# ABC100 C - Pyramid
n=int(input())
xyh=[]
idx=-1
for i in range(n):
    x,y,h=map(int,input().split())
    if h>=1:
        xyh.append([x,y,h])
        idx=i
for cx in range(101):
    for cy in range(101):
        H=abs(xyh[idx][0]-cx)+abs(xyh[idx][1]-cy)+xyh[idx][2]
        H=max(H,0)
        ok=True
        for i in range(n):
            t_height=H-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)
            if xyh[i][2]==0 and t_height>0:
                ok=False
            if xyh[i][2]>0 and xyh[i][2]!=t_height:
                ok=False
        if ok:
            print(cx,cy,H)

Fixed submission:
# ABC100 C - Pyramid
n=int(input())
xyh=[]
idx=-1
for i in range(n):
    x,y,h=map(int,input().split())
    xyh.append([x,y,h])
    if h>=1:
        idx=i
for cx in range(101):
    for cy in range(101):
        H=abs(xyh[idx][0]-cx)+abs(xyh[idx][1]-cy)+xyh[idx][2]
        H=max(H,0)
        ok=True
        for i in range(n):
            t_height=H-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)
            if xyh[i][2]==0 and t_height>0:
                ok=False
            if xyh[i][2]>0 and xyh[i][2]!=t_height:
                ok=False
        if ok:
            print(cx,cy,H)

Buggy python submission (verdict: Runtime Error):
# ABC100 C - Pyramid
n=int(input())
xyh=[]
idx=-1
for i in range(n):
    x,y,h=map(int,input().split())
    if h>=1:
        xyh.append([x,y,h])
        idx=i
for cx in range(101):
    for cy in range(101):
        H=abs(xyh[idx][0]-cx)+abs(xyh[idx][1]-cy)+xyh[idx][2]
        H=max(H,0)
        ok=True
        for i in range(n):
            t_height=H-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)
            if xyh[i][2]!=t_height:
                ok=False
        if ok:
            print(cx,cy,H)

Fixed submission:
# ABC100 C - Pyramid
n=int(input())
xyh=[]
idx=-1
for i in range(n):
    x,y,h=map(int,input().split())
    xyh.append([x,y,h])
    if h>=1:
        idx=i
for cx in range(101):
    for cy in range(101):
        H=abs(xyh[idx][0]-cx)+abs(xyh[idx][1]-cy)+xyh[idx][2]
        H=max(H,0)
        ok=True
        for i in range(n):
            t_height=H-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)
            if xyh[i][2]==0 and t_height>0:
                ok=False
            if xyh[i][2]>0 and xyh[i][2]!=t_height:
                ok=False
        if ok:
            print(cx,cy,H)
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(replace("9","a").replace("1","9").replace("a","9"))


Fixed submission:
n = input()
print(n.replace("9","a").replace("1","9").replace("a","1"))
Buggy python submission (verdict: Runtime Error):
n=int(input())
b=[int(a-(i+1))  for i,a in enumerate(list(map(int,input().split())))]
bm=b[:]
bm.sort()
mid_1=bm[n//2]
mid_2=bm[(n//2)+1]
ans_1,ans_2=0,0
if n%2==1:
  for bb in b:
    ans_1+=abs(bb-mid_1)
  print(ans_1)
else:
  for bb in b:
    ans_1+=abs(bb-mid_1)
    ans_2+=abs(bb-mid_2)
  print(min(ans_1,ans_2))



Fixed submission:
n=int(input())
b=[int(a-(i+1))  for i,a in enumerate(list(map(int,input().split())))]
if n==1:
  print(0)
  exit(0)
bm=b[:]
bm.sort()
mid_1=bm[n//2]
mid_2=bm[(n//2)+1]
ans_1,ans_2=0,0
if n%2==1:
  for bb in b:
    ans_1+=abs(bb-mid_1)
  print(ans_1)
else:
  for bb in b:
    ans_1+=abs(bb-mid_1)
    ans_2+=abs(bb-mid_2)
  print(min(ans_1,ans_2))
Buggy python submission (verdict: Runtime Error):
# ABC100 B - Ringo's Favorite Numbers 
d,n = map(int,input().split())
l = []
dd = 0
def mod(x,t):
    while x >= 100:
        if x%100 == 0:
            t +=1
        x = x//100
    return t

if d == 0:
    for i in range(1,100):
        dd = mod(i,0)
        if d == dd:
            l.append(i)
elif d == 1:
    for i in range(0,10101,100):
        if i > 0:
            dd = mod(i,0)
            if d == dd:
                l.append(i)
elif d == 2:
    for i in range(0,1010001,10000):
        if i > 0:
            dd = mod(i,0)
            if d == dd:
                l.append(i)

print(l[n-1])

Fixed submission:
# ABC100 B - Ringo's Favorite Numbers 
d,n = map(int,input().split())
ans = 100**d * n
if n==100:
  ans +=100**d
print(ans)

Buggy python submission (verdict: Runtime Error):
# ABC100 B - Ringo's Favorite Numbers 
d,n = map(int,input().split())
l = []
dd = 0
def mod(x,t):
    while x >= 100:
        if x%100 == 0:
            t +=1
        x = x//100
    return t

if d == 0:
    for i in range(1,101):
        dd = mod(i,0)
        if d == dd:
            l.append(i)
elif d == 1:
    for i in range(0,10101,100):
        if i > 0:
            dd = mod(i,0)
            if d == dd:
                l.append(i)
elif d == 2:
    for i in range(0,1010001,10000):
        if i > 0:
            dd = mod(i,0)
            if d == dd:
                l.append(i)

print(l[n-1])

Fixed submission:
# ABC100 B - Ringo's Favorite Numbers 
d,n = map(int,input().split())
ans = 100**d * n
if n==100:
  ans +=100**d
print(ans)

Buggy python submission (verdict: Runtime Error):
# ABC100 B - Ringo's Favorite Numbers 
d,n = map(int,input().split())
l = []
dd = 0
def mod(x,t):
    while x >= 100:
        if x%100 == 0:
            t +=1
        x = x//100
    return t

if d == 0:
    for i in range(1,101):
        dd = mod(i,0)
        if d == dd:
            l.append(i)
elif d == 1:
    for i in range(0,10001,100):
        if i > 0:
            dd = mod(i,0)
            if d == dd:
                l.append(i)
elif d == 2:
    for i in range(0,1000001,10000):
        if i > 0:
            dd = mod(i,0)
            if d == dd:
                l.append(i)

print(l[n-1])

Fixed submission:
# ABC100 B - Ringo's Favorite Numbers 
d,n = map(int,input().split())
ans = 100**d * n
if n==100:
  ans +=100**d
print(ans)
Buggy python submission (verdict: Runtime Error):
# ABC098 B - Cut and Count
n = int(input())
s = input()

ans = 101
s1 = set()
l = []

for i in range(0,n):
    start = s[0:i]
    end = s[i+1:n]
    for ss in start:
        if ss in end:
            s1.add(ss)
            l.append(len(s1))
    s1.clear()
print(max(l))

Fixed submission:
# ABC098 B - Cut and Count
n = int(input())
s = input()

ans=0
for i in range(n-1):
    start = s[0:i+1]
    end = s[i+1:]
    start = ''.join(set(start))
    c = 0
    for j in range(len(start)):
        if start[j] in end:
            c += 1
            ans = max(ans,c)
print(ans)
Buggy python submission (verdict: Runtime Error):
# ABC098 D - Xor Sum 2
n=int(input())
a=list(map(int,input().split()))

l=0
r=1
tmp=a[0]
ans=0

while l<n:
    if r==n:
        ans+=(r-l)
        l+=1
        continue
    if tmp+a[r]==tmp^a[r]:
        tmp=tmp+a[r]
        j+=1
    else:
        ans+=(j-l)
        tmp=tmp-a[l]
        l+=1      

print(ans)


Fixed submission:
# ABC098 D - Xor Sum 2
n=int(input())
a=list(map(int,input().split()))

l=0
r=1
tmp=a[0]
ans=0

while l<n:
    if r==n:
        ans+=(r-l)
        l+=1
        continue
    if tmp+a[r]==tmp^a[r]:
        tmp=tmp+a[r]
        r+=1
    else:
        ans+=(r-l)
        tmp=tmp-a[l]
        l+=1      

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# ABC097 C - K-th Substring
s = input()
k = int(input())

n = len(s)
d = set()
l = []

for i in range(n):
    for j in range(n-i):
        d.add(s[j:j+i+1])
l = list(d)
l.sort()

print(l[k-1])

Fixed submission:
# ABC097 C - K-th Substring
s = input()
k = int(input())

n = len(s)
d = set()
l = []

for i in range(k):
    for j in range(n-i):
        d.add(s[j:j+i+1])
l = list(d)
l.sort()

print(l[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
# ABC094 C - Many Medians
n = int(input())
x = list(map(int,input().split()))

for i in range(n):
    y = x[:]
    y[i] = 0
    y.sort()
    print(y[int((n/2))])



Fixed submission:
# ABC094 C - Many Medians
n = int(input())
x = list(map(int,input().split()))

y = sorted(x)
l = y[n//2 - 1]
r = y[n//2]
 
for x in x:
  print(l if x >= r else r)

Buggy python submission (verdict: Time Limit Exceeded):
# ABC094 C - Many Medians
n = int(input())
x = list(map(int,input().split()))

for i in range(n):
    y = x[:]
    del y[i]
    y.sort()
    print(y[int((n/2)-1)])

Fixed submission:
# ABC094 C - Many Medians
n = int(input())
x = list(map(int,input().split()))

y = sorted(x)
l = y[n//2 - 1]
r = y[n//2]
 
for x in x:
  print(l if x >= r else r)
Buggy python submission (verdict: Time Limit Exceeded):
# ABC093 B - Small and Large Integers
a,b,k = map(int, input().split())

for i in range(a,b+1):
    if i <= a+k-1:
        print(i)
        continue
    elif i >= b-k+1:
        print(i)
        continue

Fixed submission:
# ABC093 B - Small and Large Integers
a,b,k = map(int, input().split())

range_ab = set(range(a,a+k))|set(range(b-k+1,b+1))
l = list(range_ab)
l = [x for x in l if a<=x<=b]

l.sort()
print(*l,sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
# ABC093 B - Small and Large Integers
a,b,k = map(int, input().split())
s = set()
L = []
for i in range(a,b+1):
    if i <= a+k-1:
        s.add(i)
        continue
    elif i >= b-k+1:
        s.add(i)
        continue
L = list(s)
L.sort()

for l in L:
    print(l)

Fixed submission:
# ABC093 B - Small and Large Integers
a,b,k = map(int, input().split())

range_ab = set(range(a,a+k))|set(range(b-k+1,b+1))
l = list(range_ab)
l = [x for x in l if a<=x<=b]

l.sort()
print(*l,sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m=map(int,input().split())
G=[[] for i in range(n)]

for i in range(m):
    l,r,d=map(int,input().split())
    G[l-1].append([r-1,d])
    G[r-1].append([l-1,-d])

for i in range(n):
    dist=[None]*n
    q=deque()
    if dist[i]==None:
        dist[i]=0
    q.append(i)
    while q:
        cur=q.popleft()
        for nx,d in G[cur]:
            if dist[nx]==None:
                dist[nx]=dist[cur]+d
                q.append(nx)
            elif dist[nx]!=dist[cur]+d:
                print('No')
                exit()
print('Yes')


Fixed submission:
# D - People on a Line
from collections import deque
n,m=map(int,input().split())
dist=[None]*n
edge=[[] for i in range(n)]

for i in range(m):
    l,r,d=map(int,input().split())
    edge[l-1].append((r-1,d))
    edge[r-1].append((l-1,-d))

for i in range(n):
    q=deque()
    if dist[i]==None:
        dist[i]=0
        q.append(i)
    while q:
        cur=q.popleft()
        for nx,d in edge[cur]:
            if dist[nx]==None:
                dist[nx]=dist[cur]+d
                q.append(nx)
            elif dist[nx]!=dist[cur]+d:
                print('No')
                exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
# ABC083 C - Multiple Gift
x,y = map(int,input().split())

ans = 0
while x <= y:
    x *= 2
    ans += 1
print(ans)

Fixed submission:
# ABC083 A - Libra
a,b,c,d = map(int,input().split())

if a+b > c+d:
    print('Left')
elif a+b == c+d:
    print('Balanced')
elif a+b < c+d:
    print('Right')
Buggy python submission (verdict: Runtime Error):
# ABC080 C - Shopping Street
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
f=[nl() for _ in range(n)]
p=[nl() for _ in range(n)]
o = []
ans = -10**8
for i in range(2**10):
    op = [0]*10
    for j in range(10):
        if ((i>>j)&1):
            op[n-1-j]=1
    if not any(op):
        continue
    else:
        o.append(op)

for oo in o:
    value = 0
    for i,ff in enumerate(f):
        t=0
        for j in range(10):
            if oo[j]==1 and ff[j]==1:
                t+=1
        value += p[i][t]
    ans = max(ans,value)

print(ans)



Fixed submission:
# ABC080 C - Shopping Street
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
f=[nl() for _ in range(n)]
p=[nl() for _ in range(n)]
o = []
ans = -10**10
for i in range(2**10):
    op = [0]*10
    for j in range(10):
        if ((i>>j)&1):
            op[10-1-j]=1
    if not any(op):
        continue
    else:
        o.append(op)

for oo in o:
    value = 0
    for i,ff in enumerate(f):
        t=0
        for j in range(10):
            if oo[j]==1 and ff[j]==1:
                t+=1
        value += p[i][t]
    ans = max(ans,value)

print(ans)

Buggy python submission (verdict: Runtime Error):
# ABC080 C - Shopping Street
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
f=[nl() for _ in range(n)]
p=[nl() for _ in range(n)]
o = []
ans = -10**8
for i in range(2**10):
    op = [0]*10
    for j in range(10):
        if ((i>>j)&1):
            op[n-1-j]=1
    if not any(op):
        continue
    else:
        o.append(op)

for oo in o:
    value = 0
    for i,ff in enumerate(f):
        # 同じ時刻の店
        t=0
        for j in range(10):
            if oo[j]==ff[j]==1:
                t+=1
        value += p[i][t]
    ans = max(ans,value)

print(ans)


Fixed submission:
# ABC080 C - Shopping Street
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
f=[nl() for _ in range(n)]
p=[nl() for _ in range(n)]
o = []
ans = -10**10
for i in range(2**10):
    op = [0]*10
    for j in range(10):
        if ((i>>j)&1):
            op[10-1-j]=1
    if not any(op):
        continue
    else:
        o.append(op)

for oo in o:
    value = 0
    for i,ff in enumerate(f):
        t=0
        for j in range(10):
            if oo[j]==1 and ff[j]==1:
                t+=1
        value += p[i][t]
    ans = max(ans,value)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#ABC077 C - Snuke Festival
from bisect import bisect_left, bisect_right
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

N = ni()
A = nl()
B = nl()
C = nl()

A.sort()
B.sort()
C.sort()
ans = 0

for i in range(N):
    t = 0
    tt = 0
    t = bisect_left(B,C[i])
    for j in range(t,0,-1):
        tt = bisect_left(A,B[j-1])
        ans += tt

print(ans)


Fixed submission:
#ABC077 C - Snuke Festival
from bisect import bisect_left, bisect_right
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

N = ni()
A = nl()
B = nl()
C = nl()

A.sort()
C.sort()

ans = 0

for i in range(N):
    t = 0
    tt = 0
    t = bisect_left(A,B[i])
    tt = N-bisect_right(C,B[i])
    ans += t*tt

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#ABC077 C - Snuke Festival
from bisect import bisect_left, bisect_right
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

N = ni()
A = nl()
B = nl()
C = nl()

A.sort()
B.sort()
C.sort()
ans = 0

for i in range(N):
    t = 0
    tt = 0
    t = bisect_left(B,C[i])
    for j in range(t,0,-1):
        tt = bisect_left(A,B[j-1])
        ans += tt

print(ans)

Fixed submission:
#ABC077 C - Snuke Festival
from bisect import bisect_left, bisect_right
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

N = ni()
A = nl()
B = nl()
C = nl()

A.sort()
C.sort()

ans = 0

for i in range(N):
    t = 0
    tt = 0
    t = bisect_left(A,B[i])
    tt = N-bisect_right(C,B[i])
    ans += t*tt

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
from collections import deque
s=deque(s)
ans=0
while len(list(s)):
  if s[0]==s[-1]:
    if len(list(s))==1:
      s.pop()
      break
    else:
      s.pop()
      s.popleft()
  else:
    if s[0]=="x" and s[-1]!="x":
      s.append("x")
      ans+=1
    elif s[0]!="x" and s[-1]=="x":
      s.appendleft("x")
      ans+=1
    elif s[0]!="x" and s[-1]!="x":
      print(-1)
      exit(0)

print(ans)


Fixed submission:
s=input()
from collections import deque
s=deque(s)
ans=0
while len((s)):
  if s[0]==s[-1]:
    if len((s))==1:
      s.pop()
      break
    else:
      s.pop()
      s.popleft()
  else:
    if s[0]=="x" and s[-1]!="x":
      s.append("x")
      ans+=1
    elif s[0]!="x" and s[-1]=="x":
      s.appendleft("x")
      ans+=1
    elif s[0]!="x" and s[-1]!="x":
      print(-1)
      exit(0)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
from collections import deque
s=deque(s)
ans=0
while len(list(s)):
  if s[0]==s[-1]:
    if len(list(s))==1:
      s.pop()
      break
    else:
      s.pop()
      s.popleft()
  else:
    if s[0]=="x" and s[-1]!="x":
      s.append("x")
      ans+=1
    elif s[0]!="x" and s[-1]=="x":
      s.appendleft("x")
      ans+=1
    elif s[0]!="x" and s[-1]!="x":
      print(-1)
      exit(0)

print(ans)


Fixed submission:
s=input()
from collections import deque
s=deque(s)
ans=0
while len((s)):
  if s[0]==s[-1]:
    if len((s))==1:
      s.pop()
      break
    else:
      s.pop()
      s.popleft()
  else:
    if s[0]=="x" and s[-1]!="x":
      s.append("x")
      ans+=1
    elif s[0]!="x" and s[-1]=="x":
      s.appendleft("x")
      ans+=1
    elif s[0]!="x" and s[-1]!="x":
      print(-1)
      exit(0)

print(ans)
Buggy python submission (verdict: Runtime Error):
atodeyaruyo

Fixed submission:
# ABC075 C - Bridge
def dfs(v):
    visited[v]=True
    for nv in range(n):
        if G[v][nv]==False:
            continue
        if visited[nv]:
            continue
        dfs(nv)

n,m = map(int,input().split())
G = [[False]*n for _ in range(n)]
ans = 0
visited = [False for _ in range(n)]
A,B = [],[]
for i in range(m):
    a,b = map(int,input().split())
    A.append(b-1)
    B.append(a-1)
    G[a-1][b-1]=G[b-1][a-1]=True

for i in range(m):
    G[A[i]][B[i]]=G[B[i]][A[i]]=False
    visited = [False for _ in range(n)]
    dfs(0)
    if all(visited):
        ans += 1
    G[A[i]][B[i]]=G[B[i]][A[i]]=True

print(m-ans)
Buggy python submission (verdict: Time Limit Exceeded):
# ABC074 C - Sugar Water
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
a,b,c,d,e,f = nm()
L =[]
for aa in range(0,31):
    for bb in range(0,31):
        for cc in range(0,1001):
            for dd in range(0,1001):
                if 100*a<=100*a*aa+100*b*bb+c*cc+d*dd<=f:
                    L.append((aa,bb,cc,dd))

max_w = 0.0
idx = 10*7
for i,l in enumerate(L):
    water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
    sugar = c*l[2]+d*l[3]
    if (100+e)*100*sugar<=(100*e)*water:
        if l[0]>0 or l[1]>0:
            t = (sugar/water)*100
            if t>=max_w:
                max_w=t
                idx = i

for i,l in enumerate(L):
    if i==idx:
        water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
        sugar = c*l[2]+d*l[3]
        print(water,sugar)
        exit()



Fixed submission:
# ABC074 C - Sugar Water
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
a,b,c,d,e,f = nm()
L =[]
for aa in range(0,31):
    for bb in range(0,31):
        for cc in range(0,101):
            for dd in range(0,101):
                if 100*a<=100*a*aa+100*b*bb+c*cc+d*dd<=f:
                    L.append((aa,bb,cc,dd))

max_w = 0.0
idx = 10*7
for i,l in enumerate(L):
    # water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
    water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
    sugar = c*l[2]+d*l[3]
    if (100+e)*100*sugar<=(100*e)*water:
        # if water!=0 and (l[0]>0 or l[1]>0):
        if l[0]>0 or l[1]>0:
            t = (sugar/water)*100
            if t>=max_w:
                max_w=t
                idx = i

for i,l in enumerate(L):
    if i==idx:
        water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
        sugar = c*l[2]+d*l[3]
        print(water,sugar)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]

for k in range(n):
  for i in range(n):
    for j in range(n):
      if a[i][j]>a[i][k]+a[k][j]:
        print(-1)
        exit(0)

ans=0
for i in range(n):
  for j in range(i+1,n):
    ok=True
    for k in range(n):
      if i==k or j==k:
        continue
      if a[i][j]==a[i][k]+a[k][j]:
        ok=False
        break
    if ok:
        ans+=a[i][j]
print(ans)


Fixed submission:
# ABC074 D - Restoring Road Network
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]

for k in range(n):
    for i in range(n):
        for j in range(n):
            if a[i][j]>a[i][k]+a[k][j]:
                print(-1)
                exit()
"""
a[i][j]が、i,kを除く全てのkについて
a[i][j]<a[i][k]+a[k][j]なら
a[i][j]は最短経路となる。
"""
ans=0
for i in range(n):
    for j in range(i+1,n):
        # iとjの間に辺が存在する場合True
        flg=True
        for k in range(n):
            if i==k or j==k:
                continue
            if a[i][j]==a[i][k]+a[k][j]:
                flg=False
                break
        if flg:
            ans+=a[i][j]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000000)
def dfs(cur,par,d):
    dist[cur]=d
    for nx,nx_dist in G[cur]:
        if nx==par:continue
        dfs(nx,cur,d+nx_dist)

n=int(input())
G=[[] for i in range(n)]
dist=[0]*n
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append([b-1,c])
    G[b-1].append([a-1,c])
q,k=map(int,input().split())
k-=1
dfs(k,-1,0)
for i in range(q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(dist[x]+dist[y])

Fixed submission:
# ABC070 D - Transit Tree Path
import heapq
def dijkstra_heap(s):
    """
    始点sから各頂点への最短距離を返す

    Parameters
    ----------
    s : int
        視点とする頂点

    Returns
    -------
    d ：list
    始点sから各頂点への最短距離
    """
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #未使用の頂点の中から最小の距離のものを探す
        if not used[minedge[0]]:
            continue
        v = minedge[0]
        d[v] = minedge[1]
        used[v] = False
        for e in edge[v]:
            if used[e[0]]:
                heapq.heappush(edgelist,[e[0],e[1]+d[v]])
    return d

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

q,k=map(int,input().split())
k-=1
dist=dijkstra_heap(k)
for i in range(q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(dist[x]+dist[y])

Buggy python submission (verdict: Runtime Error):
def dfs(cur,par,d):
    dist[cur]=d
    for nx,nx_dist in G[cur]:
        if nx==par:continue
        dfs(nx,cur,d+nx_dist)

n=int(input())
G=[[] for i in range(n)]
dist=[0]*n
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append([b-1,c])
    G[b-1].append([a-1,c])
q,k=map(int,input().split())
k-=1
dfs(k,-1,0)
for i in range(q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(dist[x]+dist[y])

Fixed submission:
# ABC070 D - Transit Tree Path
import heapq
def dijkstra_heap(s):
    """
    始点sから各頂点への最短距離を返す

    Parameters
    ----------
    s : int
        視点とする頂点

    Returns
    -------
    d ：list
    始点sから各頂点への最短距離
    """
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #未使用の頂点の中から最小の距離のものを探す
        if not used[minedge[0]]:
            continue
        v = minedge[0]
        d[v] = minedge[1]
        used[v] = False
        for e in edge[v]:
            if used[e[0]]:
                heapq.heappush(edgelist,[e[0],e[1]+d[v]])
    return d

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

q,k=map(int,input().split())
k-=1
dist=dijkstra_heap(k)
for i in range(q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(dist[x]+dist[y])
Buggy python submission (verdict: Runtime Error):
print((int(input())-1)*(int(input())-1))

Fixed submission:
m,n = map(int,input().split())
print((m-1)*(n-1))