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

Fixed submission:
# A Anti-Adjacency
n,k = map(int,input().split())
if int((n +1) / 2) >= k:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
k,a,b = map(int,input().split())
bis = 1
if ((k <= 1) or (b <= a + 2)):
    print(1+k)
    exit()
else:
    bis = b
    k = k - (a + 1)
    if not k == 0:
        bis += int(k/2)+(b-a)+k%2
print(bis)

Buggy submission (verdict: Runtime Error):
k,a,b = map(int,input().split())
bis = 1
if k<= 1 or b <= a + 2:
    print(1+k)
    exit()
else:
    bis = b
    k = k - (a + 1)
    if not k == 0:
        bis += int(k/2)+(b-a)+k%2
print(bis)

Buggy submission (verdict: Runtime Error):
# C When I hit my pocket
k,a,b = map(int,input().split())

bis = 1

if k <= 1 or b <= a + 2:
    print(1 + k)
    exit()
else:
    bis = b
    k = k - ( a + 1)
    if not k == 0:
        bis += int(k / 2) * (b - a) + k % 2

print(bis)

Buggy submission (verdict: Runtime Error):
# C When I hit my pocket
k,a,b = map(int,input().split())

bis = 1

if k <= 1 or b <= a + 2 or k - (a + 1) < 0:
    print(1 + k)
    exit()
else:
    bis = b
    k = k - ( a + 1)
    if not k == 0:
        bis += int(k / 2) * (b - a) + k % 2

print(bis)

Buggy submission (verdict: Runtime Error):
# C When I hit my pocket
k,a,b = map(int,input().split())

bis = 1

#print(k - (a + 1))
if k <= 1 or b <= a + 2 or k - (a + 1) < 0:
    print(1 + k)
    #print('true')
    exit()
else:
    bis = b
    k = k - ( a + 1)
    if not k == 0:
        bis += int(k / 2) * (b - a) + k % 2

print(bis)
Problem p03937 (python)

Fixed submission:
h, w = map(int, input().split())
As = [list(input()) for i in range(h)]

x,y = 0,0

ans = "Possible"

while True:
    cnt = 0
    tmpX,tmpY = x,y
    # 上か左が"#" -> error
    if (x > 0 and As[y][x-1] == "#") or (y > 0 and As[y-1][x] == "#"):
        ans = "Impossible"
        break
    
    # 右も下も"#" -> error
    if x < w - 1 and As[y][x+1] == "#" and y < h - 1 and As[y+1][x] == "#":
        ans = "Impossible"
        break
    
    # 右に移動
    if x < w - 1 and As[y][x+1] == "#":
        As[y][x] = "."
        x += 1
    # 左に移動
    if y < h - 1 and As[y+1][x] == "#":
        As[y][x] = "."
        y += 1
        
    # 右下に到着
    if x == w - 1 and y == h - 1:
        As[y][x] = "."
        break

    # 移動していない
    if x == tmpX and y == tmpY:
        ans = "Impossible"
        break
        
for A in As:
    if "#" in A:
        ans = "Impossible"

print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
As = list(chain.from_iterable([list(input()) for i in range(h)]))
print("Possible" if As.count("#") == h + w - 1 else "Impossible")
Problem p03029 (python)

