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

Fixed submission:
X, Y, Z, K= map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
B=list(map(int,input().split()))
B.sort(reverse=True)
C=list(map(int,input().split()))
C.sort(reverse=True)

ABC=[]
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1)<=K:
                ABC.append(A[i] + B[j] + C[k])
            else:
                break

ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])

Buggy submission (verdict: Runtime Error):
import heapq
hq=[]
X, Y, Z, K= map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
B=list(map(int,input().split()))
B.sort(reverse=True)
C=list(map(int,input().split()))
C.sort(reverse=True)
searched={(0,0,0)}
heapq.heappush(hq,(-(A[0]+B[0]+C[0]),0,0,0))
D=[[1,0,0],[0,1,0],[0,0,1]]

for _ in range(K):
    abc,x,y,z=heapq._heappop_max(hq)
    print(-abc)
    for dx,dy,dz in D:
        if x+dx<X and y+dy < Y and z+dz < Z and (x+dx,y+dy,z+dz) not in searched:
            heapq.heappush(hq,(-(A[x+dx]+B[y+dy]+C[z+dz]),x+dx,y+dy,z+dz))
            searched.add((x+dx,y+dy,z+dz))

Buggy submission (verdict: Runtime Error):
X, Y, Z, K= map(int,input().split())
A=list(map(int,input().split())).sort(reverse=True)
B=list(map(int,input().split())).sort(reverse=True)
C=list(map(int,input().split())).sort(reverse=True)

ABC=[]
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1)>K:
                break
            else:
                ABC.append(X[i]+Y[j]+Z[k])
                
ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])
Problem p03081 (python)

Fixed submission:
N,Q=map(int,input().split())
S=list(input())
S=[0]+S+[N+1]
TD=[list(input().split()) for _ in range(Q)]

def solve(place):
    if place == 0:
        return ('Left')
    elif place == N+1:
        return ('Right')
    for td in TD:
        char,to=td
        if S[place]!=char:continue

        if to=='L':place-=1
        elif to=='R':place+=1

        if place==0:
            return('Left')
        elif place==N+1:
            return('Right')
    return('Not Drop')

l,r=0,N+1
L,R=0,N+1

while abs(r-l)>1:
    m=(l+r)//2
    if solve(m)=='Left':
        L=m
        l,r=m,r
    else:
        l,r=l,m

l,r=0,N+1

while abs(r-l)>1:
    m=(l+r)//2
    if solve(m)=='Right':
        R=m
        l,r=l,m
    else:
        l,r=m,r

print(max(R-L-1,0))

Buggy submission (verdict: Runtime Error):
def solve(place):
    if place == 0:
        return ('Left')
    elif place == N+1:
        return ('Right')
    for td in TD:
        char,to=td
        if S[place]!=char:continue

        if to=='L':place-=1
        elif to=='R':place+=1

        if place==0:
            return('Left')
        elif place==N+1:
            return('Right')
    return('Not Drop')

l,r=0,N+1
L,R=0,N+1

while abs(r-l)>1:
    m=(l+r)//2
    if solve(m)=='Left':
        L=m
        l,r=m,r
    else:
        l,r=l,m

l,r=0,N+1

while abs(r-l)>1:
    m=(l+r)//2
    if solve(m)=='Right':
        R=m
        l,r=l,m
    else:
        l,r=m,r

print(max(R-L-1,0))
Problem p03219 (python)

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

