Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

K = int(input().split()[-1])

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_next_iter(i, _list):
    if i < len(_list) - 1:
        return i + 1
    else:
        return i


values = []

ia = ib = ic = 0


def get_value(ia, ib, ic):
    return A[ia] + B[ib] + C[ic]


def get_next(ia, ib, ic):
    ia_n = get_next_iter(ia, A)
    ib_n = get_next_iter(ib, B)
    ic_n = get_next_iter(ic, C)
    s = set()
    s.add((ia_n, ib, ic, get_value(ia_n, ib, ic)))
    s.add((ia, ib_n, ic, get_value(ia, ib_n, ic)))
    s.add((ia, ib, ic_n, get_value(ia, ib, ic_n)))
    return s


values.append((ia, ib, ic, get_value(ia, ib, ic)))
candidate = get_next(0, 0, 0)

for k in range(K - 1):
    vs = sorted(candidate, reverse=True, key=itemgetter(3))
    for i, v in enumerate(vs):
        if v not in values:
            values.append(v)
            candidate.remove(v)
            for each in get_next(v[0], v[1], v[2]):
                candidate.add(each)
            break
        else:
            continue

for each in values:
    print(each[3])


Fixed submission:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_value(ai, bi, ci):
    return -(A[ai] + B[bi] + C[ci])


heap = []
heappush(heap, (get_value(0, 0, 0), 0, 0, 0))
used = {(0, 0, 0)}

for k in range(K):
    v, ia, ib, ic = heappop(heap)
    print(-v)

    if ia + 1 < X and (ia + 1, ib, ic) not in used:
        heappush(heap, (get_value(ia + 1, ib, ic), ia + 1, ib, ic))
        used.add((ia + 1, ib, ic))
    if ib + 1 < Y and (ia, ib + 1, ic) not in used:
        heappush(heap, (get_value(ia, ib + 1, ic), ia, ib + 1, ic))
        used.add((ia, ib + 1, ic))
    if ic + 1 < Z and (ia, ib, ic + 1) not in used:
        heappush(heap, (get_value(ia, ib, ic + 1), ia, ib, ic + 1))
        used.add((ia, ib, ic + 1))

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

K = int(input().split()[-1])

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)

A = A[:min(len(A) + 1, K)]
B = B[:min(len(B) + 1, K)]
C = C[:min(len(C) + 1, K)]

values = []

# prev_a = A[0]
# prev_b = B[0]
# prev_c = C[0]
# value = A[0] + B[0] + C[0]
# print(value)
# ia = 0
# ib = 0
# ic = 0

for a, b, c in itertools.product(A, B, C):
    values.append(a + b + c)
values = sorted(values, reverse=True)

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

#
# for i in range(K - 1):
#     if len(a) > ia + 1:
#
#         if A[ia] - A[ia + 1]:
#
#
#     a = max(A)
#     b = max(B)
#     c = max(C)
#
#     sub_a = prev_a - a
#     sub_b = prev_b - b
#     sub_c = prev_c - c
#
#     if sub_a < sub_b and sub_a < sub_c:
#         A.remove(a)
#     if sub_b < sub_a and sub_b < sub_c:
#         B.remove(b)
#     if sub_c < sub_a and sub_c < sub_b:
#         B.remove(c)
#
#     value -= min(sub_a, sub_b, sub_c)
#     print(value)


Fixed submission:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_value(ai, bi, ci):
    return -(A[ai] + B[bi] + C[ci])


heap = []
heappush(heap, (get_value(0, 0, 0), 0, 0, 0))
used = {(0, 0, 0)}

for k in range(K):
    v, ia, ib, ic = heappop(heap)
    print(-v)

    if ia + 1 < X and (ia + 1, ib, ic) not in used:
        heappush(heap, (get_value(ia + 1, ib, ic), ia + 1, ib, ic))
        used.add((ia + 1, ib, ic))
    if ib + 1 < Y and (ia, ib + 1, ic) not in used:
        heappush(heap, (get_value(ia, ib + 1, ic), ia, ib + 1, ic))
        used.add((ia, ib + 1, ic))
    if ic + 1 < Z and (ia, ib, ic + 1) not in used:
        heappush(heap, (get_value(ia, ib, ic + 1), ia, ib, ic + 1))
        used.add((ia, ib, ic + 1))

Buggy python submission (verdict: Runtime Error):
K = int(input().split()[-1])

A = [int(e) for e in input().split()]
B = [int(e) for e in input().split()]
C = [int(e) for e in input().split()]
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# C = list(map(int, input().split()))


# def get_good(a, v):
#     return max(a)
#     if v is not None:
#         return max(a[a < v])
#     else:
#         max(a)



prev_a = max(A)
prev_b = max(B)
prev_c = max(C)

value = prev_a + prev_b + prev_c

A.remove(max(A))
B.remove(max(B))
C.remove(max(C))

print(value)

for i in range(K - 1):
    a = max(A)
    b = max(B)
    c = max(C)

    sub_a = prev_a - a
    sub_b = prev_b - b
    sub_c = prev_c - c

    if sub_a < sub_b and sub_a < sub_c:
        A.remove(a)
    if sub_b < sub_a and sub_b < sub_c:
        B.remove(b)
    if sub_c < sub_a and sub_c < sub_b:
        B.remove(c)


    value -= min(sub_a, sub_b, sub_c)
    print(value)


Fixed submission:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_value(ai, bi, ci):
    return -(A[ai] + B[bi] + C[ci])


heap = []
heappush(heap, (get_value(0, 0, 0), 0, 0, 0))
used = {(0, 0, 0)}

