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

Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n,m=map(int,input().split())
l=make_divisors(m)
for i in l:
    if n<=i:
        ans=m//i
        break
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
if m%i==0:
    ans=m//i
else:
    ans=m//i-1
print(ans)
Problem p03361 (python)

Fixed submission:
# coding: utf-8
import sys

sys.setrecursionlimit(200000)

H,W=map(int,input().split())

canvas=[]

flg=True

def bfs(y,x):
    cnt[0]+=1
    canvas[y][x]="."
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    for i in range(4):
        ny=y+dy[i]
        nx=x+dx[i]
        
        if 0<=nx<=W-1 and 0<=ny<=H-1:
            if canvas[ny][nx]=="#":
                bfs(ny,nx)

for i in range(H):
    row=list(input())
    canvas.append(row)


for i in range(H):
    for j in range(W):
        if canvas[i][j]=="#":
            cnt=[0]
            bfs(i,j)
            if cnt[0]==1:
                flg=False

if flg:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import sys

ys.setrecursionlimit(200000)

H,W=map(int,input().split())

canvas=[]

flg=True

def bfs(y,x):
    cnt[0]+=1
    canvas[y][x]="."
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    for i in range(4):
        ny=y+dy[i]
        nx=x+dx[i]
        
        if 0<=nx<=W-1 and 0<=ny<=H-1:
            if canvas[ny][nx]=="#":
                bfs(ny,nx)

for i in range(H):
    row=list(input())
    canvas.append(row)


for i in range(H):
    for j in range(W):
        if canvas[i][j]=="#":
            cnt=[0]
            bfs(i,j)
            if cnt[0]==1:
                flg=False

if flg:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
# coding: utf-8

H,W=map(int,input().split())

canvas=[]

flg=True

def bfs(y,x):
    cnt[0]+=1
    canvas[y][x]="."
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    for i in range(4):
        ny=y+dy[i]
        nx=x+dx[i]
        
        if 0<=nx<=W-1 and 0<=ny<=H-1:
            if canvas[ny][nx]=="#":
                bfs(ny,nx)

for i in range(H):
    row=list(input())
    canvas.append(row)


for i in range(H):
    for j in range(W):
        if canvas[i][j]=="#":
            cnt=[0]
            bfs(i,j)
            if cnt[0]==1:
                flg=False

if flg:
    print("Yes")
else:
    print("No")
Problem p03427 (python)

Fixed submission:
# coding: utf-8
# Your code here!
N=int(input())

if len(str(N))==1:
    ans=N
else:
    
    if 1==len(set(list(str(N))[1:])) and int(str(N)[1])==9:
        ans=9*(len(str(N))-1) + int(str(N)[0])
    else:
        ans=9*(len(str(N))-1) + int(str(N)[0])-1

print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N=int(input())

if len(str(N))==1:
    ans=N
else:
    
    if 1==len(set(list(str(N))[1:])) and int(str(N)[2])==9:
        ans=9*(len(str(N))-1) + int(str(N)[0])
    else:
        ans=9*(len(str(N))-1) + int(str(N)[0])-1

print(ans)
Problem p03436 (python)

Fixed submission:
# coding: utf-8
# Your code here!
h,w=map(int,input().split())

maze=[]
m=[]
wn=0
INF = 10**5

for i in range(h):
    row=list(input())
    maze.append(row)
    m.append([INF for i in range(w)])
    for j in range(w):
        if row[j]==".":
            wn+=1


m[0][0]=0
dx=[1,0,-1,0]
dy=[0,1,0,-1]

queue=[]
queue.append([0,0])
maze[0][0]="#"

while len(queue)>0:

    y,x=queue.pop(0)
    for i in range(4):
        ny=y+dy[i]
        nx=x+dx[i]
        if 0<=ny<h and 0<=nx<w:
            if maze[ny][nx]==".":
                queue.append([ny,nx])
                maze[ny][nx]="#"
                m[ny][nx]=min(m[ny][nx],m[y][x]+1)


