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

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

def main():
    n,q=map(int,input().split())
    t=[[] for _ in range(n+1)]
    cnt=[0]*(n+1)
    tf=[0]*(n+1)
    for i in range(n-1):
        a,b=map(int,input().split())
        t[a].append(b)
        t[b].append(a)
    for i in range(q):
        p,x=map(int,input().split())
        cnt[p]+=x
    d=deque()
    d.append(1)
    tf[1]=1
    while d:
        chk=d.popleft()
        for i in t[chk]:
            if tf[i]==1:
                continue
            else:
                d.append(i)
                tf[i]=1
                cnt[i]+=cnt[chk]
    print(' '.join(map(str,cnt[1:])))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n,q=map(int,input().split())
    ab=[[] for _ in range(n)]
    for i in range(n-1):
        a,b=map(int,input().split())
        ab[a-1].append(b-1)
        ab[b-1].append(a-1)
    visit=[False]*n
    cnt=[0]*n
    for i in range(q):
        p,x=map(int,input().split())
        cnt[p-1]+=x

    def solve(s,x):
        visit[s]=True
        cnt[s]+=x
        x=cnt[s]
        for i in ab[s]:
            if visit[i]:
                continue
            solve(i,x)
        return
    
    solve(0,0)
    print(*cnt, sep=' ')

if __name__ == '__main__':
    main()
Problem p02973 (python)

Fixed submission:
from bisect import bisect_right,bisect_left
n=int(input())
a=[int(input()) for _ in range(n)]
INF=float('INF')
l=[INF]*n
for i in a[::-1]:
    l[bisect_right(l,i)]=i
print(bisect_left(l,INF))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
import heapq
n=int(input())
l=[]
l.append(int(input()))
heapq.heapify(l)
for i in range(n-1):
    a=int(input())
    x=bisect_left(l,a)
    if x==0:
        heapq.heappush(l,a)
    else:
        l[x-1]=a
    print(l)
print(len(l))
Problem p03148 (python)

Fixed submission:
import heapq
n,k=map(int,input().split())
td=[[0]*2 for _ in range(n)]
for i in range(n):
    t,d=map(int,input().split())
    td[i][0],td[i][1]=d,t
td.sort(reverse=True)
di=set()
sa=[]
heapq.heapify(sa)
ans=0
for d,t in td[:k]:
    if t in di:
        heapq.heappush(sa, d)
    else:
        di.add(t)
    ans+=d

s=[-10**18]*(k+1)
cnt=len(di)
s[cnt]=ans
for d,t in td[k:]:
    if t in di:
        continue
    else:
        if sa:
            x=heapq.heappop(sa)
            ans+=d-x
            di.add(t)
            cnt+=1
            s[cnt]=ans

for i in range(k+1):
    s[i]+=i*i

print(max(s))

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int,input().split())
td=[[0]*2 for _ in range(n)]
for i in range(n):
    t,d=map(int,input().split())
    td[i][0],td[i][1]=d,t
td.sort(reverse=True)
di=set()
sa=deque()
ans=0
for d,t in td[:k]:
    if t in di:
        sa.append(d)
    else:
        di.add(t)
    ans+=d

s=[0]*(k+1)
cnt=len(di)
s[cnt]=ans
for d,t in td[k:]:
    if t in di:
        continue
    else:
        x=sa.popleft()
        ans+=d-x
        di.add(t)
        cnt+=1
        s[cnt]=ans

for i in range(k+1):
    s[i]+=i*i

print(max(s))
Problem p03160 (python)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
c=[0]*n
c[1]=abs(h[0]-h[1])
for i in range(2,n):
    c[i]=min(c[i-2]+abs(h[i]-h[i-2]),c[i-1]+abs(h[i]-h[i-1]))
