Buggy python submission (verdict: Runtime Error):
import collections
import heapq

x, y, z, k = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(3)]
for i in range(3):
    ls[i].sort(reverse=True)
q = [(-sum([ls[i][0] for i in range(3)]), 0, 0, 0)]
res = []
used = collections.defaultdict(lambda: False)
while len(res) < k:
    s, i, j, l = heapq.heappop(q)
    res.append(-s)
    index_list = [
        (i + 1, j, l),
        (i, j + 1, l),
        (i, j, l + 1),
    ]
    for i, (indices, limit) in enumerate(zip(index_list, [x, y, z])):
        if indices[i] < limit and not used[indices]:
            ss = sum([ls[j][l] for j, l in zip(range(3), indices)])
            heapq.heappush(q, (-ss, *indices))
            used[indices] = True
print(*res, sep='\n')

Fixed submission:
import heapq


def select(ls0, ls1, k):
    ls = []
    for a in ls0:
        for b in ls1:
            heapq.heappush(ls, -(a + b))
    return [-heapq.heappop(ls) for _ in range(min(k, len(ls0) * len(ls1)))]


x, y, z, k = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(3)]
for i in range(3):
    ls[i].sort(reverse=True)
ps = select(ls[0], ls[1], k)
res = select(ps, ls[2], k)
print(*res, sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

x, y, z, k = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(3)]
for i in range(3):
    ls[i].sort(reverse=True)
q = [(-sum([ls[i][0] for i in range(3)]), 0, 0, 0)]
res = []
used = [[[False] * z for _ in range(y)] for _ in range(x)]
used[0][0][0] = True
while len(res) < k:
    s, i, j, l = heapq.heappop(q)
    res.append(-s)
    if i + 1 < x:
        if not used[i + 1][j][l]:
            heapq.heappush(
                q, (-(ls[0][i + 1] + ls[1][j] + ls[2][l]), i + 1, j, l))
            used[i + 1][j][l] = True
    if j + 1 < y:
        if not used[i][j + 1][l]:
            heapq.heappush(
                q, (-(ls[0][i] + ls[1][j + 1] + ls[2][l]), i, j + 1, l))
            used[i][j + 1][l] = True
    if l + 1 < z:
        if not used[i][j][l + 1]:
            heapq.heappush(
                q, (-(ls[0][i] + ls[1][j] + ls[2][l + 1]), i, j, l + 1))
            used[i][j][l + 1] = True
print(*res, sep='\n')

Fixed submission:
import heapq


def select(ls0, ls1, k):
    ls = []
    for a in ls0:
        for b in ls1:
            heapq.heappush(ls, -(a + b))
    return [-heapq.heappop(ls) for _ in range(min(k, len(ls0) * len(ls1)))]


x, y, z, k = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(3)]
for i in range(3):
    ls[i].sort(reverse=True)
ps = select(ls[0], ls[1], k)
res = select(ps, ls[2], k)
print(*res, sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
x, y, z, k = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(3)]
ps = sorted([a + b for a in ls[0] for b in ls[1]], reverse=True)[:k]
res = sorted([ab + c for ab in ps for c in ls[2]], reverse=True)[:k]
print(*res, sep='\n')

Fixed submission:
import heapq


def select(ls0, ls1, k):
    ls = []
    for a in ls0:
        for b in ls1:
            heapq.heappush(ls, -(a + b))
    return [-heapq.heappop(ls) for _ in range(min(k, len(ls0) * len(ls1)))]


x, y, z, k = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(3)]
for i in range(3):
    ls[i].sort(reverse=True)
ps = select(ls[0], ls[1], k)
res = select(ps, ls[2], k)
print(*res, sep='\n')