Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import bisect 

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

A=P[:K]
A.sort()

B=[]
for i in range(N-K):
  B.append(P[:i]+A+P[i+K:])  
  A.remove(P[i])
  #print(A)
  bisect.insort(A,P[i+K])
  #print(A)
B.append(P[:N-K]+A+P[N:])
B.sort()

ans=1
for i in range(1,len(B)):
  if B[i]!=B[i-1]:
    ans+=1
print(ans)

Fixed submission:
from heapq import heappush, heappop

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

h_max = []
h_min = []
for i in range(K):
  heappush(h_min,  A[i])
  heappush(h_max, -A[i])

check = [0] * (N + 1)
tmp = [0] * N
tmp[0] = 1
for i in range(N - K):
  
  a_min =  heappop(h_min)
  a_max = -heappop(h_max)
  while check[a_min]:
    a_min =  heappop(h_min)
  while check[a_max]:
    a_max = -heappop(h_max)
  if A[i] == a_min and A[i + K] > a_max:
    tmp[i + 1] -= 1
  check[A[i]] = 1
  heappush(h_min,  a_min)
  heappush(h_max, -a_max)  
  heappush(h_min,  A[i + K])
  heappush(h_max, -A[i + K])  
  tmp[i + 1] += 1

B = [0]
for i in range(1, N):
  if A[i] > A[i - 1]:
    B.append(1)
  else:
    B.append(0)

sum_B = sum(B[1: K])
flag = 0
for i in range(N - K + 1):
  if sum_B == K - 1:
    if tmp[i]:
      flag = 1
      tmp[i] = 0
  if i == N - K:
    break
  sum_B = sum_B - B[i + 1] + B[i + K]

print(sum(tmp) + flag)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()

dp=[[0 for i in range(N+1)] for j in range(N+1)]

for i in range(N):
  for j in range(i+1,N):
    if S[i]==S[j]:
      dp[i][j]=dp[i-1][j-1]+1
#print(dp)

ans=0
for i in range(N):
  for j in range(i+1,N):
    if ans<dp[i][j]:
      if j-i>=dp[i][j]:
        ans=dp[i][j]

print(ans)

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

T = [[0 for _ in range(N)] for _ in range(N)]

for i in range(N):
  for j in range(i + 1, N):
    if S[i] == S[j]:
      T[i][j] += T[i - 1][j - 1] + 1

answer = 0
for i in range(N):
  for j in range(N):
    if T[i][j] and j - i >= T[i][j]:
      answer = max(answer, T[i][j])
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()

sw=0
for L in range(N-1,0,-1):
  tmp=[]
  for i in range(N-L+1):
    tmp.append([S[i:i+L],i])
  tmp.sort()
  #print(tmp)
  
  old_tmp=tmp[0]
  for i in range(1,N-L+1):
    if tmp[i][0]==old_tmp[0]:
      if tmp[i][1]>=L+old_tmp[1]:
        sw=1
        break
    else:
      old_tmp=tmp[i]
  if sw==1:
    break
print(L if sw==1 else 0)

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

T = [[0 for _ in range(N)] for _ in range(N)]

for i in range(N):
  for j in range(i + 1, N):
    if S[i] == S[j]:
      T[i][j] += T[i - 1][j - 1] + 1

answer = 0
for i in range(N):
  for j in range(N):
    if T[i][j] and j - i >= T[i][j]:
      answer = max(answer, T[i][j])
print(answer)
Buggy python submission (verdict: Runtime Error):
S,T=input(),input()
print((S==T).sum())


Fixed submission:
S,T=input(),input()
res=0
if(S[0]==T[0]): res+=1
if(S[1]==T[1]): res+=1
if(S[2]==T[2]): res+=1
print(res)
Buggy python submission (verdict: Runtime Error):
s=input() #数値入力 「N」だけの入力のとき
t=input()  #数値入力 「N」だけの入力のとき
sa=list(s)
ta=list(t)
ans2
x=0
y=0
ans= [[] for i in range(26)]
for i in range(len(s)):
    ans[ord(sa[i])-96-1].append(i)