if m[-1][-1]==INF:
    print(-1)
else:
    print(wn-2-(m[-1][-1]-1))

Buggy submission (verdict: Runtime Error):
import copy
n,hp=map(int,input().split(" "))
la=[0 for i in range(n)]
lb=[0 for i in range(n)]
for i in range(n):
    la[i],lb[i]=map(int,input().split(" "))
cnt=0
ma=max(la)
lma=[i for i ,x in enumerate(la)  if x==ma]
mib=10**9
for i in lma:
    if lb[i]<mib:
        mib=lb[i]
        k=i
tmp=copy.deepcopy(lb)
while max(tmp)>ma:
    hp-=max(tmp)
    tmp.remove(max(tmp))
    cnt+=1
    if hp<0:
        print(cnt)
        exit(0)
if lb[k]>ma:
    hp+=lb[k]
if lb[k]>ma:
    hp-=lb[k]
    cnt+=1
if hp%ma==0:
    print(cnt+int(hp/ma))
else:
    print(cnt+int(hp/ma)+1)
Problem p03455 (python)

Fixed submission:
a,b=map(int,input().split(" "))
if a*b%2==0:
    print("Even")
else:
    print("Odd")

Buggy submission (verdict: Runtime Error):
a,b=int(input.split(" "))
if a*b%2=0:
    print("Even")
else:
    print("Odd")
Problem p03494 (python)

Fixed submission:
n=int(input())
l=list(map(int,input().split(" ")))
ans=0
j=0
while j==0:
    i=0
    while i <len(l):
        if l[i]%2!=0:
            j=1
        else:
            l[i]=int(l[i]/2)
        i+=1
    ans+=1
print(ans-1)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split(" ")))
ans=0

while i <len(l):
    if l[i]%2!=0:
        break
    else:
        l[i]=int(l[i]/2)
        i+=1
    ans+=1
print(ans)
Problem p03565 (python)

Fixed submission:
# coding: utf-8
S=list(input())
T=list(input())
flg=False
S.reverse()
T.reverse()

for i in range(max(0,len(S)-len(T)+1)):
    flg=True
    for j in range(len(T)):
        if not(S[i+j]=="?"):
            if S[i+j]!=T[j]:
                flg=False
    if flg:
        for k in range(len(T)):
            S[i+k]=T[k]
        break    
        

S.reverse()

for i in range(len(S)):
    if S[i]=="?":
        S[i]="a"
if flg:
    print("".join(S))
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
# coding: utf-8
S=list(input())
T=list(input())

S.reverse()
T.reverse()

for i in range(len(S)-len(T)):
    flg=True
    for j in range(len(T)):
        if not(S[i+j]=="?"):
            if S[i+j]!=T[j]:
                flg=False
    if flg:
        for k in range(len(T)):
            S[i+k]=T[k]
        break    
        

S.reverse()

for i in range(len(S)):
    if S[i]=="?":
        S[i]="a"
if flg:
    print("".join(S))
else:
    print("UNRESTORABLE")
Problem p03633 (python)

Fixed submission:
# coding: utf-8
import fractions as math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

N=int(input())
ans=lcm(1,int(input()))

for i in range(N-1):
    ans=lcm(ans,int(input()))

print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

N=int(input())
ans=lcm(1,int(input()))

for i in range(N-1):
    ans=lcm(ans,int(input()))

print(ans)
Problem p03854 (python)

Fixed submission:
st=input()
c="0"
j="0"
u="0"
for i in st:
    if i=="d" and u=="0" and c=="0":
        u="d"
        j="1"
    elif i=="r" and u=="d":
        u="r1"
    elif i=="e" and u=="r1":
        u="e1"
    elif i=="a" and u=="e1":
        u="a1"
    elif i=="m" and u=="a1":
        u="0"
        
    elif i=="e" and u=="0" and c=="0":
        u="e2"
        if j !="1":
            c="1"
    elif i=="r" and u=="e2":
        u="0"
        j="2"
    elif i=="a" and u=="0" and j=="2":
        u="a2"
    elif i=="s" and u=="a2":
        u="s"
    elif i=="e" and u=="s":
        u="0"
        c="0"
        j="3"
    elif i=="r" and u=="0" and j=="3":
        j="0"
    else:
        print("NO")
        exit(0)
