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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

count = 0
candidates = []
heapq.heappush(candidates, (-(A[0] + B[0] + C[0]), 0, 0, 0))
used = set()
while True:
    s, i, j, k = heapq.heappop(candidates)
    s *= -1
    if not (i, j, k) in used:
        print(s)
        count += 1
        if count >= K:
            break
    used.add((i, j, k))
    if i < X - 1:
        heapq.heappush(candidates, (-(A[i+1] + B[j] + C[k]), i+1, j, k))
    if j < Y - 1:
        heapq.heappush(candidates, (-(A[i] + B[j+1] + C[k]), i, j+1, k))
    if k < Z - 1:
        heapq.heappush(candidates, (-(A[i] + B[j] + C[k+1]), i, j, k+1))


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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

candidates = []
heapq.heappush(candidates, (-(A[0] + B[0] + C[0]), 0, 0, 0))
used = {(0, 0, 0)}
for _ in range(K):
    s, i, j, k = heapq.heappop(candidates)
    print(-s)
    if i < X - 1 and (i+1, j, k) not in used:
        heapq.heappush(candidates, (-(A[i+1] + B[j] + C[k]), i+1, j, k))
        used.add((i+1, j, k))
    if j < Y - 1 and (i, j+1, k) not in used:
        heapq.heappush(candidates, (-(A[i] + B[j+1] + C[k]), i, j+1, k))
        used.add((i, j+1, k))
    if k < Z - 1 and (i, j, k+1) not in used:
        heapq.heappush(candidates, (-(A[i] + B[j] + C[k+1]), i, j, k+1))
        used.add((i, j, k+1))

Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)

count = 0
candidates = {(0, 0, 0)}
used = set()
while True:
    max_x, max_y, max_z = (0, 0, 0)
    max_sum = -1
    for x, y, z in candidates:
        s = a_list[x] + b_list[y] + c_list[z]
        if s > max_sum:
            max_x, max_y, max_z = x, y, z
            max_sum = s
    if not (max_x, max_y, max_z) in used:
        print(max_sum)
        count += 1
        if count >= K:
            break
    candidates.remove((max_x, max_y, max_z))
    used.add((max_x, max_y, max_z))
    if max_x < X - 1:
        candidates.add((max_x + 1, max_y, max_z))
    if max_y < Y - 1:
        candidates.add((max_x, max_y + 1, max_z))
    if max_z < Z - 1:
        candidates.add((max_x, max_y, max_z + 1))


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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

candidates = []
heapq.heappush(candidates, (-(A[0] + B[0] + C[0]), 0, 0, 0))
used = {(0, 0, 0)}
for _ in range(K):
    s, i, j, k = heapq.heappop(candidates)
    print(-s)
    if i < X - 1 and (i+1, j, k) not in used:
        heapq.heappush(candidates, (-(A[i+1] + B[j] + C[k]), i+1, j, k))
        used.add((i+1, j, k))
    if j < Y - 1 and (i, j+1, k) not in used:
        heapq.heappush(candidates, (-(A[i] + B[j+1] + C[k]), i, j+1, k))
        used.add((i, j+1, k))
    if k < Z - 1 and (i, j, k+1) not in used:
        heapq.heappush(candidates, (-(A[i] + B[j] + C[k+1]), i, j, k+1))
        used.add((i, j, k+1))

Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)
ans = []
candidates = [(0, 0, 0)]
used = set()
while len(ans) < K:
    max_x, max_y, max_z = candidates[0]
    max_sum = a_list[max_x] + b_list[max_y] + c_list[max_z]
    for x, y, z in candidates:
        s = a_list[x] + b_list[y] + c_list[z]
        if s > max_sum:
            max_x, max_y, max_z = x, y, z
            max_sum = s
    if not (max_x, max_y, max_z) in used:
        ans.append(max_sum)
    candidates.remove((max_x, max_y, max_z))
    used.add((max_x, max_y, max_z))
    if max_x < X - 1:
        candidates.append((max_x + 1, max_y, max_z))
    if max_y < Y - 1:
        candidates.append((max_x, max_y + 1, max_z))
    if max_z < Z - 1:
        candidates.append((max_x, max_y, max_z + 1))
for a in ans:
    print(a)


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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

candidates = []
heapq.heappush(candidates, (-(A[0] + B[0] + C[0]), 0, 0, 0))
used = {(0, 0, 0)}
for _ in range(K):
    s, i, j, k = heapq.heappop(candidates)
    print(-s)
    if i < X - 1 and (i+1, j, k) not in used:
        heapq.heappush(candidates, (-(A[i+1] + B[j] + C[k]), i+1, j, k))
        used.add((i+1, j, k))
    if j < Y - 1 and (i, j+1, k) not in used:
        heapq.heappush(candidates, (-(A[i] + B[j+1] + C[k]), i, j+1, k))
        used.add((i, j+1, k))
    if k < Z - 1 and (i, j, k+1) not in used:
        heapq.heappush(candidates, (-(A[i] + B[j] + C[k+1]), i, j, k+1))
        used.add((i, j, k+1))