print(c[n-1])

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
h=np.array(list(map(int,input().split()))+[0]*2)
dp = np.full(n+k, 10 ** 10, dtype=np.int64)
dp[0] = 0
for i in range(1,n):
    dp[i:i+2]=np.minimum(dp[i:i+2],np.abs(h[i:i+2]-h[i-1])+dp[i-1])
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
import numpy as np
n=map(int,input().split())
k=2
h=np.array(list(map(int,input().split()))+[0]*k)
dp = np.full(n+k, 10 ** 10, dtype=np.int64)
dp[0] = 0
for i in range(1,n):
    dp[i:i+k]=np.minimum(dp[i:i+k],np.abs(h[i:i+k]-h[i-1])+dp[i-1])
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
c=[0]*n
for i in range(1,n):
    c[i]=min([cj+abs(h[i]-hj) for cj,hj in zip(c[max(0,i-k):i],h[max(0,i-k):i])])
print(c[-1])
Problem p03161 (python)

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
c=[0]*n
for i in range(1,n):
    c[i]=min([cj+abs(h[i]-hj) for cj,hj in zip(c[max(0,i-k):i],h[max(0,i-k):i])])
print(c[-1])

Buggy submission (verdict: Runtime Error):
3 1
10 20 10
Problem p03163 (python)

Fixed submission:
n,W=map(int,input().split())
dp=[[0]*(W+1) for _ in range(n+1)]
for i in range(1,n+1):
    w,v=map(int,input().split())
    for j in range(1,W+1):
        if j-w<0:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
print(max(dp[n]))

