Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappush, heappop, heapreplace
from collections import deque
import sys
input = sys.stdin.readline
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)
D = deque([(0,0,0)])
F = set()
H = [0]
heapify(H)
k = 1
while D:
    p = D.popleft()
    if p in F:
        continue
    F.add(p)
    x, y, z = p
    d = A[x] + B[y] + C[z]
    if k < K:
        heappush(H, d)
        k += 1
    elif H[0] > d:
        continue
    else:
        heapreplace(H, d)
    if x < X - 1: D.append((x + 1, y, z))
    if y < Y - 1: D.append((x, y + 1, z))
    if z < Z - 1: D.append((x, y, z + 1))

print(*sorted(H, reverse=True), sep="\n")

Fixed submission:
from heapq import heapify, heappush, heappop, heapreplace
import sys
input = sys.stdin.readline
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)
D = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
heapify(D)
F = set()
for _ in range(K):
    p = heappop(D)
    d, x, y, z = p
    print(-d)
    if x < X - 1:
        p = (-(A[x + 1] + B[y] + C[z]), x + 1, y, z)
        if p not in F:
            heappush(D, p)
            F.add(p)
    if y < Y - 1:
        p = (-(A[x] + B[y + 1] + C[z]), x, y + 1, z)
        if p not in F:
            heappush(D, p)
            F.add(p)
    if z < Z - 1:
        p = (-(A[x] + B[y] + C[z + 1]), x, y, z + 1)
        if p not in F:
            heappush(D, p)
            F.add(p)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappush, heappop, heapreplace
from collections import deque
import sys
input = sys.stdin.readline
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)
D = deque([(0,0,0)])
F = set()
H = [0]
heapify(H)
k = 1
while D:
    p = D.popleft()
    if p in F:
        continue
    F.add(p)
    x, y, z = p
    d = A[x] + B[y] + C[z]
    if k < K:
        heappush(H, d)
        k += 1
    elif H[0] > d:
        continue
    else:
        heapreplace(H, d)
    if x < X - 1: D.append((x + 1, y, z))
    if y < Y - 1: D.append((x, y + 1, z))
    if z < Z - 1: D.append((x, y, z + 1))

print(*sorted(H, reverse=True), sep="\n")

Fixed submission:
from heapq import heapify, heappush, heappop, heapreplace
import sys
input = sys.stdin.readline
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)
D = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
heapify(D)
F = set()
for _ in range(K):
    p = heappop(D)
    d, x, y, z = p
    print(-d)
    if x < X - 1:
        p = (-(A[x + 1] + B[y] + C[z]), x + 1, y, z)
        if p not in F:
            heappush(D, p)
            F.add(p)
    if y < Y - 1:
        p = (-(A[x] + B[y + 1] + C[z]), x, y + 1, z)
        if p not in F:
            heappush(D, p)
            F.add(p)
    if z < Z - 1:
        p = (-(A[x] + B[y] + C[z + 1]), x, y, z + 1)
        if p not in F:
            heappush(D, p)
            F.add(p)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappush, heappop, heapreplace
from collections import deque
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)
D = deque([(0,0,0)])
F = set()
H = [0]
heapify(H)
k = 1
while D:
    p = D.popleft()
    if p in F:
        continue
    F.add(p)
    x, y, z = p
    d = A[x] + B[y] + C[z]
    if k < K:
        heappush(H, d)
        k += 1
    elif H[0] > d:
        continue
    else:
        heapreplace(H, d)
    if x < X - 1: D.append((x + 1, y, z))
    if y < Y - 1: D.append((x, y + 1, z))
    if z < Z - 1: D.append((x, y, z + 1))

print(*sorted(H, reverse=True), sep="\n")

Fixed submission:
from heapq import heapify, heappush, heappop, heapreplace
import sys
input = sys.stdin.readline
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)
D = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
heapify(D)
F = set()
for _ in range(K):
    p = heappop(D)
    d, x, y, z = p
    print(-d)
    if x < X - 1:
        p = (-(A[x + 1] + B[y] + C[z]), x + 1, y, z)
        if p not in F:
            heappush(D, p)
            F.add(p)
    if y < Y - 1:
        p = (-(A[x] + B[y + 1] + C[z]), x, y + 1, z)
        if p not in F:
            heappush(D, p)
            F.add(p)
    if z < Z - 1:
        p = (-(A[x] + B[y] + C[z + 1]), x, y, z + 1)
        if p not in F:
            heappush(D, p)
            F.add(p)