Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03151 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = sorted([A[i]-B[i] for i in range(N)])
tot = sum(C)
cnt = 0
if tot<0:
    cnt = -1
else:
    a = 0
    for i in range(N):
        if C[i]<0:
            a += C[i]
            cnt += 1
        else:
            break
    for i in range(N-1,-1,-1):
        if a>=0:break
        a += C[i]
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = sorted([A[i]-B[i] for i in range(N)],reverse=True)
cp = 0
cm = 0
for i in range(N):
    if C[i]>0:
        cp += C[i]
    elif C[i]<0:
        cm += -C[i]
if cm>cp:
    print(-1)
else:
    cur = 0
    tot = C[cur]
    for i in range(N):
        if C[i]<0:
            while tot-abs(C[i])<0:
                tot += C[cur+1]
                cur += 1
            tot += C[i]
print(cur+1+cm)
Problem p03173 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
B = [0 for _ in range(N+2)]
for i in range(N+1):
    B[i+1] = B[i]+A[i]
dp = [[0 for _ in range(N+2)] for _ in range(N+2)]
for i in range(N):
    dp[i][i+2] = A[i]+A[i+1]
for k in range(3,N+1):
    for i in range(1,N-k+2):
        dp[i][i+k] = dp[i][i+1]+dp[i+1][i+k]
        for j in range(i+2,i+k):
            dp[i][i+k] = min(dp[i][i+k],dp[i][j]+dp[j][i+k])
        dp[i][i+k] += B[i+k]-B[i]
print(dp[1][N+1])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
cnt = 0
while len(A)>1:
    cmin = 10**10
    for i in range(len(A)-2+1):
        if A[i]+A[i+1]<cmin:
            ind = i
            cmin = A[i]+A[i+1]
    cnt += cmin
    A[ind] += A[ind+1]
    A.pop(ind+1)
print(cnt)
Problem p03177 (python)

