Buggy python submission (verdict: Time Limit Exceeded):
def d_cake_123_binary_search(X, Y, Z, K, A, B, C):
    # editionalの解法4 O(K^2log(max(P))
    # 参考: https://atcoder.jp/contests/abc123/submissions/4871511
    import bisect
    ab = sorted([e1 + e2 for e2 in B for e1 in A])  # A, Bの要素は全部調べる
 
    # rejected 以上の値は、美味しさの合計がそれ以上である個数がK個未満である
    accepted, rejected = -1, 10**11
    while abs(accepted - rejected) > 1:
        mid = (accepted + rejected) // 2
        count = sum([len(ab) - bisect.bisect_left(ab, mid - e) for e in C])
        if count >= K:
            accepted = mid
        else:
            rejected = mid
 
    ans = []
    for e in C:
        idx = bisect.bisect_left(ab, accepted - e)
        for i in range(idx, len(ab)):
            ans.append(e + ab[i])
    ans.sort(reverse=True)
    return '\n'.join(map(str, ans[:K]))
 
X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(d_cake_123_binary_search(X, Y, Z, K, A, B, C))

Fixed submission:
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = sorted([int(i) for i in A.split()],reverse=True)[:K]
B = sorted([int(i) for i in B.split()],reverse=True)[:K]
C = sorted([int(i) for i in C.split()],reverse=True)[:K]

ABC = []
for i in range(X):
    if (i + 1) > K:
        break
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for l in range(Z):
            if (i + 1) * (j + 1) * (l + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[l])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Buggy python submission (verdict: Runtime Error):
X, Y, Z, K = [int(i) for i in input().split()]
A = sorted([int(i) for i in input().split()],reverse=True)
B = sorted([int(i) for i in input().split()],reverse=True)
C = sorted([int(i) for i in input().split()],reverse=True)
def set_tuple(A,B,C,x,y,z):
    return (-(A[x]+B[y]+C[z]),x,y,z)
Q = []
heapq.heappush(Q,set_tuple(A,B,C,0,0,0))
Ans = []
memo = {(0,0,0):True}
for _ in range(K):
    e,x,y,z = heapq.heappop(Q)
    Ans.append(-e)
    if x+1 < X and (x+1,y,z) not in memo:
        heapq.heappush(Q,set_tuple(A,B,C,x+1,y,z))
        memo[(x+1,y,z)] = True
    if y+1 < Y and (x,y+1,z) not in memo:
        heapq.heappush(Q,set_tuple(A,B,C,x,y+1,z))
        memo[(x,y+1,z)] = True
    if z+1 < Z and (x,y,z+1) not in memo:
        heapq.heappush(Q,set_tuple(A,B,C,x,y,z+1))
        memo[(x,y,z+1)] = True
for i in Ans[:K]:print(i)

Fixed submission:
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = sorted([int(i) for i in A.split()],reverse=True)[:K]
B = sorted([int(i) for i in B.split()],reverse=True)[:K]
C = sorted([int(i) for i in C.split()],reverse=True)[:K]

ABC = []
for i in range(X):
    if (i + 1) > K:
        break
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for l in range(Z):
            if (i + 1) * (j + 1) * (l + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[l])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Buggy python submission (verdict: Runtime Error):
X, Y, Z, K = [int(i) for i in input().split()]
A = sorted([int(i) for i in input().split()],reverse=True)
B = sorted([int(i) for i in input().split()],reverse=True)
C = sorted([int(i) for i in input().split()],reverse=True)
def set_tuple(A,B,C,x,y,z):
    return (-(A[x]+B[y]+C[z]),x,y,z)
Q = []
heapq.heappush(Q,set_tuple(A,B,C,0,0,0))
Ans = []
memo = {(0,0,0):True}
for _ in range(K):
    e,x,y,z = heapq.heappop(Q)
    Ans.append(-e)
    if x+1 < X and (x+1,y,z) not in memo:
        heapq.heappush(Q,set_tuple(A,B,C,x+1,y,z))
        memo[(x+1,y,z)] = True
    if y+1 < Y and (x,y+1,z) not in memo:
        heapq.heappush(Q,set_tuple(A,B,C,x,y+1,z))
        memo[(x,y+1,z)] = True
    if z+1 < Z and (x,y,z+1) not in memo:
        heapq.heappush(Q,set_tuple(A,B,C,x,y,z+1))
        memo[(x,y,z+1)] = True
for i in Ans[:K]:print(i)

Fixed submission:
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = sorted([int(i) for i in A.split()],reverse=True)[:K]
B = sorted([int(i) for i in B.split()],reverse=True)[:K]
C = sorted([int(i) for i in C.split()],reverse=True)[:K]