for k in range(K):
    v, ia, ib, ic = heappop(heap)
    print(-v)

    if ia + 1 < X and (ia + 1, ib, ic) not in used:
        heappush(heap, (get_value(ia + 1, ib, ic), ia + 1, ib, ic))
        used.add((ia + 1, ib, ic))
    if ib + 1 < Y and (ia, ib + 1, ic) not in used:
        heappush(heap, (get_value(ia, ib + 1, ic), ia, ib + 1, ic))
        used.add((ia, ib + 1, ic))
    if ic + 1 < Z and (ia, ib, ic + 1) not in used:
        heappush(heap, (get_value(ia, ib, ic + 1), ia, ib, ic + 1))
        used.add((ia, ib, ic + 1))

Buggy python submission (verdict: Runtime Error):
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()))


# def get_good(a, v):
#     return max(a)
#     if v is not None:
#         return max(a[a < v])
#     else:
#         max(a)



prev_a = max(A)
prev_b = max(B)
prev_c = max(C)

value = prev_a + prev_b + prev_c

A.remove(max(A))
B.remove(max(B))
C.remove(max(C))

print(value)

for i in range(K - 1):
    a = max(A)
    b = max(B)
    c = max(C)

    sub_a = prev_a - a
    sub_b = prev_b - b
    sub_c = prev_c - c

    if sub_a < sub_b and sub_a < sub_c:
        A.remove(a)
    if sub_b < sub_a and sub_b < sub_c:
        B.remove(b)
    if sub_c < sub_a and sub_c < sub_b:
        B.remove(c)


    value -= min(sub_a, sub_b, sub_c)
    print(value)


Fixed submission:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_value(ai, bi, ci):
    return -(A[ai] + B[bi] + C[ci])


heap = []
heappush(heap, (get_value(0, 0, 0), 0, 0, 0))
used = {(0, 0, 0)}

for k in range(K):
    v, ia, ib, ic = heappop(heap)
    print(-v)

    if ia + 1 < X and (ia + 1, ib, ic) not in used:
        heappush(heap, (get_value(ia + 1, ib, ic), ia + 1, ib, ic))
        used.add((ia + 1, ib, ic))
    if ib + 1 < Y and (ia, ib + 1, ic) not in used:
        heappush(heap, (get_value(ia, ib + 1, ic), ia, ib + 1, ic))
        used.add((ia, ib + 1, ic))
    if ic + 1 < Z and (ia, ib, ic + 1) not in used:
        heappush(heap, (get_value(ia, ib, ic + 1), ia, ib, ic + 1))
        used.add((ia, ib, ic + 1))

Buggy python submission (verdict: Runtime Error):
X, Y, Z, K = map(int, input().split())

A = map(int, input().split())
B = map(int, input().split())
C = map(int, input().split())


def get_good(a, v):
    if v is not None:
        return max(a[a < v])
    else:
        max(a)


value = 0
a = b = c = None
for i in range(K):
    print(get_good(A, a) + get_good(B, b), get_good(C, c))
    a = get_good(a)
    b = get_good(b)
    c = get_good(c)


Fixed submission:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_value(ai, bi, ci):
    return -(A[ai] + B[bi] + C[ci])


heap = []
heappush(heap, (get_value(0, 0, 0), 0, 0, 0))
used = {(0, 0, 0)}

for k in range(K):
    v, ia, ib, ic = heappop(heap)
    print(-v)

    if ia + 1 < X and (ia + 1, ib, ic) not in used:
        heappush(heap, (get_value(ia + 1, ib, ic), ia + 1, ib, ic))
        used.add((ia + 1, ib, ic))
    if ib + 1 < Y and (ia, ib + 1, ic) not in used:
        heappush(heap, (get_value(ia, ib + 1, ic), ia, ib + 1, ic))
        used.add((ia, ib + 1, ic))
    if ic + 1 < Z and (ia, ib, ic + 1) not in used:
        heappush(heap, (get_value(ia, ib, ic + 1), ia, ib, ic + 1))
        used.add((ia, ib, ic + 1))

Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys

X, Y, Z, K = map(int, input().split())

A = map(int, input().split())
B = map(int, input().split())
C = map(int, input().split())

def get_good(a, v):
    if v is not None:
        return max(a[a < v])
    else:
        max(a)

value = 0
a = b = c = None
for i in range(K):
    print(get_good(A, a) + get_good(B, b), get_good(C, c))
    a = get_good(a)
    b = get_good(b)
    c = get_good(c)


Fixed submission:
from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())

A = sorted([int(e) for e in input().split()], reverse=True)
B = sorted([int(e) for e in input().split()], reverse=True)
C = sorted([int(e) for e in input().split()], reverse=True)


def get_value(ai, bi, ci):
    return -(A[ai] + B[bi] + C[ci])


heap = []
heappush(heap, (get_value(0, 0, 0), 0, 0, 0))
used = {(0, 0, 0)}

for k in range(K):
    v, ia, ib, ic = heappop(heap)
    print(-v)

    if ia + 1 < X and (ia + 1, ib, ic) not in used:
        heappush(heap, (get_value(ia + 1, ib, ic), ia + 1, ib, ic))
        used.add((ia + 1, ib, ic))
    if ib + 1 < Y and (ia, ib + 1, ic) not in used:
        heappush(heap, (get_value(ia, ib + 1, ic), ia, ib + 1, ic))
        used.add((ia, ib + 1, ic))
    if ic + 1 < Z and (ia, ib, ic + 1) not in used:
        heappush(heap, (get_value(ia, ib, ic + 1), ia, ib, ic + 1))
        used.add((ia, ib, ic + 1))