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

Fixed submission:
N,K=map(int,input().split(' '))
A=list(map(lambda x:int(x)-1,input().split(' ')))
roop=[0]
flg = [0 for i in range(N)]
flg[0]=1
n = A[0]
for i in range(2,N+1):
    if flg[n]==0:
        roop.append(n)
        flg[n] = i
        n = A[n]
    else:
        end=i
        break
if K <len(roop):
    print(roop[K]+1)
else:
    K-=flg[n]-1
    K%=(end-flg[n])
    roop=roop[flg[n]-1:end]
    print(roop[K]+1)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split(' '))
A=list(map(lambda x:int(x)-1,input().split(' ')))
roop=[0]
flg = [0 for i in range(N)]
n = A[0]
cnt = 0
while not flg[n] and n !=0:
    cnt += 1
    roop.append(n)
    flg[n]=cnt
    n = A[n]
if K<=len(roop):
    print(roop[K])
else:
    print(roop[flg[n]:cnt+1][(K-flg[n])%(cnt-flg[n]+1)]+1)
Problem p02692 (python)

Fixed submission:
N,A,B,C=map(int,input().split(' '))
S = [input() for i in range(N)]
ans = []
if A+B+C==0:
    print('No')
else:
    d = {"A":A,"B":B,"C":C}
    for n,i in enumerate(S):
        l,r=list(i)
        L,R=d[l],d[r]
        if L==R==0:
            print('No')
            exit()
        elif L==0:
            ans.append(l)
            d[l] +=1
            d[r] -=1
        elif R==0:
            d[l] -=1
            d[r] +=1
            ans.append(r)
        elif L==R==1 and n != N-1 and i != S[n+1]:
            if l in S[n+1]:
                d[l] +=1
                d[r] -=1
                ans.append(l)
            else:
                d[l] -=1
                d[r] +=1
                ans.append(r)
        else:
            if L>=R:
                d[l] -=1
                d[r] +=1
                ans.append(r)
            else:
                d[l] +=1
                d[r] -=1
                ans.append(l)
    print('Yes')
    for i in ans:
        print(i)

Buggy submission (verdict: Runtime Error):
N,A,B,C=map(int,input().split(' '))
S = [input() for i in range(N)]
ans = []
if A+B+C==0:
    print('No')
else:
    d = {"A":A,"B":B,"C":C}
    for n,i in enumerate(S):
        l,r=list(i)
        L,R=d[l],d[r]
        if L==R==0:
            print('No')
            exit()
        elif L==0:
            ans.append(l)
            d[l] +=1
            d[r] -=1
        elif R==0:
            d[l] -=1
            d[r] +=1
            ans.append(r)
        elif L==R==1 and n != N-1 and i != S[n+1]:
            if l in S[n+1]:
                d[l] +=1
                d[r] -=1
                ans.append(l)
            else:
                d[l] -=1
                d[r] +=1
                ans.apppend(r)
        else:
            if L>=R:
                d[l] -=1
                d[r] +=1
                ans.append(r)
            else:
                d[l] +=1
                d[r] -=1
                ans.append(l)
print('Yes')
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
N,A,B,C=map(int,input().split(' '))
S = [input() for i in range(N)]
ans = []
if A+B+C==0:
    print('No')
else:
    d = {"A":A,"B":B,"C":C}
    for n,i in enumerate(S):
        l,r=list(i)
        L,R=d[l],d[r]
        if L==R==0:
            print('No')
            print(ans)
            exit()
        elif L==0:
            ans.append(l)
            d[l] +=1
            d[r] -=1
        elif R==0:
            d[l] -=1
            d[r] +=1
            ans.append(r)
        elif L==R==1 and n != N-1 and i != S[n+1]:
            if l in S[n+1]:
                d[l] +=1
                d[r] -=1
                ans.append(l)
            else:
                d[l] -=1
                d[r] +=1
                ans.apppend(r)
        else:
            if L>=R:
                d[l] -=1
                d[r] +=1
                ans.append(r)
            else:
                d[l] +=1
                d[r] -=1
                ans.append(l)
print('Yes')
for i in ans:
    print(i)
Problem p02727 (python)