ABC = []
for i in range(X):
    if (i + 1) > K:
        break
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for l in range(Z):
            if (i + 1) * (j + 1) * (l + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[l])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Buggy python submission (verdict: Time Limit Exceeded):
[X,Y,Z,K] = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ABC = []
for ia,a in enumerate(A):
    for ib,b in enumerate(B):
        for ic,c in enumerate(C):
            if ia*ib*ic <= K:
                ABC.append(a+b+c)
ABC.sort(reverse=True)
ABC = ABC[:K]
for i in ABC:print(i)

Fixed submission:
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = sorted([int(i) for i in A.split()],reverse=True)[:K]
B = sorted([int(i) for i in B.split()],reverse=True)[:K]
C = sorted([int(i) for i in C.split()],reverse=True)[:K]

ABC = []
for i in range(X):
    if (i + 1) > K:
        break
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for l in range(Z):
            if (i + 1) * (j + 1) * (l + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[l])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Buggy python submission (verdict: Time Limit Exceeded):
[X,Y,Z,K] = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
AB = []
for a in A:
    for b in B:
        AB.append(a+b)
AB.sort(reverse=True)
ABC = []
for ab in AB[:K]:
    for c in C:
        ABC.append(ab+c)
ABC.sort(reverse=True)
for i in ABC[:K]:print(i)

Fixed submission:
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = sorted([int(i) for i in A.split()],reverse=True)[:K]
B = sorted([int(i) for i in B.split()],reverse=True)[:K]
C = sorted([int(i) for i in C.split()],reverse=True)[:K]

ABC = []
for i in range(X):
    if (i + 1) > K:
        break
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for l in range(Z):
            if (i + 1) * (j + 1) * (l + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[l])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Buggy python submission (verdict: Time Limit Exceeded):
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = sorted([int(i) for i in A.split()],reverse=True)
B = sorted([int(i) for i in B.split()],reverse=True)
C = sorted([int(i) for i in C.split()],reverse=True)
A = A[:K]
B = B[:K]
C = C[:K]
Ans = [0 for i in range(K)]
for a in A:
    for b in B:
        for c in C:
            abc = a+b+c
            if min(Ans) < a + b + c:
                Ans[Ans.index(min(Ans))] = a+b+c
Ans = sorted(Ans,reverse=True)
for i in range(len(Ans)):
    print(Ans[i])

Fixed submission:
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = sorted([int(i) for i in A.split()],reverse=True)[:K]
B = sorted([int(i) for i in B.split()],reverse=True)[:K]
C = sorted([int(i) for i in C.split()],reverse=True)[:K]

ABC = []
for i in range(X):
    if (i + 1) > K:
        break
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for l in range(Z):
            if (i + 1) * (j + 1) * (l + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[l])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Buggy python submission (verdict: Time Limit Exceeded):
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = [int(i) for i in A.split()]
B = [int(i) for i in B.split()]
C = [int(i) for i in C.split()]
Ans = [0 for i in range(K)]
for a in A:
    for b in B:
        for c in C:
            abc = a+b+c
            if min(Ans) < a + b + c:
                Ans[Ans.index(min(Ans))] = a+b+c
Ans = sorted(Ans,reverse=True)
for i in range(len(Ans)):
    print(Ans[i])

Fixed submission:
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = sorted([int(i) for i in A.split()],reverse=True)[:K]
B = sorted([int(i) for i in B.split()],reverse=True)[:K]
C = sorted([int(i) for i in C.split()],reverse=True)[:K]

ABC = []
for i in range(X):
    if (i + 1) > K:
        break
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for l in range(Z):
            if (i + 1) * (j + 1) * (l + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[l])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Buggy python submission (verdict: Runtime Error):
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = [int(i) for i in A.split()]
B = [int(i) for i in B.split()]
C = [int(i) for i in C.split()]
Ans = [0 for i in range(K)]
for a in A:
    for b in B:
        for c in C:
            abc = a+b+c
            if min(Ans) < a + b + c:
                Ans[Ans.index(min(Ans))] = a+b+c
Ans = sorted(Ans,reverse=True)
for i in range(Ans):
    print(Ans[i])

Fixed submission:
[XYZK,A,B,C] = [input() for i in range(4)]
[X,Y,Z,K] = [int(i) for i in XYZK.split()]
A = sorted([int(i) for i in A.split()],reverse=True)[:K]
B = sorted([int(i) for i in B.split()],reverse=True)[:K]
C = sorted([int(i) for i in C.split()],reverse=True)[:K]

ABC = []
for i in range(X):
    if (i + 1) > K:
        break
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for l in range(Z):
            if (i + 1) * (j + 1) * (l + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[l])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])