if u=="0"and c=="0":
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
st=input()
j="0"
u="0"
for i in st:
    if i=="d" and u=="0":
        u="d"
        j="1"
    elif i=="r" and u=="d":
        u="r1"
    elif i=="e" and u=="r1":
        u="e1"
    elif i=="a" and u=="e1":
        u="a1"
    elif i=="m" and u=="a1":
        u="0"
    elif i=="e" and u=="0":
        u="e2"
        j="2"
    elif i=="r" and u=="e2":
        u="0"
    """"""    
    elif i=="e" and u=="0":
        u="e3"
        j="0"
    elif i=="r" and u=="e3":
        u="r2"
    """"""
    elif i=="a" and u=="0" and j=="2":
        u="a2"
    elif i=="s" and u=="a2":
        u="s"
    elif i=="e" and u=="s":
        u="0"
        j="3"
    elif i=="r" and j=="3":
        j="0"
    else:
        print("NO")
        exit(0)
if u=="0":
    print("YES")
else:
    print("NO")
Problem p02664 (python)

Fixed submission:
print(input().replace('?','D'))

Buggy submission (verdict: Runtime Error):
t = input()
o = ""
for i in range(len(t)):
    if t[i] == "?":
        if i != 0 and t[i - 1] == "P":
            o += "D"
        elif i != len(t) and t[i + 1] == "D":
            o += "P"
        else:
            o += "D"
    else:
        o += t[i]

print(o)

Buggy submission (verdict: Runtime Error):
t = input()
o = ""
for i in range(len(t)):
    if t[i] == "?":
        if t[i - 1] == "P":
            o += "D"
        elif i != len(t):
            if t[i + 1] == "D":
                o += "P"
        else:
            o += "D"
    else:
        o += t[i]

print(o)

Buggy submission (verdict: Runtime Error):
t = input()
o = ""
for i in range(len(t)):
    if t[i] == "?":
        if t[i - 1] == "P":
            o += "D"
        elif t[i + 1] == "D":
            o += "P"
        else:
            o += "D"
    else:
        o += t[i]

print(o)
Problem p02801 (python)

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