Fixed submission:
import heapq as hq
X,Y,A,B,C=map(int,input().split(' '))
P,Q,R=[sorted(list(map(int,input().split(' '))),reverse=True) for i in range(3)]
P=P[:X]
Q=Q[:Y]
hq.heapify(P)
hq.heapify(Q)
R=R[::-1]
while len(R)>0:
    p=hq.heappop(P)
    q=hq.heappop(Q)
    r=R.pop()
    if r<=min(p,q):
        hq.heappush(P,p)
        hq.heappush(Q,q)
        break
    if p<=q and p<r:
        hq.heappush(P,r)
        hq.heappush(Q,q)
    elif p>q and q<r:
        hq.heappush(P,p)
        hq.heappush(Q,r)
print(sum(P)+sum(Q))

Buggy submission (verdict: Runtime Error):
import heapq as hq
X,Y,A,B,C=map(int,input().split(' '))
P,Q,R=[sorted(list(map(int,input().split(' '))),reverse=True) for i in range(3)]
P=P[:X]
Q=Q[:Y]
hq.heapify(P)
hq.heapify(Q)
R=R[::-1]
while len(R)>0:
    p=hq.heappop(P)
    q=hq.heappop(Q)
    r=R.pop()
    if r<min(p,q):
        hq.heappush(P,p)
        hq.heappush(Q,q)
        break
    if p<=q and p<r:
        hq.heappush(P,r)
        hq.heappush(Q,q)
    elif p>q and q<r:
        hq.heappush(P,p)
        hq.heappush(Q,r)
print(sum(P)+sum(Q))
Problem p02744 (python)

Fixed submission:
N=int(input())
ans = []
def same(c):
    if len(c)==N:
        ans.append(c)
        return
    else:
        for i in range(ord('a'),ord('a')+len(list(set(list(c))))+1):
            same(c+chr(i))

same('a')
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
N=int(input())
ans = []
def same(c):
    if len(c)==N:
        ans.append(c)
        return
    else:
        for i in range(ord('a'),ord(c[-1])+2):
            same(c+chr(i))
same('a')
for i in ans:
    print(ans)
Problem p02756 (python)

Fixed submission:
from collections import deque
s=deque(list(input()))
q=int(input())
r = False
for i in range(q):
    tmp = list(input().split(' '))
    if tmp[0]=='1':
        r = not r
    elif (not r and tmp[1]=='1') or (r and tmp[1] =='2'):
        s.appendleft(tmp[2])
    else:
        s.append(tmp[2])
if not r:
    for i in s:
        print(i,end='')
else:
    for i in reversed(s):
        print(i,end='')

Buggy submission (verdict: Runtime Error):
from collections import deque
s=deque(list(input()))
q=int(input())
r = False
for i in range(q):
    tmp = list(input().split(' '))
    if tmp[0]=='1':
        r = not r
    elif (not r and tmp[1]=='1') or (r and tmp[1] =='2'):
        s.appendleft(tmp[2])
    else:
        s.append(tmp[2])
if not r:
    for i in s:
        print(i,end='')
else:
    for i in s[::-1]:
        print(i,end='')

Buggy submission (verdict: Runtime Error):
from collections import deque
s=deque(list(input()))
q=int(input())
r = False
for i in range(q):
    tmp = list(input().split(' '))
    if tmp[0]=='1':
        r = not r
    elif (not r and tmp[1]=='1') or (r and tmp[1] =='2'):
        s.appendleft(tmp[2])
    else:
        s.append(tmp[2])
if not r:
    for i in s:
        print(i,end='')
else:
    for i in s[::-1]:
        print(i,end='')
Problem p02767 (python)