Fixed submission:
p = 10**9+7
def pow(X,k):
    if k==0:
        return [[1 if i==j else 0 for j in range(N)] for i in range(N)]
    if k==1:
        return X
    if k%2==0:
        Y = pow(X,k//2)
        Z = [[0 for _ in range(N)] for _ in range(N)]
        for i in range(N):
            for j in range(N):
                for m in range(N):
                    Z[i][j] = (Z[i][j]+Y[i][m]*Y[m][j])%p
        return Z
    else:
        Y = pow(X,(k-1)//2)
        Z = [[0 for _ in range(N)] for _ in range(N)]
        for i in range(N):
            for j in range(N):
                for m in range(N):
                    Z[i][j] = (Z[i][j]+Y[i][m]*Y[m][j])%p
        Z1 = [[0 for _ in range(N)] for _ in range(N)]
        for i in range(N):
            for j in range(N):
                for m in range(N):
                    Z1[i][j] = (Z1[i][j]+Z[i][m]*X[m][j])%p
        return Z1
N,K = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
X = pow(A,K)
cnt = 0
for i in range(N):
    for j in range(N):
        cnt = (cnt+X[i][j])%p
print(int(cnt))

Buggy submission (verdict: Runtime Error):
import numpy as np
p = 10**9+7
def pow(X,k):
    if k==0:
        return np.eye(X.shape[0])
    if k==1:
        return X
    if k%2==0:
        return np.dot(pow(X,k//2),pow(X,k//2))%p
    else:
        return np.dot(X,np.dot(pow(X,(k-1)//2),pow(X,(k-1)//2))%p)%p
N,K = map(int,input().split())
A = np.zeros((N,N))
for i in range(N):
    a = np.array(list(map(int,input().split())))
    A[i][:] = a[:]
X = pow(A,K)
cnt = 0
for i in range(N):
    for j in range(N):
        cnt = (cnt+X[i][j])%p
print(int(cnt))
Problem p03196 (python)

Fixed submission:
N,P = map(int,input().split())
if N==1 or P==1:
    print(P)
else:
    k = 0
    x = P
    while x>1:
        x = x//2
        k += 1
    if N>k:
        print(1)
    else:
        cmax = 1
        for i in range(1,int(P**0.5)+1):
            if P%(i**N)==0:
                cmax = i
        print(cmax)

Buggy submission (verdict: Runtime Error):
N,P = map(int,input().split())
if N==1:
    print(P)
else:
    cmax = 1
    for i in range(1,int(P**0.5)+1):
        if P%(i**N)==0:
            cmax = i
    print(cmax)
Problem p03215 (python)

Fixed submission:
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = [0 for _ in range(N+1)]
for i in range(1,N+1):
    B[i] = B[i-1]+A[i-1]
C = A[:]
for i in range(N-1):
    for j in range(i+1,N):
        C.append(B[j+1]-B[i])
C = sorted(C,reverse=True)
n = math.ceil(math.log2(C[0]))
Cb = []
for i in range(len(C)):
    x = bin(C[i])[2:]
    k = len(x)
    x = "0"*(n-k)+x
    Cb.append(x)
inds = [i for i in range(len(C))]
nlow = 0
while len(inds)>K:
    for j in range(nlow,n):
        E = []
        cnt = 0
        for i in inds:
            if Cb[i][j]=="1":
                E.append(i)
                cnt += 1
        if cnt>=K:
            inds = E[:]
            nlow = j+1
            break
    if cnt<K:break
cnt = int("1"*n,2)
for i in inds: 
    cnt = cnt&C[i]
print(cnt)

Buggy submission (verdict: Runtime Error):
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = [0 for _ in range(N+1)]
for i in range(1,N+1):
    B[i] = B[i-1]+A[i-1]
C = A[:]
for i in range(N-1):
    for j in range(i+1,N):
        C.append(B[j+1]-B[i])
C = sorted(C,reverse=True)
n = math.ceil(math.log2(C[0]))
Cb = []
for i in range(len(C)):
    x = bin(C[i])[2:]
    k = len(x)
    x = "0"*(n-k)+x
    Cb.append(x)
inds = [i for i in range(len(C))]
nlow = 0
while len(inds)>K:
    for j in range(nlow,n):
        E = []
        cnt = 0
        for i in inds:
            if Cb[i][j]=="1":
                E.append(i)
                cnt += 1
        if cnt>=K:
            inds = E[:]
            nlow = j+1
            break
    if cnt<K:break
cnt = int("1"*n,2)
for i in inds: 
    cnt = cnt&C[i]
print(cnt)
Problem p03229 (python)

Fixed submission:
from collections import deque
N = int(input())
A = deque(sorted([int(input()) for _ in range(N)]))
B = deque([])
B.append(A.popleft())
cnt = 0
while A:
    a0 = A[0]
    a1 = A[-1]
    b0 = B[0]
    b1 = B[-1]
    c00 = abs(a0-b0)
    c01 = abs(a0-b1)
    c10 = abs(a1-b0)
    c11 = abs(a1-b1)
    cmax = max(c00,c01,c10,c11)
    if cmax == c00:
        B.appendleft(A.popleft())
    elif cmax == c01:
        B.append(A.popleft())
    elif cmax == c10:
        B.appendleft(A.pop())
    else:
        B.append(A.pop())
    cnt += cmax
print(cnt)

Buggy submission (verdict: Runtime Error):
from collections import deque
N = int(input())
A = deque(sorted([int(input()) for _ in range(N)]))
que = deque([])
que.append(A.popleft())
while A:
    if turn == 1:
        a = A.pop()
        if abs(a-que[0])<=abs(a-que[-1]):
            que.append(a)
        else:
            que.appendleft(a)
        if A:
            a = A.pop()
            if abs(a-que[0])<=abs(a-que[-1]):
                que.append(a)
            else:
                que.appendleft(a)
    else:
        a = A.popleft()
        if abs(a-que[0])<=abs(a-que[-1]):
            que.append(a)
        else:
            que.appendleft(a)
        if A:
            a = A.popleft()
            if abs(a-que[0])<=abs(a-que[-1]):
                que.append(a)
            else:
                que.appendleft(a)
    turn = 1-turn
cnt = 0
for i in range(1,N):
    cnt += abs(que[i]-que[i-1])
print(cnt)

Buggy submission (verdict: Runtime Error):
from collections import deque
N = int(input())
A = deque(sorted([int(input()) for _ in range(N)]))
que = deque([])
que.append(A.popleft())
while A:
    if turn == 1:
        a = A.pop()
        if abs(a-que[0])<=abs(a-que[-1]):
                que.append(a)
            else:
                que.appendleft(a)
        if A:
            a = A.pop()
            if abs(a-que[0])<=abs(a-que[-1]):
                que.append(a)
            else:
                que.appendleft(a)
    else:
        a = A.popleft()
        if abs(a-que[0])<=abs(a-que[-1]):
                que.append(a)
            else:
                que.appendleft(a)
        if A:
            a = A.popleft()
            if abs(a-que[0])<=abs(a-que[-1]):
                que.append(a)
            else:
                que.appendleft(a)
    turn = 1-turn
cnt = 0
for i in range(1,N):
    cnt += abs(que[i]-que[i-1])
print(cnt)

Buggy submission (verdict: Runtime Error):
from collections import deque
N = int(input())
A = deque(sorted([int(input()) for _ in range(N)]))
que = deque([])
que.append(A.popleft())
turn = 1
while A:
    if turn == 1:
        que.appendleft(A.pop())
        if A:
            a = A.pop()
            if abs(a-q[0])<=abs(a-q[-1]):
                que.append(a)
            else:
                que.appendleft(a)
    else:
        que.appendleft(A.popleft())
        if A:
            a = A.pop()
            if abs(a-q[0])<=abs(a-q[-1]):
                que.append(a)
            else:
                que.appendleft(a)
    turn = 1-turn
cnt = 0
for i in range(1,N):
    cnt += abs(que[i]-que[i-1])
print(cnt)
Problem p03240 (python)

Fixed submission:
N = int(input())
D = [tuple(map(int,input().split())) for _ in range(N)]
D = sorted(D,key=lambda x:x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        ind = 1
        x,y,h = D[0]
        H = abs(x-cx)+abs(y-cy)+h
        for i in range(1,N):
            x,y,h = D[i]
            if h>0 and abs(x-cx)+abs(y-cy)+h!=H:
                ind = 0
                break
            elif h==0 and abs(x-cx)+abs(y-cy)<H:
                ind = 0
                break
        if ind==1:
            CX = cx
            CY = cy
            break
    if ind==1:break
print(CX,CY,H)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[2],reverse=True)
for x in range(101):
    for y in range(101):
        a,b,h = A[0]
        H = h+abs(x-a)+abs(y-b)
        flag = 1
        for i in range(1,N):
            a,b,h = A[i]
            if H==h+abs(x-a)+abs(y-b):continue
            else:
                flag = 0
                break
        if flag==1:
            cx = x
            cy = y
            break
    if flag==1:break
print(cx,cy,H)
Problem p03241 (python)

Fixed submission:
N,M = map(int,input().split())
k = 1
for i in range(1,int(M**0.5)+1):
    if M%i==0:
        a = i
        b = M//i
        k1 = 1
        k2 = 1
        if b>=N:
            k1 = a
        if a>=N:
            k2 = b
        k = max(k,k1,k2)
print(k)

Buggy submission (verdict: Runtime Error):
INFTY = 10**5
P = [1 for _ in range(INFTY)]
P[0]=0
P[1]=0
for i in range(2,int(INFTY**0.5)+1):
    for j in range(i*i,INFTY,i):
        P[j] = 0
N,M = map(int,input().split())
if N==1:
    x = M
elif P[M]==1:
    x = 1
else:
    b = M//N
    for i in range(b,0,-1):
        if M%i==0:
            x = i
            break
print(x)
Problem p03244 (python)

Fixed submission:
n = int(input())
V = list(map(int,input().split()))
De = {}
Do = {}
for i in range(n):
    x = V[i]
    if i%2==0:
        if x not in De:
            De[x] = 0
        De[x] += 1
    else:
        if x not in Do:
            Do[x] = 0
        Do[x] += 1
DeL = sorted(list(De.items()),key=lambda x:x[1],reverse=True)
DoL = sorted(list(Do.items()),key=lambda x:x[1],reverse=True)
y = DeL[0][0]
z = DoL[0][0]
if y!=z:
    n0 = n//2-De[y]
    n1 = n//2-Do[z]
elif y==z:
    if De[y]>Do[z]:
        z = DoL[1][0]
        n0 = n//2-De[y]
        n1 = n//2-Do[z]
    elif De[y]<Do[z]:
        y = DeL[1][0]
        n0 = n//2-De[y]
        n1 = n//2-Do[z]
    elif De[y]==Do[z]:
        if De[y]==n//2:
            n0 = 0
            n1 = n//2
        elif DeL[1][1]>=DoL[1][1]:
            y = DeL[1][0]
            n0 = n//2-De[y]
            n1 = n//2-Do[z]
        else:
            z = DoL[1][0]
            n0 = n//2-De[y]
            n1 = n//2-Do[z]
print(n0+n1)

Buggy submission (verdict: Runtime Error):
n = int(input())
V = list(map(int,input().split()))
De = {}
Do = {}
for i in range(n):
    x = V[i]
    if i%2==0:
        if x not in De:
            De[x] = 0
        De[x] += 1
    else:
        if x not in Do:
            Do[x] = 0
        Do[x] += 1
DeL = sorted(list(De.items()),key=lambda x:x[1],reverse=True)
DoL = sorted(list(Do.items()),key=lambda x:x[1],reverse=True)
y = DeL[0][0]
z = DoL[0][0]
if y!=z:
    n0 = n//2-De[y]
    n1 = n//2-Do[z]
elif y==z:
    if De[y]>Do[z]:
        z = DoL[1][0]
        n0 = n//2-De[y]
        n1 = n//2-Do[z]
    elif De[y]<Do[z]:
        y = DeL[1][0]
        n0 = n//2-De[y]
        n1 = n//2-Do[z]
    elif De[y]==Do[z]:
        if De[y]==n//2:
            no = 0
            n1 = n//2
        elif DeL[1][1]>=DoL[1][1]:
            y = DeL[1][0]
            n0 = n//2-De[y]
            n1 = n//2-Do[z]
        else:
            z = DoL[1][0]
            n0 = n//2-De[y]
            n1 = n//2-Do[z]
print(n0+n1)
Problem p03282 (python)

Fixed submission:
S = input().strip()
K = int(input())
cur = 0
a = 0
for i in range(len(S)):
    if S[i]!="1":
        a = S[i]
        break
    cur += 1
if K<cur+1:
    print("1")
else:
    print(a)

Buggy submission (verdict: Runtime Error):
S = input().strip()
K = int(input())
ind = len(S)+1
for i in range(len(S)):
    if S[i]!="1":
        ind = i+1
        break
if K<ind
    print(1)
else:
    print(S[ind-1])
Problem p03342 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
C = [0 for _ in range(N+1)]
for i in range(1,N+1):
    C[i] = C[i-1]^A[i-1]
A = [bin(A[i])[2:] for i in range(N)]
A = [A[i] if len(A[i])==20 else "0"*(20-len(A[i]))+A[i] for i in range(N)]
cnt = 0
cur = 0
for i in range(N):
    cnt += cur-i
    b = C[cur]^C[i]
    b = bin(b)[2:]
    if len(b)<20:
        b = "0"*(20-len(b))+b
    B = [int(b[j]) for j in range(20)]
    while cur<N:
        flag = 0
        for j in range(20):
            B[j] += int(A[cur][j])
            if B[j]>=2:
                flag = 1
                break
        if flag==1:break
        cnt += 1
        cur += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
A = [bin(A[i])[2:] for i in range(N)]
A = [x if len(x)==20 else "0"*(20-len(x))+x for x in A]
cnt = 0
for i in range(N):
    a = A[i]
    cnt += cur-i+1
    B = [int(a[j]) for j in range(20)]
    while True:
        cur += 1
        for j in range(20):
            B[j] += int(A[cur][j])
            if B[j]>=2:
                break
        cnt += 1
print(cnt)
Problem p03356 (python)

Fixed submission:
from bisect import bisect_left
def rt(i):
    while i!=G[i][0]:
        i = G[i][0]
    return i
N,M = map(int,input().split())
P = list(map(int,input().split()))
P.insert(0,0)
G = {i:[i,1] for i in range(1,N+1)}
for _ in range(M):
    x,y = map(int,input().split())
    rx = rt(x)
    ry = rt(y)
    if rx!=ry:
        if G[rx][1]>=G[ry][1]:
            G[ry][0] = rx
            G[rx][1] += G[ry][1]
        else:
            G[rx][0] = ry
            G[ry][1] += G[rx][1]
hist = [0 for _ in range(N+1)]
A = {}
for i in range(1,N+1):
    ri = rt(i)
    if hist[ri]==0:
        A[ri] = []
        hist[ri] = 1
    A[ri].append(i)
cnt = 0
for a in A:
    B = []
    for i in range(len(A[a])):
        B.append(P[A[a][i]])
    B = sorted(B)
    B.append(10**8)
    cur = 0
    for i in range(len(A[a])):
        if A[a][i]==B[cur]:
            cnt += 1
        elif A[a][i]<B[cur]:
            continue
        else:
            cur = bisect_left(B,A[a][i])
            if B[cur]==A[a][i]:
                cnt += 1
                cur += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
from collections import deque
N,M = map(int,input().split())
P = list(map(int,input().split()))
P.insert(0,0)
G = {i:[] for i in range(1,N+1)}
for _ in range(M):
    x,y = map(int,input().split())
    G[x].append(y)
    G[y].append(x)
A = []
hist = [0 for _ in range(N+1)]
for i in range(1,N+1):
    if hist[i]==0:
        C = [i]
        hist[i]=1
        que = deque([i])
        while que:
            x = que.popleft()
            for y in G[x]:
                if hist[y]==0:
                    que.append(y)
                    C.append(y)
                    hist[y]=1
        C = sorted(C)
        A.append(C)
cnt = 0
for C in A:
    B = []
    for c in C:
        B.append(P[c])
    B = sorted(B)
    cur = 0
    for i in range(len(C)):
        if C[i]==B[cur]:
            cnt += 1
            cur += 1
        elif C[i]<B[cur]:
            continue
        elif C[i]>B[cur]:
            while C[i]>B[cur]:
                cur += 1
            if B[cur]==C[i]:
                cnt += 1
            else:
                continue
print(cnt)
Problem p03387 (python)

Fixed submission:
A = sorted(list(map(int,input().split())))
a,b,c = A[0],A[1],A[2]
if (b-a)%2==0:
    cnt = (b-a)//2+c-b
else:
    cnt = 1+(b+1-a)//2+c-b
print(cnt)

Buggy submission (verdict: Runtime Error):
D = sorted(list(map(int,input().split())))
A,B,C = D
if (C-B)%2==0 and (B-A)%2==0:
    n = (C-B)//2+(C-A)//2
elif (C-B)%2==1 and (B-A)%2==0:
    n = (B-A)//2+(C-B)
elif (C-B)%2==0 and (B-A)%2==1:
    n = (C-B)//2+1 +(C+1-A)//2
elif (C-B)%2==1 and (B-A%2==1):
    n = 1+(C-B-1)//2+(C-A-1)//2
print(n)
Problem p03403 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
tot = abs(A[1])+abs(A[N])
for i in range(2,N+1):
    tot += abs(A[i]-A[i-1])
for i in range(1,N+1):
    if i==1:
        print(tot-abs(A[1])-abs(A[2]-A[1])+abs(A[2]))
    elif i==N:
        print(tot-abs(A[N])-abs(A[N]-A[N-1])+abs(A[N-1]))
    else:
        print(tot-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))

Buggy submission (verdict: Runtime Error):
A = list(map(int,input().split()))
A.insert(0,0)
tot = 0
for i in range(1,N+1):
    tot += abs(A[i]-A[i-1])
tot += abs(A[0]-A[N])
for i in range(1,N):
    a = tot-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])
    print(a)
a = tot-abs(A[N]-A[N-1])-abs(0-A[N])+abs(0-A[N-1])
print(a)
Problem p03424 (python)

Fixed submission:
N = int(input())
S = list(input().split())
ind = 0
for i in range(N):
    if S[i]=="Y":
        ind = 1
        break
if ind==1:
    print("Four")
else:
    print("Three")

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(map(int,input().split()))
ind = 0
for i in range(N):
    if S[i]=="Y":
        ind = 1
        break
if ind==1:
    print("Four")
else:
    print("three")
Problem p03449 (python)

Fixed submission:
N = int(input())
A = [list(map(int,input().split())) for _ in range(2)]
B = [0 for _ in range(N+1)]
for i in range(1,N+1):
    B[i] = B[i-1]+A[0][i-1]
C = [0 for _ in range(N+1)]
for i in range(1,N+1):
    C[i] = C[i-1]+A[1][i-1]
cmax = 0
for i in range(N):
    a = B[i+1]+C[N]-C[i]
    cmax = max(cmax,a)
print(cmax)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int,input().split())) for _ in range(2)]
B = [0 for _ in range(N+1)]
for i in range(1,N+1):
    B[i] = B[i-1]+A[0][i-1]
C = [0 for _ in range(N+1)]
for i in range(1,N):
    C[i] = C[i-1]+A[1][i-1]
cmax = 0
for i in range(N):
    a = A[i+1]+B[N]-B[i]
    cmax = max(cmax,)
print(cmax)
Problem p03533 (python)

Fixed submission:
from itertools import product
S = input().strip()
x = ["","K","I","H","","B","","R",""]
y = [0,4,6,8]
flag=0
for z in product((0,1),repeat=4):
    x1 = x[:]
    for i in range(4):
        if z[i]==1:
            x1[y[i]] = "A"
    x1 = "".join(x1)
    if x1==S:
        flag=1
        break
if flag==1:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
D = ["A","B","H","I","K","R"]
C = {a:0 for a in D}
C = {"X":0}
S = input().strip()
for i in range(len(S)):
    if S[i] in D:
        C[S[i]] += 1
    else:
        C["X"] += 1
if C["A"]<=4 and C["B"]==1 and C["H"]==1 and C["I"]==1 and C["K"]==1 and C["R"]==1 and C["X"]==0:
    print("YES")
else:
    print("NO")
Problem p03544 (python)

Fixed submission:
memo = {}
def L(n):
    if n==0:
        return 2
    elif n==1:
        return 1
    elif n in memo:
        return memo[n]
    memo[n] = L(n-1)+L(n-2)
    return memo[n]
print(L(int(input())))

Buggy submission (verdict: Runtime Error):
memo = {}
def L(n):
    if n==0:
        return 2
    elif n==1:
        return 1
    elif n in memo:
        return memo[n]
    memo[n] = L[n-1]+L[n-2]
    return memo[n]
print(L(int(input())))

Buggy submission (verdict: Runtime Error):
memo = {}
def L(n):
    if n==0:
        return 2
    elif n==1:
        return 1
    elif n in memo:
        return memo[n]
    memo[n] = memo[n-1]+memo[n-2]
    return memo[n]
print(L(int(input())))
Problem p03546 (python)

Fixed submission:
INFTY = 10**4
H,W = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]