Fixed submission:
A,P=map(int,input().split())
num=3*A+P
print(num//2)

Buggy submission (verdict: Runtime Error):
N=int(input())
info=[input().split() for i in range(N)] #mojiretu
#print(info)
from operator import itemgetter
dic1={}
for i in range(len(info)):
    dic1[i+1]=info[i]
#print(dic1)
info1=sorted(info,key=lambda x:int(x[1]),reverse=True)
info2=sorted(info1,key=itemgetter(0))
#print(info2)
for i in info2:
    for key,value in dic1.items():
        if value==i:
            print(key)

Buggy submission (verdict: Runtime Error):
A,P=int(input().split())
num=3A+P
print(num//2)
Problem p03059 (python)

Fixed submission:
A,B,T=map(int,input().split())
print(int(((T+0.5)//A)*B))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
n=0
for i in range(len(A)):
    if A[i]<0:
        n+=1
if n%2==0:
    ans=0
    for i in range(len(A)):
        ans+=abs(A[i])
if n%2==1:
    B=A
    for i in range(len(A)):
        B[i]=abs(A[i])
    minn=min(B)
    ans=0
    for i in range(len(A)):
        ans+=B[i]
    ans-=2*minn
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
def gcd_list(list1):
    ans=list1[0]
    for i in range(len(list1)):
        ans=fractions.gcd(ans,list1[i])
    return ans
N=int(input())
A=list(map(int,input().split()))
n=0
for i in range(N):
    b=A[i]
    A.remove(A[i])
    m=gcd_list(A)
    n=max(n,m)
    A.insert(i,b)
print(n)
Problem p03071 (python)

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

Buggy submission (verdict: Runtime Error):
S=input()
N=len(S)
list1=list(map(int,S))
ans1=0
for i in range(len(list1)):
    if i%2==0:
        if list1[i]==1:
            ans1+=1
    elif i%2==1:
        if list1[i]==0:
            ans1+=1
ans2=min(ans1,(N-ans1))
print(ans2)

Buggy submission (verdict: Runtime Error):
N=int(input())
H=list(map(int,input().split()))
ans=0
for i in range(len(H)):
    if i==0:
        ans+=1
    elif max(H[0:i])<=H[i]:
        ans+=1
print(ans)
Problem p03076 (python)

Fixed submission:
a,b,c,d,e=[int(input()) for i in range(5)]
a1=a//10
a2=a%10
if a2==0:
    a1-=1
    a2=10
b1=b//10
b2=b%10
if b2==0:
    b1-=1
    b2=10
c1=c//10
c2=c%10
if c2==0:
    c1-=1
    c2=10
d1=d//10
d2=d%10
if d2==0:
    d1-=1
    d2=10
n=e//10
m=e%10
if m==0:
    n-=1
    m=10
min1=min(a2,b2,c2,d2,m)
if a2==10 or b2==10 or c2==10 or d2==10 or m==10:
    ans=(a1+b1+c1+d1+n+4)*10+min1
else:
    ans=(a1+b1+c1+d1+n+4)*10+min1
print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c,d,e=[int(input()) for i in range(5)]
a1=a//10
a2=a%10
if a2==0:
    a1-=1
    a2=10
b1=b//10
b2=b%10
if b2==0:
    b1-=1
    b2=10
c1=c//10
c2=c%10
if c2==0:
    c1-=1
    c2=10
d1=d//10
d2=d%10
if d2==0:
    d1-=1
    d2=10
n=e//10
m=e%10
if m==0:
    n-=1
    m=10
min1=min(a2,b2,c2,d2,m)
    ans=(a1+b1+c1+d1+n+4)*10+min1
print(ans)
Problem p03086 (python)

Fixed submission:
s=input()
ans=[]
I=[0]*len(s)
for i in range(len(s)):
    if (s[i]=="A" or s[i]=="T" or s[i]=="G" or s[i]=="C"):
        I[i]=1

    else:
        I[i]=0
for i in range(len(I)):
    if (I[i]==1 and I[i-1]==0) or (I[i]==1 and i==0):
        ans.append(1)
    elif (I[i]==1 and I[i-1]==1):
        ans[-1]+=1
if ans==[]:
    print(0)
else:
    print(max(ans))

Buggy submission (verdict: Runtime Error):
s=input()
ans=[]
I=[0]*len(s)
for i in range(len(s)):
    if (s[i]=="A" or s[i]=="T" or s[i]=="G" or s[i]=="C"):
        I[i]=1

    else:
        I[i]=0
for i in range(I):
    if (I[i]==1 and I[i-1]==0) or (I[i]==1 and i==0):
        ans.append(1)
    elif (I[i]==1 and I[i-1]==1):
        ans[-1]+=1
print(max(ans))
Problem p03486 (python)

Fixed submission:
s = input()
t = input()

s = sorted(s)
t = sorted(t)

# print(s,t)
if s[0] < t[-1]:
    print('Yes')
    exit()
elif s[0] > t[-1]:
    print('No')
    exit()
elif len(set(s)) ==1 and len(set(t)) ==1 and len(s) < len(t):
    print('Yes')
    exit()
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

s = sorted(s)
t = sorted(t)

# print(s,t)
if s == [] and t == []:
    print('No')
    exit()
elif s == []:
    print('Yes')
elif t == []:
    print('No')
    
if s[0] < t[-1]:
    print('Yes')
    exit()
elif s[0] > t[-1]:
    print('No')
    exit()
elif len(s) < len(x):
    print('Yes')
    exit()
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

s = sorted(s)
t = sorted(t)

# print(s,t)

if s[0] < t[-1]:
    print('Yes')
    exit()
elif s[0] > t[-1]:
    print('No')
    exit()
elif len(s) < len(x):
    print('Yes')
    exit()
else:
    print('No')
Problem p03854 (python)

Fixed submission:
S=input()
n=0
#print(S)
while S[:]!=S[:n]:
    if S[n:n+7]=="dreamer" and S[n:n+8]!="dreamera":
        n+=7 #dreamer
    elif S[n:n+5]=="dream":
        n+=5 #dream
    elif S[n:n+5]=="erase" and S[n:n+6]!="eraser":
        n+=5 #erase
    elif S[n:n+6]=="eraser":
        n+=6 #eraser
    #elif S[:]==S[:n-1]:
        #print("YES")
        #exit()
    else:
        print("NO")
        exit()
else:
    print("YES")

Buggy submission (verdict: Runtime Error):
S=input()
n=0
#print(S)
while S[:]!=S[:n]:
    if S[n:n+5]=="dream" or S[n:n+8]=="dreamera":
        n+=5 #dream
    elif S[n:n+7]=="dreamer" and S[n+7]!="a":
        n+=7 #dreamer
    elif S[n:n+5]=="erase" and S[n+6]!="eraser":
        n+=5 #erase
    elif S[n:n+6]=="eraser" and S[n+6]!="a":
        n+=6 #eraser
    #elif S[:]==S[:n-1]:
        #print("YES")
        #exit()
    else:
        print("NO")
        exit()
else:
    print("YES")

Buggy submission (verdict: Runtime Error):
S=input()
n=0
While S[:]!=S[:n-1]:
    if S[n:n+5]==dream and S[n:n+7]!=dreamer:
        n+=5
    elif S[n:n+7]==dreamer:
        n+=7
    elif S[n:n+5]==erase and S[n+6]!=eraser:
        n+=5
    elif S[n:n+6]==eraser:
        n+=6
    #elif S[:]==S[:n-1]:
        #print("YES")
        #exit()
    else:
        print("NO")
        exit()
else:
    print("YES")
Problem p02811 (python)

Fixed submission:
sp_list = list(map(int, input().split()))

if 500 * sp_list[0] >= sp_list[1]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
sp_list = list(map(int, input.split()))

if 500 * sp_list[0] >= sp_list[1]:
  print("Yes")
else:
  print("No")
Problem p02812 (python)

Fixed submission:
total = int(input())
text = input()

res = 0

if total >= 3:
    for x in range(0, total - 1):
        if text[x] == "A":
            if x + 3 <= total:
                if text[x + 1] == "B" and text[x + 2] == "C":
                    res += 1

print(res)

Buggy submission (verdict: Runtime Error):
total = int(input())
text = input()

res = 0

if total >= 3:
    for x in range(0, total - 1):
        if text[x] == "A":
            if x + 2 <= total:
                if text[x + 1] == "B" and text[x + 2] == "C":
                    res += 1

print(res)

Buggy submission (verdict: Runtime Error):
total = int(input())
text = input()

res = 0

if total != 0:
    for x in range(0, total - 1):
        if text[x] == "A":
            if x + 2 <= total:
                if text[x + 1] == "B" and text[x + 2] == "C":
                    res += 1

print(res)

Buggy submission (verdict: Runtime Error):
total = int(input())
text = input()

res = 0

for x in range(0, total - 1):
    if text[x] == "A":
        if x + 2 <= total:
            if text[x + 1] == "B" and text[x + 2] == "C":
                res += 1

print(res)

Buggy submission (verdict: Runtime Error):
total = int(input())
text = input()

res = 0

for x in range(0, total-1):
  if x == "A":
    if x+2 =< total:
      if text[x+1] == "B" and text[x+2] == "C":
        res += 1
      
print(res)
Problem p03280 (python)

Fixed submission:
def menseki(a, b):
    return a * b - (1 * b + 1 * a - 1)

if __name__ == '__main__':
    la, lb = map(int, input().split())
    print(menseki(la, lb))

Buggy submission (verdict: Runtime Error):
def menseki(a, b):
    return a * b - (1 * b + 1 * a - 1)

if __name__ == '__main__':
    la = int(input())
    lb = int(input())

    print(menseki(la, lb))
Problem p03282 (python)

Fixed submission:
def mrinfinit(a, b):
    bf = list(set(a))
    rr = a[:b]
    sf = list(set(rr))

    if len(bf) == 1 and bf[0] == '1':
        return a[0]
    elif len(sf) == 1 and sf[0] == '1':
        return a[0]
    elif len(a) > 1:
        if '1' in a:
            a = a.replace('1', '')
            return a[0]
        else:
            return a[0]
    else:
        return a[0]


if __name__ == '__main__':
    la = input()
    lb = int(input())
    print(mrinfinit(la, lb))

Buggy submission (verdict: Runtime Error):
def mrinfinit(a):
    if len(a) > 1:
        if '1' in a:
            a = a.replace('1', '')
            return a[0]
        else:
            return a[0]
    return a[0]


if __name__ == '__main__':
    la = input()
    lb = int(input())
    print(mrinfinit(la))

Buggy submission (verdict: Runtime Error):
def mrinfinit(a, b):
    if len(a) > 1:
        if '1' in a:
            a = a.replace('1', '')
            return a[0]
        else:
            return a[0]
    return a[0]


if __name__ == '__main__':
    la = input()
    lb = int(input())
    print(mrinfinit(la, lb))

Buggy submission (verdict: Runtime Error):
def mrinfinit(a, b):
    if len(a) >= 1:
        if '1' in a:
            a = a.replace('1', '')
            return a[0]
        else:
            return a[0]
    return a[0]


if __name__ == '__main__':
    la = input()
    lb = int(input())
    print(mrinfinit(la, lb))
Problem p04043 (python)

Fixed submission:
sort_list = list(map(int, input().split()))
if sort_list.count(7) == 1 and sort_list.count(5) == 2:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
sort_list = list(int(map, input().split()))
if sort_list.count(5) == 1 and sort_list.count(7) == 2:
  print("YES")
else:
  print("NO")
Problem p02795 (python)

Fixed submission:
import math

h = int(input())
w = int(input())
n = int(input())

print(math.ceil(n / max(h, w)))

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

print(max(h, x)%n)
Problem p02898 (python)

Fixed submission:
N, K = (int(i) for i in input().split())  
h_list = [int(i) for i in input().split()] 

person = 0
for n in range(N):
    if int(h_list[n]) >= K:
        person+=1
    
print(person)

Buggy submission (verdict: Runtime Error):
NK = input().split('')
N = int(NK[0])
K = int(NK[1])
h_list = input().split('')

# N=1
# K=500
# h_list=[499]

person = 0
for n in range(N):
    if int(h_list[n]) >= K:
        person+=1
    
print(person)

Buggy submission (verdict: Runtime Error):
NK = input().split('')
N = int(NK[0])
K = int(NK[1])
h_list = input().split('')
h_list = [int(x) for x in hlist]

# N=1
# K=500
# h_list=[499]

person = 0
for n in range(N):
    if h_list[n] >= K:
        person+=1
    
print(person)

Buggy submission (verdict: Runtime Error):
N, K = input().split('')
N = int(N)
K = int(K)
h_list = input().split('')
h_list = [int(x) for x in hlist]

# N=1
# K=500
# h_list=[499]

person = 0
for n in range(N):
    if h_list[n] >= K:
        person+=1
    
print(person)
Problem p02917 (python)

Fixed submission:
import numpy as np
N = int(input())
B = np.array(input().split(), dtype=int)[::-1]

ret = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1

ret += B[-1]
print(ret)

Buggy submission (verdict: Runtime Error):

import numpy as np
N = int(input())
B = np.array(input().split(), dtype=int)[::-1]

et = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1
print(ret)

Buggy submission (verdict: Runtime Error):
N = int(input())
B = np.array(input().split(), dtype=int)[::-1]

et = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1
print(ret)

Buggy submission (verdict: Runtime Error):
N = int(input())
B = np.array(input().split(), dtype=uint)[::-1]

et = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1
print(ret)
Problem p02801 (python)

Fixed submission:
print(chr(ord(input())+1))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
ans = [input().split() for _ in range(m)]
ac = []
wn = []
acn,wan = 0,0
for i in ans:
  for j in range(len(ac)):
    if i[0] != ac[j]:
      if i[1] == 'AC' :
        wan += wn.count(i[0])
        ac += [i[0]]
        acn += 1
      else :
        wn += [i[0]]
print(acn,wan)
Problem p02848 (python)

Fixed submission:
N = int(input())
 
T = [chr((ord(s)-65 + N)%26 + 65) for s in input()]
 
print("".join(T))

Buggy submission (verdict: Runtime Error):
N,S = int(input()),input()
ans = ""
abc = "ABCDEFGHIGKLMNOPQRSTUVWXYZ"
for i in S:
  ans += abc[(abc.index(i)+N)%26]
print(ans)
Problem p02936 (python)

Fixed submission:
from collections import deque
n,q=map(int, input().split())
l=[[] for i in range(n+1)]
ans=[0]*(n+1)

for i in range(n-1):
    a,b=[int(j) for j in input().split()]
    l[a].append(b)
    l[b].append(a)
for i in range(q):
    p,x=[int(j) for j in input().split()]
    ans[p]+=x

que=deque()
que.append(1)
ll=[0]*(n+1)
while que:
    y=que.popleft()
    ll[y]=1
    for i in l[y]:
        if ll[i]==1:
            continue
        ans[i]+=ans[y]
        que.append(i)
print(*ans[1:])

Buggy submission (verdict: Runtime Error):
N,Q = map(int, input().split())

score = [0 for _ in range(N)]
 
# 子頂点番号:親頂点番号のdictを生成する
d = {}
for i in range(1,N):
  a,b = map(int,input().split())
  d[b] = a
      
# スコア加算処理
for i in range(1,Q+1):
  p,x = map(int,input().split())
  score[p-1] = x  
for i in range(1,len(score)):
  addScore = score[d[i+1]-1]
  score[i] += addScore
print(*score)

Buggy submission (verdict: Runtime Error):
N,Q = map(int, input().split())

score = [0 for _ in range(N)]
 
# 子頂点番号:親頂点番号のdictを生成する
d = {}
for i in range(1,N):
  a,b = map(int,input().split())
  d[b] = a
      
# スコア加算処理
for i in range(1,Q+1):
  p,x = map(int,input().split())
  score[p-1] = x
for i in range(1,len(score)):
  addScore = score[d[i+1]-1]
  score[i] += addScore
print(*score)
Problem p02971 (python)

Fixed submission:
import numpy as np
n = int(input())
a = [int(input()) for _ in range(n)]

# 最大値のインデックス
i1 = np.argmax(a)
temp = a[i1]
a[i1] = 0
# ２番目の最大値のインデックス
i2 = np.argmax(a)
a[i1] = temp


for i in range(n):
  if i == i1:
    print(a[i2])
  else:
    print(a[i1])

Buggy submission (verdict: Runtime Error):
l,r = map(int,input().split())

r = min(r, l+4038)

min = 99999999
for i in range(l,r):
  for j in range(i+1,r+1):
    value = (i*j)%2019
    if min > value:
      min = value
print(min)
Problem p02999 (python)

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

if x < a:
  print(0)
elif x >= a:
  print(10)

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

if x < a:
  print(0)
elif x => a:
  print(10)
Problem p03101 (python)

Fixed submission:
H,W = map(int, input().split())
h,w = map(int, input().split())


print(H*W - h*W - w*H + h*w)

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
h,w = map(int,input().spilt())

ans = h*W + w*H - h*w
print(ans)
Problem p03105 (python)

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

if a*c <= b:
  print(c)
else:
  print(b//a)

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

cost = 0
ans = 0
while True:
  if(b <= cost):
    break
  cost += a
  ans += 1
print(min(ans-1,c)
Problem p02844 (python)

Fixed submission:
N = int(input())
S = input()


pins = set()
pins_check = set()

def bfs():    
    from collections import deque
    queue = deque([(S, '', 0)])
    while queue:
        tmp_s, tmp_pin, tmp_cnt = queue.popleft()
        if tmp_cnt == 3:
            pins.add(tmp_pin)
            continue
        
        for i in range(len(tmp_s)):
            if tmp_pin+tmp_s[i] in pins_check:
                continue
            pins_check.add(tmp_pin+tmp_s[i])
            queue.append((tmp_s[i+1:], tmp_pin+tmp_s[i], tmp_cnt+1))

ans = bfs()
#print(pins)
print(len(pins))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()

import sys
sys.setrecursionlimit(2000)

pins = set()
pins_1 = set()
pins_2 = set()

def dfs(s, pin, cnt):
    if cnt == 1:
        if pin in pins_1:
            return
        pins_1.add(pin)
    if cnt == 2:
        if pin in pins_2:
            return
        pins_2.add(pin)    
    if cnt == 3:
        pins.add(pin)
    for i in range(len(s)):
        dfs(s[i+1:], pin+s[i], cnt+1)
        
dfs(S, '', 0)
print(len(pins))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()

import sys
sys.setrecursionlimit(2000)

pins = set()
def dfs(s, pin, cnt):
    if cnt == 3:
        pins.add(pin)
    for i in range(len(s)):
        dfs(s[i+1:], pin+s[i], cnt+1)
        
dfs(S, '', 0)
print(len(pins))
Problem p02957 (python)

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

K = (A + B) / 2

if A == B:
    print(0)
elif K.is_integer():
    print(int(K))
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
K = int(input())
X, Y = map(int, input().split())

def move(a, b, _a, _b, _s):
    # x, y > 0 and x < y
    if a < 0: 
        return move(-a, b, -1, _b, _s)
    if b < 0:
        return move(a, -b, _a, -1, _s)
    if a > b:
        return move(b, a, _b, _a, True)
    # ここから移動処理
    if a + b == K:
        return (0, 0)
    
    if a + b >= 2*K:
        ret = (a, b-K)
    else:
        r = K - (a + b)//2
        ret = (-r, b-K+a+r)
    # 後処理
    ret = _a * ret[0], _b * ret[1]
    ret = (ret[1], ret[0]) if _s else ret
    return ret

x, y = X, Y

if K % 2 == 0 and (x+y) % 2:
    print(-1)
else:
    ANS = []
    while x != 0 and y != 0:
        ANS.append((x, y))
        x, y = move(x, y, 1, 1, False)
    print(len(ANS))
    for ans in ANS[::-1]:
        print(ans[0], ans[1])
Problem p02985 (python)

Fixed submission:
N, K = map(int, input().split())

AB = []
for _ in range(1, N):
    a, b = map(int, input().split())
    AB.append((a, b))
    
if N == 1:
    print(K)
else:
    # 無効グラフなので双方向にする
    graph = {}
    for a,b in AB:
        if not a in graph:
            graph[a] = {}
        if not b in graph:
            graph[b] = {}
        graph[a][b] = 1
        graph[b][a] = 1


    #print(graph)

    collors = [None] * (N+1)
    from collections import deque
    q = deque([(K, 1)]) 
    while q:
        col_num, v = q.popleft()
        if collors[v] == None:
            collors[v] = col_num

            if col_num == K:
                rest_col = K-1
            else:
                rest_col = K-2

            for v in graph[v]:
                if collors[v] == None:
                    q.appendleft((rest_col, v))
                    rest_col -= 1
    #print(collors)  

    MOD = 10**9+7

    ans = 1
    for i in collors[1:]:
        ans = ans * i % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())

AB = []
for _ in range(1, N):
    a, b = map(int, input().split())
    AB.append((a, b))
    
# 無効グラフなので双方向にする
graph = {}
for a,b in AB:
    if not a in graph:
        graph[a] = {}
    if not b in graph:
        graph[b] = {}
    graph[a][b] = 1
    graph[b][a] = 1


#print(graph)

collors = [None] * (N+1)
from collections import deque
q = deque([(K, 1)]) 
while q:
    col_num, v = q.popleft()
    if collors[v] == None:
        collors[v] = col_num
        
        if col_num == K:
            rest_col = K-1
        else:
            rest_col = K-2
        
        for v in graph[v]:
            if collors[v] == None:
                q.appendleft((rest_col, v))
                rest_col -= 1
#print(collors)  

MOD = 10**9+7

ans = 1
for i in collors[1:]:
    ans = ans * i % MOD
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, K = map(int, input().split())


AB = []
for _ in range(1, N):
    a, b = map(int, input().split())
    AB.append((a, b))
    
# 無効グラフなので双方向にする
graph = {}
for a,b in AB:
    if not a in graph:
        graph[a] = {}
    if not b in graph:
        graph[b] = {}
    graph[a][b] = 1
    graph[b][a] = 1


from heapq import heappush, heappop

def dijkstra(graph, start, N):
    # path_lenが色数
    A = [None] * (N+1)
    queue = [(K, start)]
    while queue:
        path_len, v = heappop(queue)
        if A[v] is None: # v is unvisited
            A[v] = path_len
            if path_len == K:
                path_len = K
            else:
                path_len = K-1
            for w, edge_len in graph[v].items():
                if A[w] is None:
                    path_len -= 1
                    heappush(queue, (path_len, w))

    # to give same result as original, assign zero distance to unreachable vertices             
    return [0 if x is None else x for x in A]

shortest = dijkstra(graph, 1, N)

ans = 1
for i in shortest[1:]:
    ans *= i
print(ans % 1000000007)