Fixed submission:
N=int(input())
X=sorted(list(map(int,input().split(' '))))
ans = 10**9
for i in range(X[0],X[-1]+1):
    tmp = 0
    for j in X:
        tmp += (j-i)**2
    ans = min(ans,tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
X=sorted(list(map(int,input().split(' '))))
ans =math.inf
for i in range(X[0],X[-1]+1):
    tmp = 0
    for j in X:
        tmp += (j-i)**2
    ans = min(ans,tmp)
print(ans)
Problem p02817 (python)

Fixed submission:
S,T=input().split(' ')
print(T+S)

Buggy submission (verdict: Runtime Error):
S,T=input().split('')
print(T+S)
Problem p02841 (python)

Fixed submission:
M_1,D_1 = map(int,input().split())
M_2,D_2 = map(int,input().split())
if M_1 != M_2:
  print(1)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
n = int(input())
a=list(map(int,input().split(' ')))
mod = 10**9+7
ans = 1
color=[1,0,0]
g = 0
for i in a[1:]:
    cnt = 0
    for n,j in enumerate(color):
        if i==0 and j ==0:
            color[n]+=1
            cnt = 1
            break
        elif i==j:
            cnt += 1
            if cnt == 1:
                color[n]+=1
    ans *= cnt
    ans %= mod
for i in color:
    if i >0:
        g += 1
if g ==1:
    print(ans*3%mod)
else:
    print(ans*6%mod)
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500000)
N = int(input())
E = [[] for i in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split(' '))
    E[a].append((b, i))
    E[b].append((a, i))
K = max(len(e) for e in E)
print(K)
ans = [-1] * (N - 1)


def dfs(v=1, p=0, p_col=-1):
    col = 1
    for u, idx in E[v]:
        if u != p:
            if col == p_col:
                col += 1
            ans[idx] = col
            dfs(u, v, col)
            col += 1


dfs()
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
E = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split(' '))
    E[a].append((b,i))
    E[b].append((a,i))
K = max(len(e) for e in E)
print(K)
ans = [-1]*(N-1)
def dfs(v=1, p=0, p_col=-1):
    col = 1
    for u, idx in E[v]:
        if u != p:
            if col == p_col:
                col += 1
            ans[idx] = col
            dfs(u, v, col)
            col += 1
dfs()
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
E = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split(' '))
    E[a].append((b,i))
    E[b].append((a,i))
K = max(len(e) for e in E)
print(K)
ans = [-1]*(N-1)
def dfs(v=1, p=0, p_col=-1):
    col = 1
    for u, idx in E[v]:
        if u != p:
            if col == p_col:
                col += 1
            ans[idx] = col
            dfs(u, v, col)
            col += 1
dfs()
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
E = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split(' '))
    E[a].append((b,i))
    E[b].append((a,i))
K = max(len(e) for e in E)
print(K)
ans = [-1]*(N-1)
def dfs(v=1, p=0, p_col=-1):
    col = 1
    for u, idx in E[v]:
        if u != p:
            if col == p_col:
                col += 1
            ans[idx] = col
            dfs(u, v, col)
            col += 1
dfs()
for i in ans[1:]:
    print(i)
Problem p02913 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def Z(s):
    """
    s: str
    return list of int with length len(s)
    """
    # initialization
    n=len(s)
    z=[0]*n
    z[0]=n
    # construct
    L,R=0,0
    for i in range(1,n):
        if i>=R: # 過去の結果が全く使えない
            L=R=i
            while(R<n and s[R-L]==s[R]): R+=1
            z[i]=R-L
        elif z[i-L]<R-i: # 過去の結果が全て使える
            z[i]=z[i-L]
        else: # 過去の結果が一部使える
            L=i
            while(R<n and s[R-L]==s[R]): R+=1
            z[i]=R-L
    return z
def resolve():
    n=int(input())
    s=input()
    ans=0
    for i in range(n):
        z=Z(s[i:])
        k=len(z) # k=n-i
        for j in range(k):
            ans=max(ans,min(j,z[j]))
    print(ans)
resolve()

Buggy submission (verdict: Runtime Error):
def z_argorithm(s):
    s_len=len(s)
    a=[0]*s_len
    c=0
    for i in range(1,s_len):
        if i+a[i-c] < c+a[c]:
            a[i]=a[i-c]
        else:
            j=max(0,c+a[c]-i)
            while i+j<s_len and s[j]==s[j+i]:
                j += 1
            a[i]=j
            c=i
    return a
def main():
    n=int(input())
    s=input()
    ans = 0
    for i in range(n-1):
        a = z_argorithm(s[i:])
        A=len(a)
        for i in range(A):
            ans=max(ans,min(i,a[i]))
    print(ans)
if __name__ == '__main__':
    main()
Problem p02945 (python)