Buggy submission (verdict: Runtime Error):
print(int(input())+int(input())//2)
Problem p03238 (python)

Fixed submission:
N=int(input())

if N==2:
  A=int(input())
  B=int(input())
  
print('Hello World' if N==1 else A+B)

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

if N==2:
  A=int(input())
  B=int(input())
  
print('Hello World' if N==1 else a+b)
Problem p03251 (python)

Fixed submission:
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
 
if max(x)<min(y) and X<Y:
  if len(set(range(max(x)+1,min(y)+1))&set(range(X+1,Y+1)))>=1:
  	print('No War')
  else:
    print('War')
else:
  print('War')

Buggy submission (verdict: Runtime Error):
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
 
if min(y)-max(x)>=2 and X<Y:
  if len(set(range(max(x)+1,min(y)))&set(range(X+1,Y+1)):
  	print('No War')
  else:
    print('War')
else:
  print('War')
Problem p03266 (python)

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

if K%2==1:
  print((N//K)**3)
else:
  print((N//K)**3+(N//K+(N-(N//K)*K)//(K//2))**3)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
print((N//K)**3+((K+1)%2)*(N//K+(N-(N//K)*K)//(K//2))**3)
Problem p03274 (python)

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

ans=[]

for i in range(N-K+1):
  xl=X[i]
  xr=X[i+K-1]
  ans.append(min(abs(xl)+abs(xr-xl),abs(xr)+abs(xl-xr)))

print(min(ans))

Buggy submission (verdict: Runtime Error):
import bisect

N,K=map(int,input().split())
X=list(map(int,input().split()))

if 0 in X:
  K=K-1

Right=[]
Left=[]
  
for x in X:
  if x>0:
    Right.append(x):
  else:
    Left=[abs(x)]+Left

print(Right)
print(Left)
Problem p03289 (python)

Fixed submission:
S=input()

def solve():
  temp=0
  if S[0]!='A':
    print('WA')
    return
  if not 'a'<=S[1]<='z':
    print('WA')
    return
  for i in range(2,len(S)-1):
    if S[i]=='C':
      temp+=1
      if temp>1:
        print('WA')
        return
  if temp==0:
    print('WA')
    return
    
  if not 'a'<=S[len(S)-1]<='z':
    print('WA')
    return
  
  print('AC')

solve()

Buggy submission (verdict: Runtime Error):
S=input()
ans='WA'
tmp=0
for i in range(2:len(S)-1):
  if S[i]=='C':
    tmp+=1
    
if tmp==1:
  ans='AC'
  
print(ans)
Problem p03293 (python)

Fixed submission:
S=list(input())
T=list(input())
S=S+S
ans='No'
for i in range(len(T)):
  if S[i:len(T)+i]==T:
    ans='Yes'
    break
print(ans)

Buggy submission (verdict: Runtime Error):
S=list(input())
T=list(input())
S=S+S
ans='No'
fot i in range(len(T)):
  if S[i:len(T)]==T:
    ans='Yes'
    break
print(ans)
Problem p03328 (python)

Fixed submission:
a,b=map(int,input().split())
print((b-a)*(b-a+1)//2-b)

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

Fixed submission:
a,b,c,d=map(int,input().split())
print('Yes' if abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d) else 'No')

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
print('Yes' if abs(a-b)<=d or abs(a-c)+abs(b-c)<=2d else 'No')

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
P=list(map(int,input().split()))
par=[i for i in range(N)]
ans=0

def root(x):
    if x!=par[x]:
        par[x]=root(par[x])
    return par[x]

def connect(x,y):
    if root(x)!=root(y):
        par[root(y)]=root(x)

for i in range(M):
    x,y=map(int,input().split())
    connect(x-1,y-1)

for i in range(N):
    if root(i)==root(P[i]-1):
        ans+=1

print(ans)
Problem p03415 (python)

Fixed submission:
ans=''
for i in range(3):
  s=input()
  ans+=s[i]
  
print(ans)

Buggy submission (verdict: Runtime Error):
ans=''
for i in range
Problem p03417 (python)

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

if N==1 and M==1:
  ans=1
elif N==1 or M==1:
  ans=max(N,M)-2
else:
  ans=(N-2)*(M-2)
  
print(ans)

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

if N==1 and M==1:
  ans=1
elif N=1 or M=1:
  ans=max(N,M)-2
else:
  ans=(N-2)*(M-2)
  
print(ans)
Problem p03424 (python)

Fixed submission:
N=int(input())
Colors=list(map(str,input().split()))
dict={}

for c in Colors:
  dict[c]=1

ans=0
for d in dict:
  ans+=1
  
print('Three' if ans==3 else 'Four')

Buggy submission (verdict: Runtime Error):
N=int(input())
dict={}

for i in range(N):
	dict[input()]=1

ans=0
for d in dict:
  ans+=1
  
print('Three' if ans==3 else 'Four')
Problem p03425 (python)

Fixed submission:
N=int(input())
chars=['M','A','R','C','H']
dict={}
for c in chars:
  dict[c]=0
  
ans=0
  
for i in range(N):
  s=input()
  if (s[0] in chars):
    dict[s[0]]+=1

L=list(dict.values())
    
for i in range(2**5):
  usedchars=[]
  for j in range(5):
    if i>>j&1==1:
      usedchars.append(L[j])
    
  if len(usedchars)==3:
    ans+=usedchars[0]*usedchars[1]*usedchars[2]

print(ans)

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

for i in range(N):
  s=input()
  if s[0] in [M,A,R,C,H]:
    S.add(s)

L=len(S)

print(L*(L-1)*(L-2)//6)
Problem p03436 (python)

Fixed submission:
import queue

q = queue.Queue()
H,W = map(int, input().split())
memo = [[-1]*W for _ in range(H)]
board = [input() for _ in range(H)]
wall=0
direction = [(1, 0), (-1, 0), (0, 1), (0, -1)]


def bfs():
    memo[0][0] = 0
    q.put((0, 0))
    while not q.empty():
        y,x= q.get()
        for (dy, dx) in direction:
            if 0<=y+dy<=H-1 and 0<=x+dx<=W-1 and board[y+dy][x+dx] == '.' and memo[y+dy][x+dx] == -1:
                q.put((y + dy, x + dx))
                memo[y + dy][x + dx] = memo[y][x] + 1
                if (y+dy, x+dx) == (H-1, W-1):
                    return memo[H-1][W-1]
    return -1


for s in board:
    wall+=s.count('#')

min_dist=bfs()
print(H*W-wall-(min_dist+1) if min_dist>0 else -1)

Buggy submission (verdict: Runtime Error):
import queue

q = queue.Queue()
H,W = map(int, input().split())
memo = [[-1]*W for _ in range(H)]
board = [input() for _ in range(H)]
wall=0
direction = [(1, 0), (-1, 0), (0, 1), (0, -1)]


def bfs():
    memo[0][0] = 0
    q.put((0, 0))
    while not q.empty():
        y,x= q.get()
        for (dy, dx) in direction:
            if 0<=y+dy<=H-1 and 0<=x+dx<=W-1 and board[y+dy][x+dx] == '.' and memo[y+dy][x+dx] == -1:
                q.put((y + dy, x + dx))
                memo[y + dy][x + dx] = memo[y][x] + 1
                if (y+dy, x+dx) == (H-1, W-1):
                    return memo[H-1][W-1]

for s in board:
    wall+=s.count('#')

print(H*W-wall-(bfs()+1))
Problem p03469 (python)

Fixed submission:
s=list(input())
s[3]=str(8)
print(''.join(s))

Buggy submission (verdict: Runtime Error):
s=list(input())
s[3]=8
print(''.join(s))
Problem p03473 (python)

Fixed submission:
n=int(input())
print(48-n)

Buggy submission (verdict: Runtime Error):
n=int(input)
print(48-n)
Problem p03474 (python)

Fixed submission:
A,B=map(int,input().split())
S=input()
flag=False
for i in range(len(S)):
  if i!=A and ((ord(S[i])-ord('0'))<0 or 9<(ord(S[i])-ord('0'))):
    break
  if i==A and S[i]!='-':
    break
  
  if i==len(S)-1:
    flag=True
    
if flag:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
S=input()
flag=False
for i in range(len(S)):
  if i!=A and (S[i]-'0'<0 or 9<S[i]-'0'):
    break
  if i==A and S[i]!='-':
    break
  
  if i==len(S)-1:
    flag=True
    
if flag:
  print('Yes')
else:
  print('No')
Problem p03477 (python)

Fixed submission:
l=list(map(int,input().split()))
L=l[0]+l[1]
R=l[2]+l[3]

if R==L:
  print('Balanced')
elif R>L:
  print('Right')
else:
  print('Left')

Buggy submission (verdict: Runtime Error):
l=map(int,input().split())
L=l[0]+l[1]
R=l[2]+l[3]

if R==L:
  print('Balanced')
elif R>L:
  print('Right')
else:
  print('Left')
Problem p03478 (python)

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

def my_sum(x):
  ret=0
  while x>0:
    ret+=x%10
    x=x//10
  return ret 

for i in range(N+1):
  if A<=my_sum(i)<=B:
    ans+=i

print(ans)

Buggy submission (verdict: Runtime Error):
N,A,B=map(int, input().split())
ans=0

def my_sum(x):
  ret=0
  for j in range(4):
    ret+=x%10
    x=x//10
  return ret 

for i in range(N+1):
  if A<=my_sum(i)<==B:
    ans+=1

print(ans)
Problem p03493 (python)

Fixed submission:
S=input()
ans=0
for s in S:
  if s=='1':
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))ans=0
flag=0

while flag==0:
  for i in range(N):
    if A[i]&1==0:
      A[i]=A[i]>>1
    else:
      print(ans)
      flag=1
      break
  ans+=1

print(ans)
Problem p03494 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
ans=0
flag=0

while flag==0:
  for i in range(N):
    if A[i]&1==0:
      A[i]=A[i]>>1
    else:
      print(ans)
      flag=1
      break
  ans+=1

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))ans=0
flag=0

while flag==0:
  for i in range(N):
    if A[i]&1==0:
      A[i]=A[i]>>1
    else:
      print(ans)
      flag=1
      break
  ans+=1

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
ans=0

while True:
  for i in range(N):
    if A[i]&1==0:
      A[i]=A[i]>>1
    else:
      print(ans)
      return
  ans+=1

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
ans=0

while True:
  for i in range(N):
    if A[i]%2==0:
      A[i]=A//2
    else:
      print(ans)
      return
  ans+=1

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
ans=0

while True:
  for i in range(N):
    if A[i]&1==0:
      A[i]=A>>1
    else:
      print(ans)
      return
  ans+=1
Problem p03503 (python)

Fixed submission:
N=int(input())
F=[list(map(int,input().split())) for _ in range(N)] #0-9
P=[list(map(int,input().split())) for _ in range(N)] #0-10

INF=10**9
ans=-INF

for i in range(1,2**10):
    tmpans=0
    for n in range(N):
        c=0
        for j in range(10):
            if (i>>j&1)&F[n][j]:
                c+=1
        tmpans+=P[n][c]

    ans=max(ans,tmpans)

print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
F=[list(map(int,input().split())) for _ in range(N)] #0-9
P=[list(map(int,input().split())) for _ in range(N)] #0-10

INF=10**9
ans=-INF

for i in range(1,2**10):
    tmp=[0]*10
    tmpans=0
    for j in range(0,10):
        bit=i>>j&1
        for n in range(N):
            tmp[n]+=F[n][j]*bit
    for n in range(N):
        tmpans+=P[n][tmp[n]]

    ans=max(ans,tmpans)

print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
F=[list(map(int,input().split())) for _ in range(N)] #0-9
P=[list(map(int,input().split())) for _ in range(N)] #0-10
INF=10**9
ans=-INF


for i in range(1,2**10):
    tmp=[0]*10
    tmpans=0
    for j in range(0,10):
        bit=i>>j&1
        for n in range(N):
            tmp[n]+=F[n][j]*bit
    for n in range(N):
        tmpans+=P[n][tmp[n]]

    ans=max(ans,tmpans)

print(ans)
Problem p03545 (python)

Fixed submission:
S=input()
for i in range(1<<3):
  tmp=S[0]
  for j in range(3):
    if i>>j&1==1:
      tmp+='+'
    else:
      tmp+='-'
    tmp+=S[j+1]
  if eval(tmp)==7:
    break
print(tmp+'=7')

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

for i in range(1<<3):
  tmp+=S[0]
  for j in range(3):
    if i>>j&1==1:
      tmp+='+'
    else:
      tmp+='-'
  if eval(tmp)==7:
    break
print(tmp+'=7')
Problem p03555 (python)

Fixed submission:
c1=input()
c2=input()
if c1[0]==c2[2] and c1[1]==c2[1] and c1[2]==c2[0]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
c1=input()
c2=input()
if c1[0]==c2[2] and c1[1]==c2[2] adn c1[2]==c2[0]:
  print('YES')
else:
  print('NO')
Problem p03657 (python)

Fixed submission:
A,B=map(int,input().split())
if A%3==0 or B%3==0 or (A+B)%3==0:
  print('Possible')
else:
  print('Impossible')

Buggy submission (verdict: Runtime Error):
A,B=map(int,input())
if A%3==0 or B%3==0 or (A+B)%3==0:
  print('Possible')
else:
  print('Impossible')
Problem p03658 (python)

Fixed submission:
N,K=map(int,input().split())
A=sorted(list(map(int,input().split())))
A.reverse()
ans=0
for i in range(K):
  ans+=A[i]
  
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=sorted(list(map(int,input().split()))).reverse()
ans=0
for i in range K:
  ans+=A[i]
  
print(ans)
Problem p02898 (python)

Fixed submission:
import numpy as np
result = 0
N = list(map(int, input().split())) 
A = list(map(int, input().split())) 

for i in range(N[0]):
    p1 = A[i]
    if p1 >= N[1]:
        result +=1
print(result)

Buggy submission (verdict: Runtime Error):
import numpy as np
result = 0
people = int(input('people:'))
restrict = int(input('Restricted height:'))

for i in range(people):
    p1 = int(input())
    if p1 >= restrict:
        result +=1
print(result)
Problem p02923 (python)

Fixed submission:
N = int(input())
listH =  list(map(int, input().split()))
val = 0
ans = 0

for i in range(N-1):
    if listH[i] >= listH[i+1]:
        val += 1
    else:
        val = 0
    ans = max(val,ans)
        
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
listH =  list(map(int, input().split()))
count_lr = 0
li_lr = []

for i in range(N-1):
    if listH[i] >= listH[i+1]:
        count_lr += 1
        li_lr.append(count_lr)
    else:
        count_lr = 0
        li_lr.append(count_lr)
        
print(max(li_lr))

Buggy submission (verdict: Runtime Error):
N = int(input())
listH =  list(map(int, input().split()))
count_lr = 0
count_rl = 0
li_lr = []


for i in range(N-1):
    if listH[i] >= listH[i+1]:
        count_lr += 1
        li_lr.append(count_lr)
    else:
        count_lr = 0
        li_lr.append(count_lr)
        
print(max(li_lr))
Problem p02886 (python)

Fixed submission:
n=int(input())
d_list=list(map(int,input().split()))
count=0
for i in range(n):
  for j in range(n):
    if i<j:
        count+=d_list[i]*d_list[j]
print(count)

Buggy submission (verdict: Runtime Error):
n=int(input())
d_list=map(int,inout().spllit())
count=0
for i in range(n):
  for j in range(n):
    count+=d_list[i]*d_list[j]
  count-=d_list[i]**2
if n=2:
  print(count)
else:
  print(count/2)

Buggy submission (verdict: Runtime Error):
n=int(input())
d_list=map(int,inout().spllit())
count=0
for i in range(n):
  for j in range(n):
    count+=d_list[i]*d_list[j]
  count-=d_list[i]**2
print(count)

Buggy submission (verdict: Runtime Error):
n=int(input())
d_list=map(int,inout().spllit())
count=0
for i in range(n):
  count-=d_list[i]**2
  for j in range(n):
    count+=d_list[i]*d_list[j]
print(count)

Buggy submission (verdict: Runtime Error):
n=int(input())
d_list=map(int,inout().spllit())
count=0
for i in range(n):
  count-=d_list[i]
  for j in range(n):
    count+=d_list[i]*d_list[j]
print(count)
Problem p02888 (python)

Fixed submission:
import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        x=l[i]+l[j]
        y=bisect.bisect_left(l,x)-j-1        
        ans+=y
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
lst=list(map(int,input().split()))
count=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(k+1,n):              
            a=lst[i]
            b=lst[j]
            c=lst[k]
            if a<b+c and b<c+a and c<a+b:
                    count+=1
print(count)
Problem p03164 (python)

Fixed submission:
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

V = 10**3
dp = [[float('INF')]*(N*(V+1)) for _ in range(N+1)]  # Nとv≦10**3の制約から取りうるvの範囲
dp[0][0] = 0

for i in range(N):
    for v in range((i+1)*(V+1)):
        if v - WV[i][1] >= 0:  # 品物を追加できるとき
            dp[i+1][v] = min(dp[i+1][v], dp[i][v-WV[i][1]] + WV[i][0])
        # できないとき
        dp[i+1][v] = min(dp[i+1][v], dp[i][v])

ans = 0
for i in range(N*(V+1)):
    if dp[N][i] <= W:
        ans = i
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import count

N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for w in range(W+1):
        if w - WV[i][0] >= 0:  # 品物を追加できるとき
            dp[i+1][w] = max(dp[i+1][w], dp[i][w-WV[i][0]] + WV[i][1])
        # できないとき
        dp[i+1][w] = max(dp[i+1][w], dp[i][w])
print(dp[N][W])
Problem p04013 (python)

Fixed submission:
N, A = map(int, input().split())
x = list(map(int, input().split()))

max_of_a = N * A

# dp[i][j][k] := i枚目までからj枚取って、合計をkにする通り数
dp = [[[0] * (max_of_a + 1) for _ in range(N+1)]for _ in range(N+1)]
dp[0][0][0] = 1


for i in range(N+1):
    for j in range(N+1):
        for k in range(max_of_a + 1):
            if i >= 1 and x[i-1] > k:
                dp[i][j][k] = dp[i-1][j][k]
            elif i >= 1 and j >= 1 and x[i-1] <= k:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k - x[i-1]]

ans = 0
for j in range(1, N+1):
    # N枚(カード総数)の中から1枚以上取った時の、j枚取って合計がj*Aの所 の合計
    ans += dp[N][j][j*A]
print(ans)

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

total = sum(x)

# dp[i][j][k] := i枚目までからj枚取って、合計をkにする通り数
dp = [[[0] * (total+1) for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1


for i in range(N+1):
    for j in range(N+1):
        for k in range(total+1):
            if i >= 1 and x[i-1] > k:
                dp[i][j][k] = dp[i-1][j][k]
            elif i >= 1 and j >= 1 and x[i-1] <= k:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k - x[i-1]]

ans = 0
for j in range(1, N+1):
     # N枚(カード総数)の中から1枚以上取った時の、j枚取って合計がj*Aの所 の合計
    ans += dp[N][j][j*A]
print(ans)
Problem p04031 (python)

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


def mean(numbers):
    return sum(a) / N


target = round(mean(a))
cost = 0
for num in a:
    cost += (num - target)**2

print(cost)

Buggy submission (verdict: Runtime Error):
from statistics import mean

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

target = round(mean(a))
cost = 0
for num in a:
    cost += (num - target)**2

print(cost)
Problem p04043 (python)

Fixed submission:
def equal_list(lst1, lst2):
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            break
    else:
        if not lst:
            return "YES"
    return "NO"


HAIKU = [5, 7, 5]
v = list(map(int, input().split()))
print(equal_list(v, HAIKU))

Buggy submission (verdict: Runtime Error):
ef main():
    HAIKU = [5, 7, 5]
    v = list(map(int, input().split()))
    return equal_list(v, HAIKU)


def equal_list(lst1, lst2):
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            break
    else:
        if not lst:
            return "YES"
    return "NO"


if __name__ == "__main__":
    print(main())
Problem p02918 (python)

Fixed submission:
import sys

if __name__ == '__main__':
    N, K = map(int, sys.stdin.readline().split())
    S = input()
    ans = 0
    for i in range(N-1):
        if S[i] == S[i+1]:
            ans += 1
    ans = min(N-1, ans+K*2)
    print(ans)

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    N, K = map(int, input())
    S = input()
    ans = 0
    for i in range(N-1):
        if S[i] == S[i+1]:
            ans += 1
    ans = min(N-1, ans+K*2)
    print(ans)
Problem p03044 (python)

Fixed submission:
N = int(input())

q = []
visited = [0] * N
ans = [0] * N
A = [[] for _ in range(N)]  # tree
W = [[] for _ in range(N)]  # weight

for i in range(N-1):
    u,v,w = map(int, input().split())
    u -= 1
    v -= 1
    A[u].append(v)
    A[v].append(u)
    W[u].append(w)
    W[v].append(w)

q.append(0)  # start
for _ in range(N):
    u = q.pop(0)
    visited[u] = 1
    k = 0
    for v in A[u]:
        if visited[v]==0:
            q.append(v)
            ans[v] = ans[u] + W[u][k]
        k += 1

for a in ans:
    print(a%2)

Buggy submission (verdict: Runtime Error):
N = int(input())
arr = [None]*N
visited = [False]*N
for i in range(N-1):
    u, v, w = map(int, input().split())
    if i==0:
        arr[u-1] = 0
        arr[v-1] = w
    else:
        if visited[u-1]:
            arr[v-1] = arr[u-1] + w
        else:
            arr[u-1] = arr[v-1] + w
    visited[u-1] = True
    visited[v-1] = True

for a in arr:
    if a%2==0:
        print(0)
    else:
        print(1)