d = [[INFTY for _ in range(10)] for _ in range(10)]
for i in range(10):
    for j in range(10):
        d[i][j] = C[i][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])

cnt = 0
for i in range(H):
    for j in range(W):
        if A[i][j]>-1:
            cnt += d[A[i][j]][1]
print(cnt)

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
B = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]

for i in range(10):
    for j in range(10):
        for k in range(10):
            B[i][j] = min(B[i][j],B[i][k]+B[k][j])
G = {i:0 for i in range(-1,10)}
for i in range(H):
    for j in range(W):
        G[A[i][j]] += 1
cnt = 0
for i in range(2,10):
    cnt += G[i]*C[i][1]
print(cnt)
Problem p03547 (python)

Fixed submission:
X,Y = input().strip().split()
if X>Y:
    print(">")
elif X<Y:
    print("<")
else:
    print("=")

Buggy submission (verdict: Runtime Error):
X,Y = input().strip()
if X>Y:
    print(">")
elif Y<X:
    print("<")
else:
    print("=")
Problem p03550 (python)

Fixed submission:
N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
if N>=2:
    print(max(abs(A[-1]-A[-2]),abs(A[-1]-W)))
else:
    print(abs(A[0]-W))

Buggy submission (verdict: Runtime Error):
memof = {}
def f(x,y,i):
    if i==N-1:
        return abs(A[N-1]-y)
    if (x,y,i) in memof:
        return memo[(x,y,i)]
    b = abs(A[N-1]-y)
    for j in range(i,N-1):
        b = max(b,g(A[j],y,j+1))
    memof[(x,y,i)]=b
    return b
memog = {}
def g(x,y,i):
    if i==N-1:
        return abs(x-A[N-1])
    if (x,y,i) in memog:
        return memog[(x,y,i)]
    b = abs(x-A[N-1])
    for j in range(i,N-1):
        b = min(b,f(x,A[j],j+1))
    memog[(x,y,i)] = b
    return b
N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
print(f(Z,W,0))

Buggy submission (verdict: Runtime Error):
def f(x,y,i):
    if i==N-1:
        return abs(A[N-1]-y)
    b = abs(A[N-1]-y)
    for j in range(i,N-1):
        b = max(b,g(A[j],y,j+1))
    return b
def g(x,y,i):
    if i==N-1:
        return abs(x-A[N-1])
    b = abs(x-A[N-1])
    for j in range(i,N-1):
        b = min(b,f(x,A[j],j+1))
    return b
N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
print(f(Z,W,0))