Fixed submission:
def main():
    a,b = map(int,input().split(' '))
    print(max(a+b,a-b,a*b))
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def mian():
    a,b=map(jnt,input().split(' '))
    print(max(a+b,a-b,a*b))
if __name__ == '__main__':
    main()
Problem p02963 (python)

Fixed submission:
S=int(input())
if S<10**18:
    x1,y1,x2,y2,x3,y3=0,0,(S//10**9+1),10**9-S%10**9,1,10**9
else:
    x1,y1,x2,y2,x3,y3=(0,0,10**9,1,0,10**9)
print(x1,y1,x2,y2,x3,y3)

Buggy submission (verdict: Runtime Error):
def main():
    s = int(input())
    x = int(s**0.5//1)
    if s <= 10**9:
        print(0,0,1,0,0,s)
        exit()
    if s%2 != 0
        print(0,1,1,0,s//2+1,s//2+1)
        exit()
    for i,j in zip(range(x,0,-1),range(x,s+1)):
        if s%i ==0:
            x = i
            break
        elif s%j == 0:
            x = i
            break
    y = int(s/x)
    print(0,0,x,0,0,y)
if __name__ == '__main__':
    main()
Problem p02981 (python)

Fixed submission:
def main():
    n,a,b = map(int,input().split(' '))
    print(min(int(n*a),b))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    l,r = map(int,input().split(' '))
    tmp = 2019
    if l//2019 < r//2019:
        print(0)
    else:
        for i in range(l,r):
            if tmp > (i*(i+1))%2019:
                tmp = (i*(i+1))%2019
                if tmp == 0:
                    print(i,i+1)
        print(tmp)

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

Fixed submission:
def main():
    l,r = map(int,input().split(' '))
    tmp = 2019
    if l//2019 < r//2019:
        print(0)
    else:
        for i in range(l,r):
            for j in range(i+1,r+1):
                if tmp > (i*j)%2019:
                    tmp = (i*j)%2019
        print(tmp)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    l,r = map(int,input().split(' '))
    tmp = 2019
    if l//2019 < r//2019:
        print(0)
    else:
        for i in range(l,r):
            if tmp > (i*(i+1))%2019:
                tmp = (i*(i+1))%2019
                if tmp == 0:
        print(tmp)

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

Fixed submission:
import numpy as np
H,W=map(int,input().split(' '))
maze = [list(input()) for i in range(H)]
maze = (np.array(maze) == '.')*1
L=np.zeros((H,W),dtype=int)
R=np.zeros((H,W),dtype=int)
U=np.zeros((H,W),dtype=int)
D=np.zeros((H,W),dtype=int)
for i in range(W):
    if i==0:
        L[:,i]=maze[:,i]
        R[:,W-i-1]=maze[:,W-i-1]
    else:
        L[:,i]=(L[:,i-1]+1)*maze[:,i]
        R[:,W-i-1]=(R[:,W-i]+1)*maze[:,W-i-1]
for i in range(H):
    if i==0:
        U[i,:]=maze[i,:]
        D[H-i-1,:]=maze[H-i-1,:]
    else:
        U[i,:]=(U[i-1,:]+1)*maze[i,:]
        D[H-i-1,:]=(D[H-i]+1)*maze[H-i-1,:]
print(max(np.max(U+D+L+R-3),0))

Buggy submission (verdict: Runtime Error):
import numpy as np
H,W=map(int,input().split(' '))
maze = [list(input()) for i in range(H)]
maze_w=[]
maze_h=[]
for i in maze:
    cnt = 0
    l = 0
    r = 0
    tmp = ''
    for j in i:
        if j != "#":
            cnt += 1
            r += 1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            l = r+1
            r = r+1
            cnt = 0
        else:
            tmp +='0'
    if cnt:
        tmp +=str(cnt)*cnt
    maze_w.append(list(tmp))

for i in range(W):
    cnt = 0
    h = 0
    t = 0
    tmp = ""
    for j in range(H):
        if maze[j][i]!='#':
            cnt += 1
            t +=1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            h = t+1
            t = t+1
            cnt = 0
        else:
            tmp += '0'
    if cnt:
        tmp += str(cnt)*cnt
    maze_h.append(list(tmp))
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,int(maze_h[j][i])+int(maze_w[i][j])-1)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
H,W=map(int,input().split(' '))
maze = np.array([list(input()) for i in range(H)])
maze_w=[]
maze_h=np.array([['0']*W for i in range(H)])
for i in maze:
    cnt = 0
    l = 0
    r = 0
    tmp = ''
    for j in i:
        if j != "#":
            cnt += 1
            r += 1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            l = r+1
            r = r+1
            cnt = 0
        else:
            tmp +='0'
    if cnt:
        tmp +=str(cnt)*cnt
    maze_w.append(list(tmp))

for i in range(W):
    cnt = 0
    h = 0
    t = 0
    tmp = ""
    for j in maze[:,i]:
        if j!='#':
            cnt += 1
            t +=1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            h = t+1
            t = t+1
            cnt = 0
        else:
            tmp += '0'
    if cnt:
        tmp += str(cnt)*cnt
    maze_h[:,i] = list(tmp)
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,int(maze_h[i][j])+int(maze_w[i][j])-1)
print(ans)
Problem p03031 (python)

Fixed submission:
import itertools

def main():
    n,m=list(map(int,input().split(' ')))
    swich_all=list(itertools.product([0,1],repeat=n))
    swich=[]
    cnt=0
    for i in range(m):
        swich.append(list(map(int,input().split(' '))))
    check_p=list(map(int,input().split(' ')))
    for i in swich_all:
        check = []
        for j in range(m):
            tmp = 0
            for k in swich[j][1:]:
                tmp += i[k-1]
            check.append(tmp%2)
        if check == check_p:
            cnt +=1

    print(cnt)

main()

Buggy submission (verdict: Runtime Error):
import itertools

def main():
    n,m=list(map(int,input().split(' ')))
    swich_all=list(itertools.product([0,1],repeat=n))
    swich=[]
    cnt=0
    for i in range(m):
        swich.append(list(map(int,input().split(' '))))
    check_p=list(map(int,input().split(' ')))
    for i in swich_all:
        tmp=0
        check =True
        for j in range(m):
            for k in swich[j][1:]:
                tmp += i[k-1]
            if tmp%2 != check_p[j]:
                check = False
                break
        if check == True:
            cnt +=1

    print(cnt)

main()

main()
Problem p03044 (python)

Fixed submission:
from collections import deque
N = int(input())
E = [[] for i in range(N + 1)]
ans = [-1]*(N+1)
ans[1] = 0
for i in range(N - 1):
    u, v, w = map(int, input().split((' ')))
    E[u].append((u, v, w % 2))
    E[v].append((v, u, w % 2))
dfs = deque(E[1])
while dfs:
    p = (dfs.popleft())
    f, t, w = p
    if ans[t] != -1:
        continue
    if w == 0:
        ans[t] = ans[f]
    else:
        ans[t] = 0 if ans[f] else 1
    for i in E[t]:
        dfs.append(i)
for i in ans[1:]:
    print(i)

Buggy submission (verdict: Runtime Error):
from collections import deque
N = int(input())
E = [[] for i in range(N + 1)]
ans = [-1]*(N+1)
ans[1] = 0
for i in range(N - 1):
    u, v, w = map(int, input().split((' ')))
    E[u].append((v, w % 2))
    E[v].append((u, w % 2))


def dfs(c=0,p=1):
    for e,w in E[p]:
        if ans[e] != -1:
            continue
        if w:
            ans[e] = 0 if c else 1
        else:
            ans[e] = c
        dfs(ans[e], e)
dfs()
for i in ans[1:]:
    print(i)

Buggy submission (verdict: Runtime Error):
from collections import deque
N = int(input())
E = [[] for i in range(N + 1)]
ans = [-1]*(N+1)
ans[1] = 0
for i in range(N - 1):
    u, v, w = map(int, input().split((' ')))
    E[u].append((v, w % 2))
    E[v].append((u, w % 2))


def dfs(c=0,p=1):
    for e,w in E[p]:
        if ans[e] != -1:
            continue
        if w:
            ans[e] = 0 if c else 1
        else:
            ans[e] = c
        dfs(ans[e], e)
dfs()
print(ans[1:])
Problem p03069 (python)

Fixed submission:
n = int(input())
s = input()
ans = s.count('.')
num = ans
for c in s:
  if c == '.':
    num -= 1
  else:
    num += 1
  
  ans = min(ans,num)

print(ans)

Buggy submission (verdict: Runtime Error):
from heapq import *
def main():
    N=int(input())
    line = list(input())
    ans=[]

    for i in range(N+1):
        a=line[:i].count("#")
        b=line[i:].count(".")
        heappush(ans,a+b)
    
    return peappop(ans)

print(main())
Problem p03071 (python)

Fixed submission:
A,B=list(map(int,input().split(" ")))
coin=[A+(A-1),B+(B-1),A+B]
print(max(coin))

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

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

def solve():
    cnt=0
    l=[]
    prev = "1"
    for i in S:
        if prev ==i:
            cnt += 1
        else:
            l.append(cnt)
            cnt = 1
        prev =i
    l.append(cnt)
    if prev=="0":
        l.append("0")
    
    w = 2 * K + 1
    
    if len(l) <=w:
        return N
    
    acc=[0]+list(accumulate(l))
    ans = 0
    for i in range(0,len(l) - w+ 1,2):
        ans = max(ans, acc[w+i] - acc[i])

    return ans
print(solve())

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

n, k = list(map(int, input().split()))
s = input()


def solve():
    l = []
    prev = '1'
    cnt = 0
    for c in s:
        if prev == c:
            cnt += 1
        else:
            l.append(cnt)
            cnt = 1
        prev = c
    l.append(cnt)
    if prev == '0':
        l.append(0)

    w = 2 * k + 1

    if len(l) <= w:
        return n

    acc = [0] + list(accumulate(l))
    ans = 0
    for i in range(0, len(l) - w + 1, 2):
        ans = max(ans, acc[i + w] - acc[i])
    return ans


print(solve())
Problem p03078 (python)

Fixed submission:
from heapq import *

Q=[]
teast=[]
X,Y,Z,K=list(map(int,input().split(" ")))

for i in range(3):
    teast.append(list(map(int,input().split(" "))))

A=sorted(teast[0],reverse=True)
B=sorted(teast[1],reverse=True)
C=sorted(teast[2],reverse=True)

arg_hash={}
heappush(Q,(-A[0]-B[0]-C[0],0,0,0))
arg_hash[(0,0,0)]=1

for k in range(K):
    ans=heappop(Q)
    a,b,c=ans[1:]
    print(-ans[0])
    argA=(a+1,b,c)
    if a <X-1 and( not argA in arg_hash):
        arg_hash[argA]=1
        heappush(Q,(-A[a+1]-B[b]-C[c],)+argA)
    argB=(a,b+1,c)
    if b <Y-1 and( not argB in arg_hash):
        arg_hash[argB]=1
        heappush(Q,(-A[a]-B[b+1]-C[c],)+argB)
    argC=(a,b,c+1)
    if c <Z-1 and( not argC in arg_hash):
        arg_hash[argC]=1
        heappush(Q,(-A[a]-B[b]-C[c+1],)+argC)

Buggy submission (verdict: Runtime Error):
N=list(map(int,(input().split(" "))))
teast=[]
K = N[3]
total=[]
c=0
for i in range(3):
    teast.append(list(map(int,input().split(" "))))
A=sorted(teast[0],reverse=True)
B=sorted(teast[1],reverse=True)
C=sorted(teast[2],reverse=True)

for i in range(len(A)):

    for j in range(len(B)):

        for k in range(len(C)):
            if i*j*k>K:
                break
            else:
                total.append(A[i]+B[j]+C[k])

total_s=sorted(total,reverse=True)

for i in range(K):
    print(total_

Buggy submission (verdict: Runtime Error):
N=list(map(int,(input().split(" "))))
teast=[]
K = N[3]
total=[]
for i in range(3):
    teast.append(list(map(int,input().split(" "))))
A=sorted(teast[0],reverse=True)
B=sorted(teast[1],reverse=True)
C=sorted(teast[2],reverse=True)
for i in range(len(A)):

    for j in range(len(B)):

        for k in range(len(C)):
            if a*b*c>K:
                break
            else:
                total.append(A[i]+B[j]+C[k])

total_s=sorted(total,reverse=True)

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