Buggy submission (verdict: Runtime Error):
print(chr(ord(input()+1)
Problem p02583 (python)

Fixed submission:
import itertools
import numpy as np

N = int(input(''))
L = (list(map(int, input('').split(' '))))
L = np.array(sorted(L))
set_L = set(L)

if len(set_L) <= 2:
    print(0)
else:
    K = {i:len(L[L==i]) for i in set_L}
    
    i = 0
    for team in itertools.combinations(K.keys(), 3):
        if (team[0] < team[1] + team[2]) & (team[1] < team[0] + team[2]) & (team[2] < team[0] + team[1]):
            i += K[team[0]]*K[team[1]]*K[team[2]]
    print(i)

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

N = int(input(''))
L = (list(map(int, input('').split(' '))))
L = np.array(sorted(L))
set_L = set(L)
if len(set_L) <= 2:
    print(0)
else:
    K = {i:len(L[L==i]) for i in set_L}
    
i = 0
for team in itertools.combinations(K.keys(), 3):
    if (team[0] < team[1] + team[2]) & (team[1] < team[0] + team[2]) & (team[2] < team[0] + team[1]):
        i += K[team[0]]*K[team[1]]*K[team[2]]
print(i)
Problem p02584 (python)

Fixed submission:
import numpy as np
X, K, D = (list(map(int, input('').split(' '))))
X = np.abs(X)

if np.abs(X)/D <= K:
    new_K = K - int(X/D)
    new_X = X - D*int(X/D)
    if new_K%2==0:
        print(new_X)
    else:
        print(np.abs(new_X-D))
else:
    print(np.abs(X-D*K))

Buggy submission (verdict: Runtime Error):
import numpy as np
X, K, D = (list(map(int, input('').split(' '))))

sign = np.sign(X)*(-1)
if K%2 == 0:
    new_X = X
    for i in range(2*sign, (K+1)*sign, 2*sign):
        old_X = new_X
        new_X = i*D + X
        if np.abs(new_X) > np.abs(old_X):
            ans = np.abs(old_X)
            break
else:
    new_X = X
    for i in range(sign, (K+1)*sign, 2*sign):
        old_X = new_X
        new_X = i*D + X#2*sign*D
        if np.abs(new_X) > np.abs(old_X):
            ans = np.abs(old_X)
            break
            
try:
    print(ans)
except NameError:
    print(np.abs(new_X))

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

X, K, D = (list(map(int, input('').split(' '))))
dX = np.arange(-K,K+1,2)
new_X = X + D * dX
print(np.min(np.abs(new_X)))

Buggy submission (verdict: Runtime Error):
X, K, D = (list(map(int, input('').split(' '))))
dX = np.arange(-K,K+1,2)
new_X = X + D * dX
print(np.min(np.abs(new_X)))
Problem p02582 (python)

Fixed submission:
S=input()
ans=0
tmp=0
for s in S:
  if s=='R':
    tmp+=1
  else:
    ans=max(ans,tmp)
    tmp=0
print(max(ans,tmp))

Buggy submission (verdict: Runtime Error):
S=input()
ans=0
tmp=0
for s in S:
  if s='S':
    tmp+=1
  else:
    ans=max(ans,tmp)
    tmp=0
print(max(ans,tmp))
Problem p02585 (python)

Fixed submission:
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
A=[]
S=[]
p=2**N-1
for i in range(N):
  if p>>i&1:
    s=i+1
    tmp=[C[i]]
    while s!=P[i]:
      i=P[i]-1
      tmp.append(C[i])
      p^=1<<i
    A.append(tmp)
    S.append(sum(tmp))
ans=-1*(10**9)-1
for i in range(len(A)):
  a=A[i]
  n=len(a)
  s=S[i]
  for j in range(n):
    t=0
    k=n
    if K>n:
      if s > 0:
        k=K%n
        if k==0:
          k=n
          t=s*(K//n-1)
        else:
          k=K%n
          t=s*(K//n)
    else:
      k=K
    for jj in range(j,k+j):
      if jj>=n:
        jj-=n
      t+=a[jj]
      ans=max(ans,t)
    ans=max(ans,t)
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
A=[]
S=[]
p=2**N-1
for i in range(N):
  if p>>i&1:
    s=i+1
    tmp=[C[i]]
    while s!=P[i]:
      i=P[i]-1
      tmp.append(C[i])
      p^=1<<i
    A.append(tmp)
    S.append(sum(tmp))
ans=-1*(10**9)-1
for i in range(len(A)):
  a=A[i]
  n=len(a)
  s=S[i]
  for j in range(n):
    t=0
    k=n
    if K>n:
      if s > 0:
        k=K%n
        if :
          k=n
          t=s*(K//n-1)
        else:
          k=K%n
          t=s*(K//n)
    else:
      k=K
    for jj in range(j,k+j):
      if jj>=n:
        jj-=n
      t+=a[jj]
      ans=max(ans,t)
    ans=max(ans,t)
print(ans)
Problem p02628 (python)

Fixed submission:
N,K=map(int,input().split())
P=sorted(list(map(int,input().split())))
print(sum(P[:K]))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input())
P=sorted(list(map(int,input().split())))
print(sum(P[:K]))
Problem p02641 (python)

Fixed submission:
X,N=map(int,input().split())
if N>0:
  P=list(map(int,input().split()))
  for i in range(N+1):
    if X-i not in P:
      print(X-i)
      break
    elif X+i not in P:
      print(X+i)
      break
else:
  print(X)

Buggy submission (verdict: Runtime Error):
X,N=map(int,input().split())
p=[]
if N>0:
  p=list(map(int,input().split()))
  L=[abs(X-i) for i in P]
  l=min(L)
  if X-l in P:
    print(X-l)
  else:
    print(X+l)
else:
  print(X)
Problem p02720 (python)

Fixed submission:
K=int(input())

if K<=9:
  print(K)
else:
  p=1
  dp,old=[[1]*10],[0,1]
  n=9
  while K>n:
    old=dp[p-1]
    tmp=[0]*10
    for i in range(1,9):
      tmp[i]=old[i-1]+old[i]+old[i+1]
    tmp[9]=old[8]+old[9]
    tmp[0]=old[0]+old[1]
    dp.append(tmp)
    p+=1
    n+=sum(tmp[1:])

  ans=0
  n-=sum(tmp[1:])
  K-=n
  c=2
  for i in range(p-1,-1,-1):
    if c!=0:
      c-=1
    while K>dp[i][c]:
      K-=dp[i][c]
      c+=1
    ans+=c*10**i
  print(ans)

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

p=1
dp,old=[[1]*10],[0,1]
n=9
while K>n:
  old=dp[p-1]
  tmp=[0]*10
  for i in range(1,9):
    tmp[i]=old[i-1]+old[i]+old[i+1]
  tmp[9]=old[8]+old[9]
  tmp[0]=old[0]+old[1]
  dp.append(tmp)
  p+=1
  n+=sum(tmp[1:])

ans=0
n-=sum(tmp[1:])
K-=n
c=2
for i in range(p-1,-1,-1):
  if c!=0:
    c-=1
  while K>dp[i][c]:
    K-=dp[i][c]
    c+=1
  ans+=c*10**i
print(ans)
Problem p02727 (python)

Fixed submission:
X,Y,A,B,C=map(int,input().split())
P=sorted(map(int,input().split()), reverse=True)[:X]
Q=sorted(map(int,input().split()), reverse=True)[:Y]
R=sorted(map(int,input().split()), reverse=True)[:X+Y]
i,j=X-1,Y-1
for r in R:
    if i==-1 and j==-1:
        break
    elif j==-1:
        if r>P[i]:
            P[i]=r
            i-=1
        else:
            break
    elif i==-1:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    elif P[i]>Q[j]:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    else:
        if r>P[i]:
            P[i]=r
            i-=1
        else:
            break
print(sum(P)+sum(Q))

Buggy submission (verdict: Runtime Error):
X,Y,A,B,C=map(int,input().split())
P=sorted(map(int,input().split()), reverse=True)[:X]
Q=sorted(map(int,input().split()), reverse=True)[:Y]
R=sorted(map(int,input().split()), reverse=True)[:X+Y]
i,j=X-1,Y-1
for r in R:
    if i==-1 and j==-1:
        break
    elif j==-1:
        if r>P[i]:
            p[i]=r
            i-=1
        else:
            break
    elif i==-1:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    elif P[i]>Q[j]:
        if r>Q[j]:
            Q[j]=r
            j-=1
        else:
            break
    else:
        if r>P[i]:
            p[i]=r
            i-=1
        else:
            break
print(sum(P)+sum(Q))

Buggy submission (verdict: Runtime Error):
X,Y,A,B,C=map(int,input().split())
P=sorted(map(int,input().split()), reverse=True)
Q=sorted(map(int,input().split()), reverse=True)
R=sorted(map(int,input().split()), reverse=True)
Sp,Sq,Sr=[0],[0],[0]
for i in range(A):
    Sp.append(Sp[-1]+P[i])
for i in range(B):
    Sq.append(Sq[-1]+Q[i])
l,r=0,2*10**14
while not l+1==r:
    x=(l+r)//2
    tmp=Sp[X]+Sq[Y]
    i,j,k=X,Y,0
    while tmp<x and k<C:
        if i==0 and j==0:
            break
        elif i==0:
            if R[k]>Q[j-1]:
                tmp+=R[k]-Q[j-1]
                j-=1
                k+=1
            else:
                break
        elif j==0:
            if R[k]>P[i-1]:
                tmp+=R[k]-P[i-1]
                i-=1
                k+=1
            else:
                break
        elif P[i-1]>Q[j-1]:
            if R[k]>Q[j-1]:
                tmp+=R[k]-Q[j-1]
                j-=1
                k+=1
            else:
                break
        else:
            if R[k]>P[j-1]:
                tmp+=R[k]-P[i-1]
                i-=1
                k+=1
            else:
                break
    if tmp>=x:
        l=x
    else:
        r=x

print(l)
Problem p02811 (python)

Fixed submission:
N,X=map(int, input().split())
print("Yes" if 500*N >= X else "No")

Buggy submission (verdict: Runtime Error):
N,X=map(int, input(),split())
print("Yes" if 500*N >= X else "No")
Problem p02818 (python)

Fixed submission:
S=list(map(int, input().split()))
if S[2] >= S[0] + S[1]:
  print(0,0)
elif S[2] >= S[0]:
  print(0,S[1]+S[0]-S[2])
else:
  print(S[0]-S[2],S[1])

Buggy submission (verdict: Runtime Error):
S=list(map(int, input().split()))
if S[2] >= S[0]+S[1]:
  print(0,0)
else S[2] >= S[0]:
  print(0,S[1]+S[0]-S[2])
else:
  print(S[0]-S[2],S[1])
Problem p02830 (python)

Fixed submission:
N=int(input())
S,T=input().split()
U=[]
for i in range(N):
  U.append(S[i])
  U.append(T[i])
print("".join(U))

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
T=input()
U=[]
for i in range(N):
  U.append(S[i])
  U.append(T[i])
print(U)
Problem p02839 (python)

Fixed submission:
import numpy as np
import itertools

H,W=map(int,input().split())
A=[list(map(int, input().split())) for _ in range(H*2)]
M=[[abs(A[i][j]-A[H+i][j]) for j in range(W)] for i in range(H)]
m=max(max(j for j in i) for i in M)
r=m*(H+W)+1
dp=np.zeros((H,W,r),dtype='bool')
dp[0][0][M[0][0]]=True
it = itertools.product(range(H),range(W))
next(it)
for h,w in it:
    m=M[h][w]
    dp[h][w][m:] |= dp[h][w-1][:r-m] | dp[h-1][w][:r-m]
    dp[h][w][:r-m] |= dp[h][w-1][m:] | dp[h-1][w][m:]
    dp[h][w][:m] |= dp[h][w-1][m:0:-1] | dp[h-1][w][m:0:-1]

for i in range(r):
    if dp[-1][-1][i]:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
H,W = map(int, input().split())
A=[]
B=[]
for _ in range(H):
    A.append(list(map(int, input().split())))
for _ in range(H):
    B.append(list(map(int, input().split())))
M=[[] for _ in range(W)]
m=0
for i in range(H):
    for j in range(W):
        M[i][j]=abs(A[i][j]-B[i][j])
        m=max(M[i][j],m)
r=m*(H+W)
dp=[[[False for _ in range(r)] for _ in range(W)] for _ in range(H)]
dp[0][0][abs(A[0][0]-B[0][0])]=True
for i in range(H):
    for j in range(W):
        if i==0 and j==0: continue
        for k in range(r):
            if i==0:
                if dp[i][j-1][abs(k-M[i][j])] or dp[i][j-1][k+M[i][j]]:
                    dp[i][j][k]=True
            elif j==0:
                if dp[i-1][j][abs(k-M[i][j])] or dp[i-1][j][k+M[i][j]]:
                    dp[i][j][k]=True
            elif dp[i][j-1][abs(k-M[i][j])] or dp[i][j-1][k+M[i][j]] or dp[i-1][j][abs(k-M[i][j])] or dp[i-1][j][k+M[i][j]]:
                dp[i][j][k]=True
for i in range(r):
    if dp[H-1][W-1][i]:
        print(i)
        break
Problem p02885 (python)

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

Buggy submission (verdict: Runtime Error):
N=int(input())
L=list(map(int, input().split()))
L.sort()
L.reverse()
a=L.pop(0)
count=0
while(L!=[]):
    for i in range(len(L)):
        for j in range(i+1,len(L)):
            if a < L[i]+L[j]:
                count+=1
    a=L.pop(0)
print(count)
Problem p02910 (python)

Fixed submission:
S=input()

p=True
q=True
for i in S:
  if p:
    if not i=='L':
      p=False
    else:
      q=False
      break
  else:
    if not i=='R':
      p=True
    else:
      q=False
      break

print ("Yes" if q else "No")

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

p=True
q=True
for i in S:
  if p:
    if not i=='L':
      p=False
	else:
      q=False
      break
  else:
    if not i=='R':
      p=True
    else:
      q=False
      break
      
print ("Yes" if q else "No")
Problem p02911 (python)

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

A = [K for _ in range(N)]

for _ in range(Q):
    A[int(input())-1] += 1
for i in range(N):
    print("Yes" if A[i] > Q else "No")

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

A = [K for _ in range(N)]

for _ in range(N):
    A[int(input())-1] += 1
for i in range(N):
    print("Yes" if A[i] > Q else "No")

Buggy submission (verdict: Runtime Error):
N,K,Q = map(int, input().split())
A = [K for _ in N]
for _ in N:
  a = int(input())
  A[a-1] += 1
for i in N:
  if A[i] > Q:
    print("Yes")
  else:
    print("No")
Problem p02922 (python)

Fixed submission:
import math
A,B = map(int, input().split())
print(math.ceil((B-1)/(A-1)))

Buggy submission (verdict: Runtime Error):
A,B = map(int, input().split())
if B==1:
  print(0)
else if B<A:
  print(1)
else:
  print(B//(A-1))
Problem p02936 (python)

Fixed submission:
from collections import deque

N,Q=map(int,input().split())
to=[[] for _ in range(N)]
count=[0]*N
for _ in range(N-1):
    a,b=map(int, input().split())
    to[a-1].append(b-1)
    to[b-1].append(a-1)
for _ in range(Q):
    p,x=map(int, input().split())
    count[p-1]+=x
q = deque()
q.append(0)
p=[True]*N
while q:
    i = q.pop()
    if p[i]:
        p[i]=False
        for j in to[i]:
            if p[j]:
                count[j]+=count[i]
                q.append(j)
print(*count)

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
tree=[[] for _ in range(N)]
counter=[0]*N
for _ in range(N-1):
    a,b=map(int, input().split())
    tree[a-1].append(b-1)
for _ in range(Q):
    p,x=map(int, input().split())
    counter[p-1]+=x
def f(t,x):
    for i in t:
        counter[i]+=x
        f(tree[i],counter[i])
f(tree[0],counter[0])
counter=list(map(str, counter))
print(' '.join(counter))

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
s=[0]*N
tree=[[] for _ in range(N)]
counter=[0]*N
def pl(t,x):
    if t:
        for i in t:
            s[i]+=x
            pl(tree[i],x)
for _ in range(N-1):
    a,b=map(int, input().split())
    tree[a-1].append(b-1)
for _ in range(Q):
    p,x=map(int, input().split())
    s[p-1]+=x
    pl(tree[p-1],x)
s=list(map(str, s))
print(' '.join(s))

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
s=[0]*N
tree=[[] for _ in range(N)]
counter=[0]*N
def pl(t,x):
    if t:
        for i in t:
            s[i]+=x
            pl(tree[i],x)
for _ in range(N-1):
    a,b=map(int, input().split())
    tree[a-1].append(b-1)
for _ in range(Q):
    p,x=map(int, input().split())
    s[p-1]+=x
    pl(tree[p-1],x)
s=[str(i) for i in s]
print(' '.join(s))