Buggy submission (verdict: Runtime Error):
n,W=map(int,input().split())
dp=[[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
	w,v=map(int,input().split())
	for j in range(1,W+1):
		if j-w>0:
			dp[i][j]=dp[i-1][j]
		else:
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
print(max(dp[n])

Buggy submission (verdict: Runtime Error):
n,W=map(int,input().split())
dp=[[0]*(w+1) for _ in range(n+1)]
for i in range(1,n+1):
	w,v=map(intinput().split())
	for j in range(1,W+1):
		if j-w>0:
			dp[i][j]=dp[i-1][j]
		else:
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
print(max(dp[n])
Problem p03164 (python)

Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np
INF=10**9+1
def main():
    n, W = map(int, input().split())
    dp = np.full(n*1000+1,INF,dtype=int)
    dp[0]=0
    for i in range(1,n+1):
        w,v=map(int,input().split())
        dp[v:]=np.minimum(dp[v:],dp[:-v]+w)
    for i in range(len(dp)-1, -1, -1):
        if dp[i] <= W:
            print(i)
            break

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np

def main():
    n, W = map(int, input().split())
    dp = np.zeros(W + 1, dtype = np.int64)
    for i in range(n):
        w,v=map(int,input().split())
        dp[w:]=np.maximum(dp[w:],dp[:-w]+v)
    print(max(dp))

if __name__ == '__main__':
    main()
Problem p03219 (python)

Fixed submission:
x,y=map(int,input().split())
print(x+y//2)

Buggy submission (verdict: Runtime Error):
def resolve():
    n,m=map(int,input().split())
    py=[[0]*3 for _ in range(m)]
    for i in range(m):
        p,y=map(int,input().split())
        py[i][0],py[i][1],py[i][2]=p,y,i
    py.sort()
    ans=[[''] for _ in range(m)]
    cnt=[0]*(n+1)
    for p,y,i in py:
        cnt[p]+=1
        ans[i]='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(cnt[p])))+str(cnt[p])
    for i in ans:
        print(i)


if __name__ == '__main__':
    resolve()
Problem p03260 (python)

Fixed submission:
a,b=map(int,input().split())
if a*b%2==0:
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if ab%2==0:
  print('NO')
else:
  print('Yes')
Problem p03261 (python)

Fixed submission:
def resolve():
    n=int(input())
    w=[input() for _ in range(n)]
    chk=[]
    chk.append(w[0])
    ans='Yes'
    for i in range(1,n):
        if w[i-1][-1]!=w[i][0] or (w[i] in chk):
            ans='No'
            break
        chk.append(w[i])
    print(ans)

if __name__ == '__main__':
    resolve()

Buggy submission (verdict: Runtime Error):
    w=[input() for _ in range(n)]
    chk=[]
    chk.append(w[0])
    ans='Yes'
    for i in range(1,n):
        if w[i-1][-1]!=w[i][0] or (w[i] in chk):
            ans='No'
            break
        chk.append(w[i])
    print(ans)

if __name__ == '__main__':
    resolve()
Problem p03263 (python)

Fixed submission:
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
ans=[]
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            ans.append([i+1,j+1,i+1,j+2])
for i in range(h-1):
    if a[i][w-1]%2==1:
        a[i+1][w-1]+=1
        ans.append([i+1,w,i+2,w])
print(len(ans))
for i in ans:
    print(*i)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
ans=[]
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            ans.append([i+1,j+1,i+1,j+2])
for i in range(h-1):
    if a[i][j]==1:
        a[i+1][j]+=1
        ans.append([i+1,j+1,i+2,j+1])
print(len(ans))
for i in ans:
    print(*i)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[list(map(lambda x:int(x)%2,input().split())) for _ in range(h)]
maxnum=sum(sum(a))//2
ans=[]
bx,by,cnt=0,0,0
if a[0][0]==0:
    flg=0#0はスタートを探しモード
else:
    flg=1
for i in range(1,h*w):
    if (i//w)%2==0:
        x,y=i%w,(i//w)%2
    else:
        x,y=w-1-i%w,(i//w)%2
    if flg==1:
        a[y][x]=(a[y][x]+1)%2
        ans.append([by,bx,y,x])
        cnt+=1
    if maxnum==cnt:
        break
    flg=a[y][x]
    bx,by=x,y
print(len(ans))
for a,b,c,d in ans:
    print(a+1,b+1,c+1,d+1)
Problem p03276 (python)

Fixed submission:
def resolve():
    from bisect import bisect
    n,k=map(int,input().split())
    x=list(map(int,input().split()))
    g=bisect(x,0)
    if x[n-1]<=0:
        print(abs(x[n-k]))
    elif x[0]>=0:
        print(x[k-1])
    else:
        if g>=k:
            s=g-k
        else:
            s=0
        t=0
        while s<=n-k:
            if x[s]<0 and x[s+k-1]>0:
                if t==0:
                    t=min(2*abs(x[s])+x[s+k-1],abs(x[s])+2*x[s+k-1])
                else:
                    t=min(t,2*abs(x[s])+x[s+k-1],abs(x[s])+2*x[s+k-1])
            else:
                t=min(t,max(abs(x[s]),abs(x[s+k-1])))
            s+=1
        print(t)
resolve()

Buggy submission (verdict: Runtime Error):
    from bisect import bisect
    n,k=map(int,input().split())
    x=list(map(int,input().split()))
    g=bisect(x,0)
    if x[n-1]<=0 or x[0]>=0:
        print(max(abs(x[k-1]),abs(x[0])))
    else:
        if g>=k:
            s=g-k
        else:
            s=0
        t=0
        while s<=n-k:
            if x[s]<0 and x[s+k-1]>0:
                if t==0:
                    t=min(2*abs(x[s])+x[s+k-1],abs(x[s])+2*x[s+k-1])
                else:
                    t=min(t,2*abs(x[s])+x[s+k-1],abs(x[s])+2*x[s+k-1])
            else:
                t=min(t,max(abs(x[s]),abs(x[s+k-1])))
            s+=1
        print(t)
Problem p03866 (python)

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

    import heapq
    def dijkstra_heap(s,g,edge):
        #始点sから各頂点への最短距離
        d = [10**20] * (n+2)
        used = [True] * (n+2) #True:未確定
        d[s] = 0
        used[s] = False
        edgelist = []
        sx,sy,sr=edge[s][0],edge[s][1],edge[s][2]
        for i in range(n+2):
            x,y,r=edge[i][0],edge[i][1],edge[i][2]
            dist=((x-sx)**2+(y-sy)**2)**(1/2)
            heapq.heappush(edgelist,(max(dist-r-sr,0),i))
        while len(edgelist):
            minedge = heapq.heappop(edgelist)
            #まだ使われてない頂点の中から最小の距離のものを探す
            v = minedge[1]
            if not used[v]:
                continue
            d[v] = minedge[0]
            used[v] = False
            bx,by,br=edge[v][0],edge[v][1],edge[v][2]
            for i in range(n+2):
                x,y,r=edge[i][0],edge[i][1],edge[i][2]
                dist=((x-bx)**2+(y-by)**2)**(1/2)
                if used[i]:
                    heapq.heappush(edgelist,(max(dist-r-br,0)+d[v],i))
            if not used[g]:
                break
        return d[g]

    sx,sy,gx,gy = map(int,input().split()) #n:頂点数　w:辺の数
    n=int(input())
    edge=[(sx,sy,0),(gx,gy,0)]
    for i in range(2,n+2):
        x,y,r=map(int,input().split())
        edge.append((x,y,r))
    print(dijkstra_heap(0,1,edge))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import heapq
def dijkstra_heap(s,g,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * (n+2)
    used = [True] * (n+2) #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    sx,sy,sr=edge[s][0],edge[s][1],edge[s][2]
    for i in range(n+2):
        x,y,r=edge[i][0],edge[i][1],edge[i][2]
        dist=((x-sx)**2+(y-sy)**2)**(1/2)
        heapq.heappush(edgelist,int(max(dist-r-sr,0)*(10**9))*10000+i)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        dis=(minedge//(10**4))/10**9
        v = int(minedge-dis*10**13)
        if not used[v]:
            continue
        d[v] = dis
        used[v] = False
        bx,by,br=edge[v][0],edge[v][1],edge[v][2]
        for i in range(n+2):
            x,y,r=edge[i][0],edge[i][1],edge[i][2]
            dist=((x-bx)**2+(y-by)**2)**(1/2)
            if used[i]:
                heapq.heappush(edgelist,int((max(dist-r-br,0)+d[v])*(10**9))*10000+i)
        if not used[g]:
            break
    return d[g]

sx,sy,gx,gy = map(int,input().split()) #n:頂点数　w:辺の数
n=int(input())
edge=[[sx,sy,0],[gx,gy,0]]
for i in range(2,n+2):
    x,y,r=map(int,input().split())
    edge.append([x,y,r])
print(dijkstra_heap(0,1,edge))
Problem p02600 (python)

Fixed submission:
X = int(input())
 
if 400 <= X < 600:
    result = 8
elif X < 800:
    result = 7
elif X < 1000:
    result = 6
elif X < 1200:
    result = 5
elif X < 1400:
    result = 4
elif X < 1600:
    result = 3
elif X < 1800:
    result = 2
elif X < 2000:
    result = 1
 
print(result)

Buggy submission (verdict: Runtime Error):
X = int(input())

if 400 <= X < 600:
    result = 8
elif X < 800:
    result = 7
elif X < 1000:
    result = 6
elif X < 1200:
    result = 5
elif X < 1400:
    result = 4
elif X < 1600:
    result = 3
elif X < 1800:
    result = 2
elif X < 200:
    result = 1

print(result)
Problem p02885 (python)

Fixed submission:
A, B = map(int, input().split())
print(max(A - 2 * B, 0))

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
print(max(A - 2 * B), 0)
Problem p02900 (python)

Fixed submission:
def gcd(x, y):
    while y != 0:
        r = x % y
        x = y
        y = r
    return x

A, B = map(int, input().split())
gcd = gcd(A, B)
result = 1
d = 2
while d * d <= gcd:
    e = 0
    while gcd % d == 0:
        gcd //= d
        e += 1
    if e > 0:
        result += 1
    d += 1
if gcd > 1:
    result += 1
print(result)

Buggy submission (verdict: Runtime Error):
import numpy as np

A, B = map(int, input().split())
gcd = np.gcd(A, B)
result = 1
d = 2
while d * d <= gcd:
    e = 0
    while gcd % d == 0:
        gcd //= d
        e += 1
    if e > 0:
        result += 1
    d += 1
if gcd > 1:
    result += 1
print(result)
Problem p03049 (python)

Fixed submission:
N = int(input())
s = [input() for i in range(N)]

count_AB = [s[i].count("AB") for i in range(N)]

headB = 0
tailA = 0
headB_and_tailA = 0
for i in range(N):
    #print("i =", i)
    if s[i][0] == 'B':
        if s[i][-1] != 'A':
            #print("headB")
            headB += 1
        else:
            headB_and_tailA += 1
            #print("both")
    elif s[i][-1] == 'A':
        tailA += 1
        #print("tailA")

"""
print("both =", headB_and_tailA)
print("headB = ", headB)
print("tailA = ", tailA)
"""
result = sum(count_AB) + min(headB, tailA)
headB -= min(headB, tailA)
tailA -= min(headB, tailA)
for _ in range(headB_and_tailA):
    if tailA > 0:
        result += 1
    elif headB > 0:
        result += 1
    else:
        tailA += 1
#print("sum = ", sum(count_AB))
    
print(result)

Buggy submission (verdict: Runtime Error):
N = int(input())
s = [input() for i in range(N)]

count_AB = [s[i].count("AB") for i in range(N)]

headB = 0
tailA = 0
headB_and_tailA = 0
for i in range(N):
    #print("i =", i)
    if s[i][0] == 'B':
        if s[i][-1] != 'A':
            #print("headB")
            headB += 1
        else:
            headB_and_tailA += 1
            #print("both")
    elif s[i][-1] == 'A':
        tailA += 1
        #print("tailA")

"""
print("both =", headB_and_tailA)
print("headB = ", headB)
print("tailA = ", tailA)
"""
result = sum(count_AB) + min(headB, tailA)
headB -= min(headB, tailA)
tailA -= min(headB, tailA)
for _ in range(headB_and_tailA):
    if tailA > 0:
        result += 1
    elif tailB > 0:
        result += 1
    else:
        tailA += 1
#print("sum = ", sum(count_AB))
    
print(result)
Problem p03071 (python)

Fixed submission:
A, B = map(int, input().split())
if A > B:
    result = A + (A - 1)
elif A < B:
    result = B + (B - 1)
else:
    result = A + B
print(result)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A > B:
    result = A + (A - 1)
elif A < B:
    reuslt = B + (B - 1)
else:
    result = A + B
print(result)
Problem p03284 (python)

Fixed submission:
N, K = map(int, input().split())
print(0 if N % K == 0 else 1)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
print(f"{N % K != 0:d}")
Problem p03421 (python)

Fixed submission:
N, A, B = map(int, input().split())
def solve():
    if A + B - 1 <= N and N <= A * B:
        if A == 1:
            return [i for i in range(N, 0, -1)]
        s = []
        q = (N - B) // (A - 1)
        r = (N - B) % (A - 1)
        if r == 0:
            q -= 1
            r = A - 1
        for i in range(B - q - 1):
            s.append(N - i)
        for i in range(r + 1):
            s.append(A * q + 1 + i)
        for i in range(q - 1, -1, -1):
            for j in range(A):
                s.append(A * i + j + 1)
        return s
    else:
        return [-1]
print(" ".join(map(str, solve())))

Buggy submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
def solve():
    if A + B - 1 <= N and N <= A * B:
        s = []
        q = (N - B) // (A - 1)
        r = (N - B) % (A - 1)
        if r == 0:
            q -= 1
            r = A - 1
        for i in range(B - q - 1):
            s.append(N - i)
        for i in range(r + 1):
            s.append(A * q + 1 + i)
        for i in range(q - 1, -1, -1):
            for j in range(A):
                s.append(A * i + j + 1)
        return " ".join(map(str, s))
    else:
        return "-1"
print(solve())
Problem p03673 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
print(*a[-1::-2]+a[n%2::2])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
print(*a[-1::-2],*a[n%2::2])
Problem p02579 (python)

Fixed submission:
from collections import deque

h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
ch-=1
cw-=1
dh-=1
dw-=1

maze=[list(input()) for i in range(h)]

Q=deque()
Q.append((ch,cw,0))

dx=[1,0,-1,0]
dy=[0,1,0,-1]
ddx=[2,2,2,2,2,-2,-2,-2,-2,-2,1,1,1,1,-1,-1,-1,-1,0,0]
ddy=[-2,-1,0,1,2,-2,-1,0,1,2,2,1,-1,-2,2,1,-1,-2,2,-2]

dp=[[float('inf')]*w for i in range(h)]


while Q:
  p=Q.popleft()
  if p[0]==dh and p[1]==dw:
    print(p[2])
    exit()
  
  for i in range(4):
    nx=p[0]+dx[i]
    ny=p[1]+dy[i]

    if 0<=nx<h and 0<=ny<w and maze[nx][ny]=='.' and p[2]<dp[nx][ny]:
      Q.appendleft((nx,ny,p[2]))
      dp[nx][ny]=p[2]

  for j in range(20):
    nnx=p[0]+ddx[j]
    nny=p[1]+ddy[j]

    if 0<=nnx<h and 0<=nny<w and maze[nnx][nny]=='.' and p[2]+1<dp[nnx][nny]:
      Q.append((nnx,nny,p[2]+1))
      dp[nnx][nny]=p[2]+1


print(-1)

Buggy submission (verdict: Runtime Error):
distance=[[10**10 for j in range(w)] for i in range(h)]

distance[ch][cw]=0


Q=deque()
Q.append((ch,cw))



while Q:
  p=Q.popleft()
  flag=False

  if p[0]==dh and p[1]==dw:
    break
  
  dx=[1,1,-1,-1]
  dy=[-1,1,-1,1]
  dddx=[0,0,2,-2,2,2,2,2,1,1,1,1,-2,-2,-2,-2,-1,-1,-1,-1]
  dddy=[2,-2,0,0,2,1,-1,-2,2,1,-1,-2,2,1,-1,-2,2,1,-1,-2]

  for i in range(4):
    nx=p[0]+dx[i]
    ny=p[1]+dy[i]

    if 0<=nx<h and 0<=ny<w and maze[nx][ny]!='#' and distance[p[0]][p[1]]<distance[nx][ny]:
      Q.appendleft((nx,ny))
      flag=True
      distance[nx][ny]=distance[p[0]][p[1]]

  if flag:
    continue

  for j in range(20):
    nnnx=p[0]+dddx[j]
    nnny=p[1]+dddy[j]

    if 0<=nnnx<h and 0<=nnny<w and maze[nnnx][nnny]!='#' and distance[p[0]][p[1]]<distance[nnnx][nnny]+1:
      Q.append((nnnx,nnny))
      distance[nnnx][nnny]=distance[p[0]][p[1]]+1


if distance[dh][dw]==10**10:
  print(-1)
  exit()


print(distance[dh][dw])

Buggy submission (verdict: Runtime Error):
from collections import deque

h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
ch-=1
cw-=1
dh-=1
dw-=1

maze=[list(input()) for i in range(h)]
distance=[[float('inf') for j in range(w)] for i in range(h)]

distance[ch][cw]=0


Q=deque()
Q.append((ch,cw))


while Q:
  p=Q.popleft()
  if p[0]==dh and p[1]==dw:
    break
  
  dx=[1,1,-1,-1]
  dy=[-1,1,-1,1]
  dddx=[2,2,2,2,2,1,1,1,1,1,0,0,0,0,-1,-1,-1,-1,-1,-2,-2,-2,-2,-2]
  dddy=[2,1,0,-1,-2,2,1,0,-1,-2,2,1,-1,-2,2,1,0,-1,-2,2,1,0,-1,-2]

  for i in range(4):
    nx=p[0]+dx[i]
    ny=p[1]+dy[i]

    if 0<=nx<h and 0<=ny<w and maze[nx][ny]!='#':
      if distance[nx][ny]<distance[p[0]][p[1]]:
        Q.append((nx,ny))
      distance[nx][ny]=distance[p[0]][p[1]]

  
  for j in range(24):
    nnnx=p[0]+dddx[j]
    nnny=p[0]+dddy[j]

    if 0<=nnnx<h and 0<=nnny<w and maze[nnnx][nnny]!='#':
      
      Q.appendleft((nx,ny))
      distance[nnnx][nnny]=min(distance[nnnx][nnny],distance[p[0]][p[1]]+1)


if distance[dh][dw]==float('inf'):
  print(-1)
  exit()


print(distance[dh][dw])
Problem p02586 (python)

Fixed submission:
r,c,k=map(int,input().split())
lst=[[0]*(c+1) for i in range(r+1)]
for i in range(k):
  s,t,u=map(int,input().split())
  lst[s][t]=u


dp1=[[0]*(c+1) for i in range(r+1)]
dp2=[[0]*(c+1) for i in range(r+1)]
dp3=[[0]*(c+1) for i in range(r+1)]

for i in range(1,r+1):
  for j in range(1,c+1):
    dp1[i][j]=max(dp1[i][j-1],dp1[i-1][j]+lst[i][j],dp2[i-1][j]+lst[i][j],dp3[i-1][j]+lst[i][j])
    dp2[i][j]=max(dp2[i][j-1],dp1[i][j-1]+lst[i][j])
    dp3[i][j]=max(dp3[i][j-1],dp2[i][j-1]+lst[i][j])

print(max(dp1[-1][-1],dp2[-1][-1],dp3[-1][-1],0))

Buggy submission (verdict: Runtime Error):
R,C,k=map(int,input().split())
h=[]
w=[]
v=[]

for i in range(k):
  ss,tt,uu=map(int,input().split())
  h.append(ss-1)
  w.append(tt-1)
  v.append(uu)
  
dp=[[[0]*(C+1) for i in range(R+1)] for _ in range(k+1)]

for i in range(k):
  for s in range(R+1):
    cnt=0
    for t in range(C+1):
      if h[i]>s or w[i]>t:
        dp[i+1][s][t]=dp[i][s][t]

      else:
        s==h[i] and t==w[i]:
          

      if dp[i+1][s][t]!=dp[i+1][s][t-1]:
        cnt+=1

print(dp[-1][-1][-1])
Problem p02641 (python)

Fixed submission:
x,n=map(int,input().split())
a=list(map(int,input().split()))
if n==0:
  ans=x
else:
  ans=0
  for i in range(101):
    y=x-i
    if y not in a:
      ans=y
      break
    z=x+i
    if z not in a:
      ans=z
      break
print(ans)

Buggy submission (verdict: Runtime Error):
x,n=map(int,input().split())
a=list(map(int,input().split()))
if n==0:
  print(x)
else:
  ans=0
  for i in range(101):
    y=x-i
    if y not in a:
      ans=y
      break
    z=x+i
    if z not in a:
      ans=z
      break
print(ans)

Buggy submission (verdict: Runtime Error):
x,n=map(int,input().split())
a=list(map(int,input().split()))
if n==0:
  print(x)
else:
  ans=0
  for i in range(n):
    y=x-i
    if y not in a:
      ans=y
      break
    z=x+i
    if z not in a:
      ans=z
      break
  if ans==0:
    for j in range(2*x,101):
      if j not in a:
        ans=j
        break
print(ans)

Buggy submission (verdict: Runtime Error):
x,n=map(int,input().split())
a=list(map(int,input().split()))
if n==0:
  print(x)
else:
  ans=0
  for i in range(n-1):
    y=x-i
    if y not in a:
      ans=y
      break
    z=x+i
    if z not in a:
      ans=z
      break
  if ans==0:
    for j in range(2*x,101):
      if j not in a:
        ans=j
        break
print(ans)
Problem p02658 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
if 0 in a:
  print(0)
else:
  cnt=1
  for i in a:
    cnt*=i
    if cnt>10**18:
      cnt=-1
      break
  print(cnt)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
if 0 in a:
  print(0)
else:
  cnt=1
  for i in a:
    cnt*=i
    if cnt>10**18:
      cnt=-1
      break
print(cnt)