print(ans)
for i in range(len(t)):
    if len(ans[ord(ta[i])-97])==0:
        ans2=-1
        break;
    else:
        x_old=x
        for j in ans[ord(ta[i])-97]:
            if j>x:
                x=j
        if x_old==x:
            x=0
            y+=1
            for j in ans[ord(ta[i])-97]:
                if j>x:
                    x=j
print(y*len(s)+x+1)



Fixed submission:
import bisect

s,t=input(),input()
ls=len(s)
lt=len(t)
A=[[] for i in range(26+1)]
L=[0 for i in range(26+1)]

for i in range(ls):
  A[ord(s[i])-96].append(i+1)
  L[ord(s[i])-96]+=1
#print(A)

tmp=0
ans=0
for i in range(lt):
  ii=ord(t[i])-96

  if L[ii]==0:
    print(-1)
    exit()
  else:
    iii=bisect.bisect(A[ii],tmp)
    #print(t[i],A[ii],tmp,iii,ans)
    if iii==L[ii]:
      ans+=ls-tmp+A[ii][0]
      tmp=A[ii][0]
    else:
      ans+=A[ii][iii]-tmp
      tmp=A[ii][iii]
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())  #数値入力 「N」だけの入力のとき
#n=11
#l=len(str(n))
if l ==1:
    print(n)
elif l==2:
    print(9)
elif l==3:
    print(9+n-99)
elif l==4:
    print(9+900)
elif l==5:
    print(9+900+n-9999)
elif l==6:
    print(9+900+90000)
    

Fixed submission:
n=int(input())  #数値入力 「N」だけの入力のとき
#n=11
l=len(str(n))
if l ==1:
    print(n)
elif l==2:
    print(9)
elif l==3:
    print(9+n-99)
elif l==4:
    print(9+900)
elif l==5:
    print(9+900+n-9999)
elif l==6:
    print(9+900+90000)
Buggy python submission (verdict: Runtime Error):
s=input()
#s="RRLLLLRLRRLL"
a = [0] * len(s)
l_first = 0
r_first = 0

for i in range(len(s)):
    ii =len(s)-i-1
    if s[ii] == "R":
        if r_first==0:
            d = len(s)-ii-1
            r_first=ii
            a[ii+1]+=int(d/2)+d%2
            a[ii]+=int(d/2)
        else:
            d = -ii+r_first-1
            r_first=ii
            a[ii+1]+=int(d/2)+d%2
            a[ii]+=int(d/2)    
for i in range(len(s)):
    if s[i] == "L":
        if l_first==0:
            d = i-l_first
            l_first=i
            a[i-1]+=int(d/2)+d%2
            a[i]+=int(d/2)
        else:
            d = i-l_first-1
            l_first=i
            a[i-1]+=int(d/2)+d%2
            a[i]+=int(d/2)
print(" ".join(a))

Fixed submission:
s=input()
#s="RRLLLLRLRRLL"
a = [0] * len(s)
l_first = 0
r_first = 0

for i in range(len(s)):
    ii =len(s)-i-1
    if s[ii] == "R":
        if r_first==0:
            d = len(s)-ii-1
            r_first=ii
            a[ii+1]+=int(d/2)+d%2
            a[ii]+=int(d/2)
        else:
            d = -ii+r_first-1
            r_first=ii
            a[ii+1]+=int(d/2)+d%2
            a[ii]+=int(d/2)    
for i in range(len(s)):
    if s[i] == "L":
        if l_first==0:
            d = i-l_first
            l_first=i
            a[i-1]+=int(d/2)+d%2
            a[i]+=int(d/2)
        else:
            d = i-l_first-1
            l_first=i
            a[i-1]+=int(d/2)+d%2
            a[i]+=int(d/2)
print(" ".join(list(map(str,a))))
Buggy python submission (verdict: Runtime Error):
n=int(input())  #数値入力 「N」だけの入力のとき
c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
d=[i for i in range(1,n+1)]
f=0
for i in range(n):
    if d[i]-d[i]:
        f+=1
