Buggy python submission (verdict: Runtime Error):
X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

import heapq

heap = []
heapq.heappush(heap, (-(A[0]+B[0]+C[0]), 0, 0, 0))
added = set([(0, 0, 0)])

for _ in range(K):
    p, i, j, k = heapq.heappop(heap)
    if (i+1, j, k) not in added and i+1<X:
        heapq.heappush(heap, (-(A[i+1]+B[j]+C[k]), i+1, j, k))
        added.add((i+1, j, k))
    if (i, j+1, k) not in added and j+1<Y:
        heapq.heappush(heap, (-(A[i]+B[j+1]+C[k]), i, k+1, j))
        added.add((i, j+1, k))
    if (i, j, k+1) not in added and k+1<Z:
        heapq.heappush(heap, (-(A[i]+B[j]+C[k+1]), i, j, k+1))
        added.add((i, j, k+1))
    print(-p)

Fixed submission:
import heapq
 
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
 
heap = []
heapq.heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0))
added = set([(0, 0, 0)])
for _ in range(K):
    p, i, j, k = heapq.heappop(heap)
    if (i + 1, j, k) not in added and i + 1 < X:
        heapq.heappush(heap, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))
        added.add((i + 1, j, k))
    if (i, j + 1, k) not in added and j + 1 < Y:
        heapq.heappush(heap, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))
        added.add((i, j + 1, k))
    if (i, j, k + 1) not in added and k + 1 < Z:
        heapq.heappush(heap, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        added.add((i, j, k + 1))
    print(-p)

Buggy python submission (verdict: Runtime Error):
X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

import heapq

heap = []
heapq.heappush(heap, (-(A[0]+B[0]+C[0]), 0, 0, 0))
added = set([(0, 0, 0)])

for _ in range(K):
    p, i, j, k = heapq.heappop(heap)
    if (i+1, j, k) not in added and i+1<X:
        heapq.heappush(heap, -(A[i+1]+B[j]+C[k]), i+1, j, k)
        added.add((i+1, j, k))
    if (i, j+1, k) not in added and j+1<Y:
        heapq.heappush(heap, -(A[i]+B[j+1]+C[k]), i, k+1, j)
        added.add((i, j+1, k))
    if (i, j, k+1) not in added and k+1<Z:
        heapq.heappush(heap, -(A[i]+B[j]+[k]), i, j, k+1)
        added.add((i, j, k+1))
    print(-p)

Fixed submission:
import heapq
 
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
 
heap = []
heapq.heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0))
added = set([(0, 0, 0)])
for _ in range(K):
    p, i, j, k = heapq.heappop(heap)
    if (i + 1, j, k) not in added and i + 1 < X:
        heapq.heappush(heap, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))
        added.add((i + 1, j, k))
    if (i, j + 1, k) not in added and j + 1 < Y:
        heapq.heappush(heap, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))
        added.add((i, j + 1, k))
    if (i, j, k + 1) not in added and k + 1 < Z:
        heapq.heappush(heap, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        added.add((i, j, k + 1))
    print(-p)

Buggy python submission (verdict: Time Limit Exceeded):
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()))

E = []
for i in range(X):
    for j in range(Y):
        E.append(A[i]+B[j])
        
E = sorted(E, reverse=True)[:K]

F = []
for k in range(len(E)):
    for l in range(Z):
        F.append(E[k]+C[l])

F = sorted(F, reverse=True)

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

Fixed submission:
import heapq
 
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
 
heap = []
heapq.heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0))
added = set([(0, 0, 0)])
for _ in range(K):
    p, i, j, k = heapq.heappop(heap)
    if (i + 1, j, k) not in added and i + 1 < X:
        heapq.heappush(heap, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))
        added.add((i + 1, j, k))
    if (i, j + 1, k) not in added and j + 1 < Y:
        heapq.heappush(heap, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))
        added.add((i, j + 1, k))
    if (i, j, k + 1) not in added and k + 1 < Z:
        heapq.heappush(heap, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        added.add((i, j, k + 1))
    print(-p)