Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

X, Y, Z, K = list(map(int, input().split()))
A = list(sorted(map(int, input().split()), reverse=True))
B = list(sorted(map(int, input().split()), reverse=True))
C = list(sorted(map(int, input().split()), reverse=True))

heap = []
heapq.heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0))
history = set()
while len(history) < K:
    d, a, b, c = heapq.heappop(heap)
    if a + 1 < X:
        heapq.heappush(heap, (-(A[a + 1] + B[b] + C[c]), a + 1, b, c))
    if b + 1 < Y:
        heapq.heappush(heap, (-(A[a] + B[b + 1] + C[c]), a, b + 1, c))
    if c + 1 < Z:
        heapq.heappush(heap, (-(A[a] + B[b] + C[c + 1]), a, b, c + 1))
    if (a, b, c) not in history:
        history.add((a, b, c))
        print(-d)


Fixed submission:
import heapq

x, y, z, k = map(int, input().split())
ali = list(reversed(sorted(map(int, input().split()))))
bli = list(reversed(sorted(map(int, input().split()))))
cli = list(reversed(sorted(map(int, input().split()))))

done = {}
count = 0

heap = []


def main(a, b, c):
    global count
    if '{}'.format((a, b, c)) in done:
        return
    done['{}'.format((a, b, c))] = True
    count += 1
    print(ali[a] + bli[b] + cli[c])
    if a + 1 < x:
        heapq.heappush(heap, (-(ali[a + 1] + bli[b] + cli[c]), a + 1, b, c))
    if b + 1 < y:
        heapq.heappush(heap, (-(ali[a] + bli[b + 1] + cli[c]), a, b + 1, c))
    if c + 1 < z:
        heapq.heappush(heap, (-(ali[a] + bli[b] + cli[c + 1]), a, b, c + 1))


main(0, 0, 0)
while count < k:
    s, a, b, c = heapq.heappop(heap)
    main(a, b, c)

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

x, y, z, k = map(int, input().split())
ali = list(reversed(sorted(map(int, input().split()))))
bli = list(reversed(sorted(map(int, input().split()))))
cli = list(reversed(sorted(map(int, input().split()))))

done = {}
count = 0

heap = []


def main(a, b, c):
    global count
    if f'{a, b, c}' in done:
        return
    done[f'{a, b, c}'] = True
    count += 1
    print(ali[a] + bli[b] + cli[c])
    if a + 1 < x:
        heapq.heappush(heap, (-(ali[a + 1] + bli[b] + cli[c]), a + 1, b, c))
    if b + 1 < y:
        heapq.heappush(heap, (-(ali[a] + bli[b + 1] + cli[c]), a, b + 1, c))
    if c + 1 < z:
        heapq.heappush(heap, (-(ali[a] + bli[b] + cli[c + 1]), a, b, c + 1))


main(0, 0, 0)
while count < k:
    s, a, b, c = heapq.heappop(heap)
    main(a, b, c)


Fixed submission:
import heapq

x, y, z, k = map(int, input().split())
ali = list(reversed(sorted(map(int, input().split()))))
bli = list(reversed(sorted(map(int, input().split()))))
cli = list(reversed(sorted(map(int, input().split()))))

done = {}
count = 0

heap = []


def main(a, b, c):
    global count
    if '{}'.format((a, b, c)) in done:
        return
    done['{}'.format((a, b, c))] = True
    count += 1
    print(ali[a] + bli[b] + cli[c])
    if a + 1 < x:
        heapq.heappush(heap, (-(ali[a + 1] + bli[b] + cli[c]), a + 1, b, c))
    if b + 1 < y:
        heapq.heappush(heap, (-(ali[a] + bli[b + 1] + cli[c]), a, b + 1, c))
    if c + 1 < z:
        heapq.heappush(heap, (-(ali[a] + bli[b] + cli[c + 1]), a, b, c + 1))


main(0, 0, 0)
while count < k:
    s, a, b, c = heapq.heappop(heap)
    main(a, b, c)