if f == 0 or f == 2:
    print("YES")
else:
    print("NO)

Fixed submission:
n=int(input())  #数値入力 「N」だけの入力のとき
#n= 5  #数値入力 「N」だけの入力のとき
c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#c=[5, 2, 3, 4, 1]
d=[i for i in range(1,n+1)]
f=0
for i in range(n):
    if c[i]-d[i]:
        f+=1
#print(f)
if f == 0 or f == 2:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

d = [i*10%13 for i in range(13)]

if S[0]=="?":
  res=[[1,1,1,1,1,1,1,1,1,1,0,0,0]]
else:
  res=[[0 if i!=int(S[0]) else 1 for i in range(13) ]]

for i in range(1,len(S)): #N
  res.append([0 for i in range(13)])
  if S[i]=="?":
    for j in range(13): #N*13
      for k in range(10): #N*13*10
        res[i][(d[j]+k)%13]+=res[i-1][j]
  else:
    for j in range(13):
      res[i][(d[j]+int(S[i]))%13]+=res[i-1][j]
      
print(res[len(S)-1][5]%(10**9+7))

Fixed submission:
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

MOD=10**9+7

S=read().rstrip().decode("utf-8")
#print("S:",S)

R=[0]*13
R_buffer=[0]*13

if S[0]=="?":
  for i in range(0,10):
    R[i]=1
else:
  R[int(S[0])]=1
#print("R:",R)

for i in range(1,len(S)):
  
  if S[i]=="?":
    for j in range(13):
      for k in range(10):
        R_buffer[(j*10+k)%13]+=R[j]
  else:
    for j in range(13):
      R_buffer[(j*10+int(S[i]))%13]+=R[j]
  
  for j in range(13):
    R[j]=R_buffer[j]%MOD
    R_buffer[j]=0
  #print("R:",R)
  
print(R[5])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

d = [i*10%13 for i in range(13)]

if S[0]=="?":
  res=[[1,1,1,1,1,1,1,1,1,1,0,0,0]]
else:
  res=[[0 if i!=int(S[0]) else 1 for i in range(13) ]]

for i in range(1,len(S)):
  res.append([0 for i in range(13)])
  if S[i]=="?":
    for j in range(13):
      for k in range(10):
        res[i][(d[j]+k)%13]+=res[i-1][j]
  else:
    for j in range(13):
      res[i][(d[j]+int(S[i]))%13]+=res[i-1][j]
      
print(res[len(S)-1][5]%(10**9+7))

Fixed submission:
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

MOD=10**9+7

S=read().rstrip().decode("utf-8")
#print("S:",S)

R=[0]*13
R_buffer=[0]*13

if S[0]=="?":
  for i in range(0,10):
    R[i]=1
else:
  R[int(S[0])]=1
#print("R:",R)

for i in range(1,len(S)):
  
  if S[i]=="?":
    for j in range(13):
      for k in range(10):
        R_buffer[(j*10+k)%13]+=R[j]
  else:
    for j in range(13):
      R_buffer[(j*10+int(S[i]))%13]+=R[j]
  
  for j in range(13):
    R[j]=R_buffer[j]%MOD
    R_buffer[j]=0
  #print("R:",R)
  
print(R[5])
Buggy python submission (verdict: Runtime Error):
S=int(input())
x1,y1=0,0
x2,y2=10**9,1

if S//10**9==0:
  y3=0
  x3=S
else:
  y3=-(-S/10**9//1)
  x3=10**9*x3-S
print(x1,y1,x2,y2,x3,y3)

Fixed submission:
S=int(input())

x1,y1=0,0
x2,y2=10**9,1

y3=-(-S//10**9)
x3=y3*10**9-S

print(x1,y1,x2,y2,x3,y3)
Buggy python submission (verdict: Runtime Error):
A,P = map(int,input().split())
print((A*3+P)//2)

Fixed submission:
N,A,B=map(int,input().split())
print(min(N*A,B))

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

Fixed submission:
N,A,B=map(int,input().split())
print(min(N*A,B))

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

print(min(N*A,B))

Fixed submission:
N,A,B=map(int,input().split())
print(min(N*A,B))

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

print(max(N*A,B))

Fixed submission:
N,A,B=map(int,input().split())
print(min(N*A,B))
Buggy python submission (verdict: Runtime Error):
print("reference: yaketate08")

from collections import deque

N, M = map(int, input().split())
UV = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())

graph = [[] for i in range(N + 1)]
for U, V in UV:
    graph[U].append(V)

INF = 10 ** 9

U = [[INF for _ in range(N)] for i in range(3)]
U[0][S] = 0 # S != T なのでこの表記はOK

#そうか、余りの数で最小のものを都度探す。
que = deque([(S, 0)])
while que:
    v, t = que.popleft()
    u = (t + 1) % 3
    d = U[t][v]
    if t == 2:
        d += 1
    Uu = U[u]
    for w in G[v]:
        if Uu[w] != INF:
            continue
        que.append((w, u))
        Uu[w] = d
print(U[0][T] if U[0][T] < INF else -1)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline

from collections import deque

N, M = map(int, input().split())
UV = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())
INF = 10 ** 15

if M == 0:
  print(-1)
  exit()

graph = [[] for _ in range(3 * M + 1)]
for u, v in UV:
  graph[u].append(v + M)
  graph[u + M].append(v + 2 * M)
  graph[u + 2 * M].append(v)

queue = deque([S])
dist = [INF] * (3 * M + 1)
dist[S] = 0

while queue:
  q = queue.popleft()
  for g in graph[q]:
    if dist[g] > dist[q] + 1:
      dist[g] = dist[q] + 1
      queue.append(g)
print(dist[T] // 3 if dist[T] != INF else -1)
Buggy python submission (verdict: Runtime Error):
def z_algorithm(s):
  n = len(s)
  z = [None] * n
  z[0] = n
  
  i = 1
  j = 0
  while i < n:
    while i + j < n and s[j] == s[i + j]:
      j += 1
    z[i] = j
    if j == 0:
      i += 1
      continue
    k = 1
    while i + k < n and z[k] + k < j:
      z[i + k] = z[k]
      k += 1
    i += k
    j -= k
  return z

S = input()
T = input()
z = z_algorithm(T + "$" + S)

length = len(T)
for i in range(len(z)):
  if z[i] == length:
    index = i - length - 1
    print(index)

Fixed submission:
S = list(input())
if S[0]!=S[1] and S[1]!=S[2] and S[2]!=S[3]:
    print("Good")
else:
    print("Bad")

Buggy python submission (verdict: Runtime Error):
S = list(input)
if S[0]!=S[1] and S[1]!=S[2] and S[2]!=S[3]:
    print("Bad")
else:
    print("Good")

Fixed submission:
S = list(input())
if S[0]!=S[1] and S[1]!=S[2] and S[2]!=S[3]:
    print("Good")
else:
    print("Bad")
Buggy python submission (verdict: Runtime Error):
import math

A,B,C,D=map(int,input().split())
CD = C*D/math.gcd(C,D)

def S(A,B,X):
    A = A if A%X==0 else A+(X-A%X)
    if B>A:
        return int((B-A)//X+1)
    else:
        return 0

print(B-A+1-(S(A,B,C)+S(A,B,D)-S(A,B,CD)))
    

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

A,B,C,D=map(int,input().split())

CD=int(C*D/gcd(C,D))
Ac=A if A%C==0 else A+(C-A%C)
Ad=A if A%D==0 else A+(D-A%D)
Acd=A if A%CD==0 else A+(CD-A%CD)

Rc=(B-Ac)//C+1 if Ac>=A and Ac<=B else 0
Rd=(B-Ad)//D+1 if Ad>=A and Ad<=B else 0
Rcd=(B-Acd)//CD+1 if Acd>=A and Acd<=B else 0

print(B-A+1-(Rc+Rd-Rcd))
Buggy python submission (verdict: Runtime Error):
N,X=map(int,input().split())
L=list(map(int,input().split()))

D=0
for i in range(N+1):
  D+=L[i]
  if D>X:
    break
    
print(i+1)

Fixed submission:
N,X=map(int,input().split())
L=list(map(int,input().split()))
#print(L)

D=0
for i in range(N):
  D+=L[i]
  if D>X:
    print(i+1)
    break
  if i==N-1:
    print(i+2)
    break
Buggy python submission (verdict: Runtime Error):
import collections

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

pq = []
for i in range(N):
  xi, yi = xy[i][0], xy[i][1]
  for j in range(i + 1, N):
    xj, yj = xy[j][0], xy[j][1]
    p, q = xj - xi, yj - yi
    pq.append((p, q))
#print(pq)

c = list(collections.Counter(pq).values())
c.sort()
print(N - c[-1])

Fixed submission:
import collections

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

if N == 1:
  print(1)
  exit()

pq = []
for i in range(N):
  xi, yi = xy[i][0], xy[i][1]
  for j in range(i + 1, N):
    xj, yj = xy[j][0], xy[j][1]
    p, q = xj - xi, yj - yi
    pq.append((p, q))
#print(pq)

c = list(collections.Counter(pq).values())
c.sort()
print(N - c[-1])
Buggy python submission (verdict: Runtime Error):
N=int(input())
W=list(map(int,input().split()))

res=0
s=sum(W)
ans=100000000000
for i in range(N):
  res+=W[i]
  ans=min(abs(s-res*2))
print(ans)
          

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

res=0
s=sum(W)
ans=100000000000
for i in range(N):
  res+=W[i]
  ans=min(ans,abs(s-res*2))
print(ans)

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

res=0
s=sum(W)
ans=100000000000
for i in range(N):
  res+=W[i]
  ans=min(abs(s-res*2)

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

res=0
s=sum(W)
ans=100000000000
for i in range(N):
  res+=W[i]
  ans=min(ans,abs(s-res*2))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
S=[]
for i in range(H):
  S.append(input())
  
L=[[0 for i in range(W)] for j in range(H)]
R=[[0 for i in range(W)] for j in range(H)]
D=[[0 for i in range(W)] for j in range(H)]
U=[[0 for i in range(W)] for j in range(H)]
A=[[0 for i in range(W)] for j in range(H)]

for i in range(H):
  for j in range(W):
      if S[i][j]=='.':
        L[i][j]=L[i][j-1]+1 if j!=0 else 1
      else:
        L[i][j]=0
#print(L)

for i in range(H):
  for j in reversed(range(W)):
      if S[i][j]=='.':
        R[i][j]=R[i][j+1]+1 if j!=W-1 else 1
      else:
        R[i][j]=0
#print(R)

for j in range(W):
  for i in range(H):
      if S[i][j]=='.':
        U[i][j]=U[i-1][j]+1 if i!=0 else 1
      else:
        U[i][j]=0
#print(U)

for j in range(W):
  for i in reversed(range(H)):
      if S[i][j]=='.':
        D[i][j]=D[i+1][j]+1 if i!=H-1 else 1
      else:
        D[i][j]=0
#print(D)

for i in range(H):
  for j in range(W):
    A[i][j]=L[i][j]+R[i][j]+D[i][j]+U[i][j]-3

res = -1
for i in range(H):
  res = max(res,max(A[i]))
print(res)

Fixed submission:
import numpy as np

H,W=map(int,input().split())
S=np.array([list(input()) for _ in range(H)])=='.'
D=np.zeros((H,W),dtype=int)
U=np.zeros((H,W),dtype=int)
L=np.zeros((H,W),dtype=int)
R=np.zeros((H,W),dtype=int)

for i in range(H):
  U[i]=(U[i-1]+1)*S[i]
  D[-i-1]=(D[-i]+1)*S[-i-1]
for i in range(W):
  L[:,i]=(L[:,i-1]+1)*S[:,i]
  R[:,-i-1]=(R[:,-i]+1)*S[:,-i-1]
#print(L)
print(np.max(U+D+L+R)-3)
Buggy python submission (verdict: Runtime Error):
N,A,B,C,D=map(int,input().split())
S=input()

d=0
for i in range(min(A+1,N-1),min(C+1,N-1)):
  if S[i]=="#" and S[i+1]=="#":
    d=1
    break
for i in range(min(B+1,N-1),min(D+1,N-1)):
  if S[i]=="#" and S[i+1]=="#":
    d=1
    break

if C<D:
  t=1
else:
  for i in range(max(0,min(B-1,N-2)),min(C+1,N-2)):
    if S[i]=="." and S[i+1]=="." and S[i+2]==".":
      t=1
      break

if C==D:
  print("No")
else:
  if d==1:
    print("No")
  else:
    if t==0:
      print("No")
    else:
      print("Yes")

Fixed submission:
N,A,B,C,D=map(int,input().split())
S=input()
 

if "##" in S[A-1:C] or "##" in S[B-1:D]:
  print("No")
  exit()


# A B C D
# A C B D
if C < D:
  print("Yes")
  exit()

# A B D C  
else:
  if "..." in S[B-2:D+1]:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
V = list(map(int, input().split()))

first_sum = sum(V)

answer = 0
for i in range(min(N + 1, K + 1)):
  for j in range(i + 1):
    left = j
    right = i - j
    
    q = []
    for k in range(left):
      q.append(V[k])
    for k in range(N - right, N):
      q.append(V[k])
    q.sort()
    
    tmp = sum(q)
    for k in range(min(K - i, len(q))):
      if q[k] < 0:
        tmp -= q[k]
      else:
        break
    answer = max(answer, tmp)
    
print(answer)N, K = map(int, input().split())
V = list(map(int, input().split()))

first_sum = sum(V)

answer = 0
for i in range(min(N + 1, K + 1)):
  for j in range(i + 1):
    left = j
    right = i - j
    
    q = []
    for k in range(left):
      q.append(V[k])
    for k in range(N - right, N):
      q.append(V[k])
    q.sort()
    
    tmp = sum(q)
    for k in range(min(K - i, len(q))):
      if q[k] < 0:
        tmp -= q[k]
      else:
        break
    answer = max(answer, tmp)
    
print(answer)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,K = map(int, readline().split())
V = list(map(int, readline().split()))

answer = 0

for i in range(min(N, K)+1):
  for j in range(i+1):
    U = V[:j]+V[N-(i-j):]
    U.sort()
    rid = K - i
    for k in range(len(U)):
      if rid == 0:
        break
      if U[k] < 0:
        rid -= 1
        U[k] = 0
      else:
        break
    answer = max(sum(U), answer)   
print(answer)
Buggy python submission (verdict: Runtime Error):
A,B map(int,input().split())
if A<=5:
    print(0)
elif A<=12:
    print(B/2)
else:
    print(B)

Fixed submission:
A,B = map(int,input().split())
if A<=5:
    print(0)
elif A<=12:
    print(int(B/2))
else:
    print(B)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

check=[-1]*(N+1)
check[1]=0
D = deque()
D.append(1)

while D:
  d=D.popleft()
  for b in B[d]:
    if check[b]==-1:
      D.append(b)
      check[b]=(check[d]+A[d][b])%2

for i in range(1,len(check)):
  print(check[i])

Fixed submission:
from collections import deque

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

check = [-1] * (N + 1)
check[1] = 0
D = deque()
D.append(1)

while D:
  d=D.popleft()
  for a in A[d]:
    if check[a[0]]==-1:
      D.append(a[0])
      check[a[0]]=(check[d]+a[1])%2

for i in range(1,len(check)):
  print(check[i])
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N=map(int,input().split())

ans=0
for r in range(N//R+1):
  for g in range(N//G+1):
    b=(N-r*R-g*G)/B
    if b.is_integer() and b>=0:
      ans+=1
      #print(r,g,b)  
print(ans)

Fixed submission:
R,G,B,N=map(int,input().split())

ans=0
for r in range(N//R+1):
  for g in range((N-r*R)//G+1):
    if (N-r*R-g*G)%B==0:
      ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [input() for _ in range(H)]

INF = 10 ** 10
B = [[INF for _ in range(W)] for _ in range(W)]

for h in range(H):
  for w in range(W):
    if A[h][w] == "#":
      B[h][w] = 0

for h in range(H):
  for w in range(W):
    if B[h][w] == 0:
      stack = [(h, w)]
      while stack:
        hh, ww = stack.pop()
        if hh != 0:
          if B[hh][ww] + 1 < B[hh - 1][ww]:
            B[hh - 1][ww] = B[hh][ww] + 1
            stack.append((hh - 1, ww))

        if hh != H - 1:
          if B[hh][ww] + 1 < B[hh + 1][ww]:
            B[hh + 1][ww] = B[hh][ww] + 1
            stack.append((hh + 1, ww))


        if ww != 0:
          if B[hh][ww] + 1 < B[hh][ww - 1]:
            B[hh][ww - 1] = B[hh][ww] + 1
            stack.append((hh, ww - 1))

        if ww != W - 1:
          if B[hh][ww] + 1 < B[hh][ww + 1]:
            B[hh][ww + 1] = B[hh][ww] + 1
            stack.append((hh, ww + 1))
answer = 0
for h in range(H):
  for w in range(W):
    answer = max(answer, B[h][w])
print(answer)

Fixed submission:
from collections import deque

H, W = map(int, input().split())
A = [input() for _ in range(H)]

check = [[-1 for _ in range(W)] for _ in range(H)]
q = deque()
for i in range(H):
  for j in range(W):
    if  A[i][j] == "#":
      check[i][j] = 0
      q.append((i, j))

while q:
  i, j = q.popleft()
  
  if i - 1 >= 0 and check[i - 1][j] == -1:
      check[i - 1][j] = check[i][j] + 1
      q.append((i - 1, j))

  if i + 1 < H and check[i + 1][j] == -1:
      check[i + 1][j] = check[i][j] + 1
      q.append((i + 1, j))

  if j - 1 >= 0 and check[i][j - 1] == -1:
      check[i][j - 1] = check[i][j] + 1
      q.append((i, j - 1))

  if j + 1 < W and check[i][j + 1] == -1:
      check[i][j + 1] = check[i][j] + 1
      q.append((i, j + 1))

answer = -1
for i in range(H):
  answer = max(answer, max(check[i]))
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

AB=[]
for i in A:
  for j in B:
    heapq.heappush(AB,-i-j)
#print(AB)

ABC=[]
for i in AB:
  for j in C:
    heapq.heappush(ABC,i-j)

for i in range(min(K,X*Y*Z)):
  print(-heapq.heappop(ABC))
    

Fixed submission:
import heapq

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

AB=[]
for i in A:
  for j in B:
    heapq.heappush(AB,-i-j)
#print(AB)

ABC=[]
for i in range(min(K,X*Y)):
  temp=heapq.heappop(AB)
  for j in C:
    heapq.heappush(ABC,temp-j)

for i in range(min(K,X*Y*Z)):
  print(-heapq.heappop(ABC))

Buggy python submission (verdict: Time Limit Exceeded):
X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

AB=[]
for i in A:
  for j in B:
    AB.append(i+j)
AB=sorted(AB,key=lambda x: -x)
AB=AB[:min(K,len(A)*len(B))]
#print(AB)

ABC=[]
for i in AB:
  for j in C:
    ABC.append(i+j)
ABC=sorted(ABC,key=lambda x: -x)
#print(ABC)

for i in range(min(K,X*Y*Z)):
  print(ABC[i])

Fixed submission:
import heapq

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

AB=[]
for i in A:
  for j in B:
    heapq.heappush(AB,-i-j)
#print(AB)

ABC=[]
for i in range(min(K,X*Y)):
  temp=heapq.heappop(AB)
  for j in C:
    heapq.heappush(ABC,temp-j)

for i in range(min(K,X*Y*Z)):
  print(-heapq.heappop(ABC))