Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin python3
# -*- coding: utf-8 -*-

import itertools

n, k = map(int, input().split())
a = list(itertools.accumulate(list(map(int, input().split()))))
a = [0] + a
s = []
for i in range(n+1):
    for j in range(i,n+1):
        s.append(list(format(a[j]-a[i], '050b')))

ret = 0
sel = set(range(n*(n+1)//2))
for i in range(50):
    nxt = set([])
    for j in sel:
        if s[j][i] == '1':
            nxt.add(j)
    if len(nxt)>=k:
        sel = nxt
        ret += 2**(49-i)
print(ret)

Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

import itertools

n, k = map(int, input().split())
a = list(itertools.accumulate(list(map(int, input().split()))))
a = [0] + a
s = [None] * (n*(n+1)//2)
cnt = 0
for i in range(n+1):
    for j in range(i+1,n+1):
        s[cnt] = format(a[j]-a[i], '050b')
        cnt += 1

ret = 0
sel = set(range(n*(n+1)//2))
for i in range(50):
    nxt = set([])
    for j in sel:
        if s[j][i] == '1':
            nxt.add(j)
    if len(nxt)>=k:
        sel = nxt
        ret += 2**(49-i)
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin python3
# -*- coding: utf-8 -*-

import itertools

n, k = map(int, input().split())
a = list(itertools.accumulate(list(map(int, input().split()))))
a = [0] + a
s = []
for i in range(n+1):
    for j in range(i,n+1):
        s.append(list(format(a[j]-a[i], '050b')))

ret = 0
sel = set(range(n*(n+1)//2))
for i in range(50):
    nxt = set([])
    for j in sel:
        if s[j][i] == '1':
            nxt.add(j)
    if len(nxt)>=k:
        sel = nxt
        ret += 2**(49-i)
print(ret)


Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

import itertools

n, k = map(int, input().split())
a = list(itertools.accumulate(list(map(int, input().split()))))
a = [0] + a
s = [None] * (n*(n+1)//2)
cnt = 0
for i in range(n+1):
    for j in range(i+1,n+1):
        s[cnt] = format(a[j]-a[i], '050b')
        cnt += 1

ret = 0
sel = set(range(n*(n+1)//2))
for i in range(50):
    nxt = set([])
    for j in sel:
        if s[j][i] == '1':
            nxt.add(j)
    if len(nxt)>=k:
        sel = nxt
        ret += 2**(49-i)
print(ret)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin python3
# -*- coding: utf-8 -*-

from fractions import gcd   #for python3.4
from math import gcd        #for python3.8

def lcm(a,b):
    G = gcd(a, b) #最大公約数
    L = (a//G)*b #最小公倍数
    return L

def main():
    N, M = map(int, input().split())
    S = input()
    T = input()
    L = lcm(N,M)
    if S[::L//M]==T[::L//N]:
        print(L)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

from fractions import gcd   #for python3.4
#from math import gcd        #for python3.8

def lcm(a,b):
    G = gcd(a, b) #最大公約数
    L = (a//G)*b #最小公倍数
    return L

def main():
    N, M = map(int, input().split())
    S = input()
    T = input()
    L = lcm(N,M)
    if S[::L//M]==T[::L//N]:
        print(L)
    else:
        print(-1)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
ret = ''
for a in input():
  if a = '1':
    ret += '9'
  elif a = '9':
    ret += '1'
  else:
    ret += a
print(ret)

Fixed submission:
print(((input().replace("1","d")).replace("9","1")).replace("d","9"))
Buggy python submission (verdict: Runtime Error):
S=input()
C1=S[0]=='A' and S[-1].islower()
C1=C1 and S[1].islower()
C2=0
C3=0
for i in S[2:len(S)-1]:
  if i=='C':
    C2+=1
  elif i.islower():
  else:
    C3+=1
if C1 and C2==1 and C3==0:
  print('AC')
else:
  print('WA')


Fixed submission:
S=input()
C1=S[0]=='A' and S[-1].islower()
C1=C1 and S[1].islower()
C2=0
C3=0
for i in S[2:len(S)-1]:
  if i=='C':
    C2+=1
  elif i.islower():
    C3=C3
  else:
    C3+=1
if C1 and C2==1 and C3==0:
  print('AC')
else:
  print('WA')

Buggy python submission (verdict: Runtime Error):
S=input()
C1=(S[0]=='A')
C2=0
for i in range(2:len(S)):
  if S[i]=='C' and i in range(2:len(S)-1):
    C2+=1
  else:
    C1=C1 and S[i].islower()
if C1 and C2==1:
  print('AC')
else:
  print('WA')

Fixed submission:
S=input()
C1=S[0]=='A' and S[-1].islower()
C1=C1 and S[1].islower()
C2=0
C3=0
for i in S[2:len(S)-1]:
  if i=='C':
    C2+=1
  elif i.islower():
    C3=C3
  else:
    C3+=1
if C1 and C2==1 and C3==0:
  print('AC')
else:
  print('WA')
Buggy python submission (verdict: Runtime Error):
a = list(map(int,input()))
print(max(a)-min(a))

Fixed submission:
a = list(map(int,input().split()))
print(max(a)-min(a))
Buggy python submission (verdict: Runtime Error):
D,N = map(int,input().split())
k = 100**D
m = 100**(D+1)
cnt = 0
for i in range(1,200):
  if (i*k)%m != 0:
    cnt +=1
    if cnt =N:
      print(i*k)
      break

Fixed submission:
D,N = map(int,input().split())
k = 100**D
m = 100**(D+1)
cnt = 0
for i in range(1,200):
  if (i*k)%m != 0:
    cnt +=1
    if cnt ==N:
      print(i*k)
      break
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input())
i=b-a
print(i*(i+1)//2-b)

Fixed submission:
a,b=map(int,input().split())
i=b-a
print(i*(i+1)//2-b)
Buggy python submission (verdict: Runtime Error):
a,b =map(int,input().split())
print(max(a+b,a-b,a*b)

Fixed submission:
a,b =map(int,input().split())
print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())
print(max([len(set(S[:i]) & set(S[i:])) for

Fixed submission:
N = int(input())
S = list(input())
print(max([len(set(S[:i]) & set(S[i:])) for i in range(1,N)]))
Buggy python submission (verdict: Runtime Error):
X = int(input())
A =[]
for b in range(1,int(X**0.5)+1):
  for p in range(2,X):
    if b**p > X:
      A.append(b**(p-1))
      break
print(max(A))

Fixed submission:
X = int(input())
if X != 1:
  A =[]
  for b in range(1,int(X**0.5)+1):
    for p in range(2,X):
      if b**p > X:
        A.append(b**(p-1))
        break
  print(max(A))
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
a=int(input())
import math
b=int(math.log(a, 2)
c=1
if b!=1:
  for i in range(2,b+1,1):
    c=max(c,int(a**(1/i))**i)
print(c)

Fixed submission:
X = int(input())
if X != 1:
  A =[]
  for b in range(1,int(X**0.5)+1):
    for p in range(2,X):
      if b**p > X:
        A.append(b**(p-1))
        break
  print(max(A))
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
a=int(input())
import math
b=int(math.sqrt(a))
c=1
for i in range(b):
  c=max(c,int(a**(1/i))**i)
print(c)

Fixed submission:
X = int(input())
if X != 1:
  A =[]
  for b in range(1,int(X**0.5)+1):
    for p in range(2,X):
      if b**p > X:
        A.append(b**(p-1))
        break
  print(max(A))
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
a=int(input())
import math
b=int(math.sqrt(a))
c=1
for i in range(b):
  c=max(c,(int(a**(1/i)))**i)
print(c)

Fixed submission:
X = int(input())
if X != 1:
  A =[]
  for b in range(1,int(X**0.5)+1):
    for p in range(2,X):
      if b**p > X:
        A.append(b**(p-1))
        break
  print(max(A))
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
m,d=map(int,input())
if d>=m:
  print(m)
else:
  print(m-1)

Fixed submission:
m,d=map(int,input().split())
if d>=m:
  print(m)
else:
  print(m-1)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K = map(int,input().split())
s = list(set(range(A,B+1))&(set(range(A,A+K))|set(range(B-K+1,B+1))))
for i in sorted(s):
  print(i)

Fixed submission:
A,B,K = map(int,input().split())
if (2*K)<(B-A+2):
  for i in range(A,A+K):
    print(i)
  for i in range(B-K+1,B+1):
    print(i)
else:
  for i in range(A,B+1):
    print(i)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A==1 and B==1:
  print(1)
elif A==1:
  print(B-2)
elif B==!:
  print(A-2)
else:
  print((A-2)*(B-2))

Fixed submission:
A, B = map(int, input().split())
if A==1 and B==1:
  print(1)
elif A==1:
  print(B-2)
elif B==1:
  print(A-2)
else:
  print((A-2)*(B-2))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
H,W,D = map(int,input().split())
A = []
for h in range(H):
  A = A + list(map(int,input().split()))
for i in range(H*W):
  A[i]=(A[i], i, i%W, i//W)
A.sort()

Q = int(input())
for q in range(Q):
  L,R = map(int,input().split())
  ret = 0
  x0,y0=A[L-1][2],A[L-1][3]
  for l in range((R-L)//D):
    x,y=A[L+D*(l+1)-1][2],A[L+D*(l+1)-1][3]
    ret += abs(x-x0)+abs(y-y0)
    x0,y0=x,y
  print(ret)

Fixed submission:
import sys
input=sys.stdin.readline
H,W,D = map(int,input().split())
A = []
for h in range(H):
  A = A + list(map(int,input().split()))
for i in range(H*W):
  A[i]=(A[i], i%W, i//W)
A.sort()
Dist=[0]*(H*W)
for i in range(H*W):
  if i>=D:
    Dist[i] = Dist[i-D] + abs(A[i][1]-A[i-D][1]) + abs(A[i][2]-A[i-D][2])
Q = int(input())
for q in range(Q):
  L,R = map(int,input().split())
  ret = Dist[R-1]-Dist[L-1]
  print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
H,W,D = map(int,input().split())
MP = [None]*(H*W)
for h in range(H):
  X = list(map(int,input().split()))
  for w in range(W):
    MP[X[w]-1]=[h+1,w+1]
Q = int(input())
for h in range(Q):
  L,R = map(int,input().split())
  ans = 0
  for l in range(L,R,D):
    lD = l+D
    ans += abs(MP[lD-1][0]-MP[l-1][0])+abs(MP[lD-1][1]-MP[l-1][1])
  print(ans)

Fixed submission:
import sys
input=sys.stdin.readline
H,W,D = map(int,input().split())
A = []
for h in range(H):
  A = A + list(map(int,input().split()))
for i in range(H*W):
  A[i]=(A[i], i%W, i//W)
A.sort()
Dist=[0]*(H*W)
for i in range(H*W):
  if i>=D:
    Dist[i] = Dist[i-D] + abs(A[i][1]-A[i-D][1]) + abs(A[i][2]-A[i-D][2])
Q = int(input())
for q in range(Q):
  L,R = map(int,input().split())
  ret = Dist[R-1]-Dist[L-1]
  print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    L = 0
    print(L, flush=True)
    Ls = input()
    if Ls == "Vacant":
        exit()
    else:
    U = N-1
    print(U, flush=True)
    Us = input()
    if Us == "Vacant":
        exit()
    for i in range(18):
        mid = (U+D)//2
        if mid%2==1:
            mid-=1
        print(mid, flush=True)
        ms = input()
        if ms == "Vacant":
            exit()
        if Ls==ms:
            L=mid
        if Us==ms:
            U=mid

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys

def main():
    N = int(input())
    L = 0
    print(L)
    sys.stdout.flush()
    Ls = input()
    if Ls == "Vacant":
        exit()
    U = N-1
    print(U)
    sys.stdout.flush()
    Us = input()
    if Us == "Vacant":
        exit()
    for _ in range(18):
        mid = (U+L)//2
        if mid%2==1:
            mid-=1
        if mid==L:
            mid+=1
        print(mid)
        sys.stdout.flush()
        ms = input()
        if ms == "Vacant":
            exit()
        if Ls==ms:
            L=mid
        if Us==ms:
            U=mid

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    L = 0
    print(L)
    Ls = input()
    if Ls == "Vacant":
        exit()
    else:
    U = N-1
    print(U)
    Us = input()
    if Us == "Vacant":
        exit()
    for i in range(18):
        mid = (U+D)//2
        if mid%2==1:
            mid-=1
        print(mid)
        ms = input()
        if ms == "Vacant":
            exit()
        if Ls==ms:
            L=mid
        if Us==ms:
            U=mid

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys

def main():
    N = int(input())
    L = 0
    print(L)
    sys.stdout.flush()
    Ls = input()
    if Ls == "Vacant":
        exit()
    U = N-1
    print(U)
    sys.stdout.flush()
    Us = input()
    if Us == "Vacant":
        exit()
    for _ in range(18):
        mid = (U+L)//2
        if mid%2==1:
            mid-=1
        if mid==L:
            mid+=1
        print(mid)
        sys.stdout.flush()
        ms = input()
        if ms == "Vacant":
            exit()
        if Ls==ms:
            L=mid
        if Us==ms:
            U=mid

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin python3
# -*- coding: utf-8 -*-

n = 10**5
#primes = set(range(3, n+1, 2))|set([2])
primes = set(range(3, n+1, 2)) #偶数は除く
for i in range(3, int(n**0.5+1)):
    primes.difference_update(range(i*3, n+1, i*2))
primes = list(primes)

Likes = [0] * (n+1)
cnt = 0
for i in primes:
    if (i+1)//2 in primes or (i+1)//2==2:
        Likes[i]=1
for i in range(1,n):
    Likes[i]+=Likes[i-1]

def main():
    Q = int(input())
    for q in range(Q):
        l,r = map(int,input().split())
        print(Likes[r]-Likes[l-1])

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input=sys.stdin.readline
N=100000
primes = set(range(3, N+1, 2))
for i in range(3, int(N**0.5+1)):
  primes.difference_update(range(i*3, N+1, i*2))
primes=set(primes)
primes.add(2)
FG=[0]*(N+1)
for i in range(1,N+1,2):
  FG[i-1]=FG[i-2]
  if i in primes and (i+1)//2 in primes:
    FG[i]=FG[i-1]+1
  else:
    FG[i]=FG[i-1]
for q in range(int(input())):
  l,r=map(int,input().split())
  print(FG[r]-FG[l-1])
Buggy python submission (verdict: Runtime Error):
#!/usr/bin python3
# -*- coding: utf-8 -*-

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

def check(l):
    ret = True
    for i in range(n-1):
        if a[i]>a[i+1]:
            ret = False
            break
    return ret

def solv(ret):
    print(len(ret))
    for i in ret:
        print("{} {}".format(*i))

if check(a):
    print(0); exit()

m = 0
for i, ai in enumerate(a):
    if abs(ai) > m:
        m = ai
        mi = i

ret = []
if m > 0:
    for i in range(n):
        ret.append([mi+1, i+1])
        a[i] += a[mi]
        if check(a):
            solv(ret)
            exit()
    for i in range(n-1):
        ret.append([i+1, i+2])
        a[i+1] += a[i]
        if check(a):
            solv(ret)
            exit()
else:
    for i in range(n):
        ret.append([mi+1, i+1])
        a[i] += a[mi]
        if check(a):
            solv(ret)
            exit()
    for i in range(n-1, -1, -1):
        ret.append([i+1, i+2])
        a[i+1] += a[i]
        if check(a):
            solv(ret)
            exit()


Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int, input().split()))
m = 0
for i, ai in enumerate(a):
    if abs(ai) >= m:
        m = abs(ai)
        mi = i
ret= [[mi+1, i+1] for i in range(n)]
if a[mi] >= 0:
    for i in range(n-1):
        ret.append([i+1, i+2])
else:
    for i in range(n-2, -1, -1):
        ret.append([i+2, i+1])  #i+1->i
print(2*n-1)
for x in ret:
    print(" ".join(map(str, x)))
Buggy python submission (verdict: Runtime Error):
S = input()
if len(S)<=2:
  print("YES")
else:
  ca = S.count("a")
  cb = S.count("b")
  cc = S.count("c")
  n = len(S)//3
  ca2 = ca - n
  cb2 = cb - n
  cc2 = cc - n
  flg = [ca2,cb2,cc2]
  if flg.count(0)==3:
    print("YES")
    print(flg2,n,flg)
  elif flg.count(1)==1 and flg.count(0)==2:
    print("YES")
  elif flg.count(1)==2 and flg.count(0)==1:
    print("YES")
  elif flg.count(2)==1 and flg.count(1)==2:
    print("YES")
  else:
    print("NO")

Fixed submission:
S = input()
ca = S.count("a")
cb = S.count("b")
cc = S.count("c")
n = min(ca,cb,cc)
ca2 = ca - n
cb2 = cb - n
cc2 = cc - n
flg = [ca2,cb2,cc2]
flg.sort()
if flg in [[0,0,0],[0,0,1],[0,1,1]]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
ret='YES'
for i in range(3):
  if a[i]!=b[2-i]
    ret='NO'
    break
print(ret)

Fixed submission:
a=input()
b=input()
ret='YES'
for i in range(3):
  if a[i]!=b[2-i]:
    ret='NO'
    break
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort()
    B.sort()
    C.sort()

    ret = 0
    for a in A:
        ib = bisect_right(B,a)
        for b in B[ib:]:
            ic = bisect_right(C,b)
            ret += N - ic
    print(ret)

if __name__ == '__main__':
    main()

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
from bisect import bisect_right
ret=0
Cb=[0]*(N+1)
for i in range(N):
  Cb[i]=N-bisect_right(C,B[i])
for i in range(N-1,-1,-1):
  Cb[i]+=Cb[i+1]
for a in A:
  bi=bisect_right(B,a)
  ret+=Cb[bi]
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
from bisect import bisect_right
ret=0
Cb=[0]*(N+1)
prebr=0
for i in range(N):
  prebr+=bisect_right(C[prebr:],B[i])
  Cb[i]=N-prebr
for i in range(N-1,-1,-1):
  Cb[i]+=Cb[i+1]
for a in A:
  bi=bisect_right(B,a)
  ret+=Cb[bi]
print(ret)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
from bisect import bisect_right
ret=0
Cb=[0]*(N+1)
for i in range(N):
  Cb[i]=N-bisect_right(C,B[i])
for i in range(N-1,-1,-1):
  Cb[i]+=Cb[i+1]
for a in A:
  bi=bisect_right(B,a)
  ret+=Cb[bi]
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
from bisect import bisect_right
ret=0

Cb=[0]*N
for i in range(N):
  Cb[i]=N-bisect_right(C,B[i])
for a in A:
  bi=bisect_right(B,a)
  for bii in range(bi,N):
    ret+=Cb[bii]
print(ret)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
from bisect import bisect_right
ret=0
Cb=[0]*(N+1)
for i in range(N):
  Cb[i]=N-bisect_right(C,B[i])
for i in range(N-1,-1,-1):
  Cb[i]+=Cb[i+1]
for a in A:
  bi=bisect_right(B,a)
  ret+=Cb[bi]
print(ret)
Buggy python submission (verdict: Runtime Error):
a,m=map(int,input().split())
print(2*m-a)

Fixed submission:
a=int(input())
m=int(input())
print(2*m-a)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
t=s.replace('x','')
ret = -1
if t==t[::-1]:
  ret+=1
  a=list(s)
  b=list(s[::-1])
  while a!=b:
    if len(a)==0:
      ret+=len(b)
      break
    elif len(b)==0:
      ret+=len(a)
      break
    elif a[-1]!=b[-1]:
      if a[-1]=='x':
        del a[-1]
        ret+=1
      elif b[-1]=='x':
        del b[-1]
        ret+=1
    else:
      del a[-1]
      del b[-1]
print(ret//2)

Fixed submission:
s = input()
l, r=0, len(s)-1
ret = 0
while l<r:
  L, R=s[l], s[r]
  if L==R:
    l+=1
    r-=1
  elif L=='x':
    l+=1
    ret+=1
  elif R=='x':
    r-=1
    ret+=1
  else:
    ret=-1
    break
print(ret)
Buggy python submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
ret = 'No'
for m in range(M+1):
  a=K-m*N
  b=M-2*m
  if 0<=a and 0<=b and a%b==0:
    n=a//b
    if 0<=n<=N:
      ret = 'Yes'
print(ret)

Fixed submission:
N,M,K=map(int,input().split())
ret = 'No'
for m in range(M+1):
  a=K-m*N
  b=M-2*m
  if 0<=a and 0<b and a%b==0:
    n=a//b
    if 0<=n<=N:
      ret = 'Yes'
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin python3
# -*- coding: utf-8 -*-

# ワーシャルフロイド法
# 全頂点間最短路
# d[i][j]は2頂点間i, j間の移動コストを格納, Mは頂点数

INF = float("inf")
import copy

def warshall_floyd(d):
    n = len(d)
    wf = copy.deepcopy(d)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])

    return wf #wf[i][j]に頂点i, j間の最短距離を格納

##############################

n = int(input())
d = [list(map(int,input().split())) for _ in range(n)]

if d != warshall_floyd(d):
    print(-1)
else:
    ret = 0
    for i in range(n):
        for j in range(i+1,n):
            if i == j: continue
            ret += d[i][j]
            for mid in range(n):
                if mid in (i, j): continue
                if d[i][mid] + d[mid][j] == d[i][j]:
                    ret -= d[i][j]
                    break
    print(ret)

Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

# ワーシャルフロイド法
# 全頂点間最短路
# d[i][j]は2頂点間i, j間の移動コストを格納, Mは頂点数

INF = float("inf")
import copy

def warshall_floyd(d):
    n = len(d)
    wf = copy.deepcopy(d)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])

    return wf #wf[i][j]に頂点i, j間の最短距離を格納

##############################

n = int(input())
d = [list(map(int,input().split())) for _ in range(n)]

if d != warshall_floyd(d):
    print(-1)
else:
    ret = 0
    for i in range(n):
        for j in range(i+1,n):
            if i == j: continue
            ret += d[i][j]
            for mid in range(n):
                if mid in (i, j): continue
                if d[i][mid] + d[mid][j] == d[i][j]:
                    ret -= d[i][j]
                    break
    print(ret)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[None]*N
for i in range(N):
  A[i]=input()
A.sort()
cnt=0
i = 0
while i <N:
  if A[i]==A[i+1]:
    i+=2
  else:
    cnt+=1
    i+=1
print(cnt)

Fixed submission:
N=int(input())
A=[None]*N
for i in range(N):
  A[i]=input()
A.sort()
A.append('x')
cnt=0
c=A[0]
cc=1
for i in range(1,N+1):
  if A[i]==c:
    cc+=1
  else:
    cnt+=cc%2
    c=A[i]
    cc=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
N=int(input())
P=list(map(int,input().split()))
ans = 0
for i in range(1,N+1):
  if P[i-1]==i:
    P[i-1],P[i]=P[i],P[i-1]
    ans += 1
print(ans)

Fixed submission:
N=int(input())
P=list(map(int,input().split()))
ans = 0
for i in range(1,N+1):
  if P[i-1]==i and i!=N:
    P[i-1],P[i]=P[i],P[i-1]
    ans += 1
  elif P[i-1]==i and i==N:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
S = list(set(list(input())))
S.sort()
al = 'abcdefghijklmnopqrstuvwxyz'
if len(S)==26:
  ans = 'None'
else:
  for i in range(len(al)):
    if al[i] != S[i]:
      ans = al[i]
      break
print(ans)

Fixed submission:
S = list(set(list(input())))
S.sort()
al = 'abcdefghijklmnopqrstuvwxyz'
if len(S)==26:
  ans = 'None'
else:
  for i in range(len(S)):
    if al[i] != S[i]:
      ans = al[i]
      break
    else:
      ans = al[len(S)]
print(ans)

Buggy python submission (verdict: Runtime Error):
S = list(set(list(input())))
S.sort()
al = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(al)):
  if al[i] != S[i]:
    ans = al[i]
    break
if len(S)==26:
  ans = 'None'
print(ans)

Fixed submission:
S = list(set(list(input())))
S.sort()
al = 'abcdefghijklmnopqrstuvwxyz'
if len(S)==26:
  ans = 'None'
else:
  for i in range(len(S)):
    if al[i] != S[i]:
      ans = al[i]
      break
    else:
      ans = al[len(S)]
print(ans)