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

X,Y,Z,K = map(int,input().split())
A, B, C = [sorted(list(map(int,input().split())),reverse=True) for _ in range(3)]

Q = []
ia,ib,ic = 0,0,0
plus_i = 1
heapq.heappush(Q, [-(A[ia]+B[ib]+C[ic]),ia,ib,ic])

for _ in range(K):
  if ia+plus_i < X and [-(A[ia+plus_i]+B[ib]+C[ic]),ia+plus_i,ib,ic] not in Q:heapq.heappush(Q, [-(A[ia+plus_i]+B[ib]+C[ic]),ia+plus_i,ib,ic])
  if ib+plus_i < Y and [-(A[ia]+B[ib+plus_i]+C[ic]),ia,ib+plus_i,ic] not in Q:heapq.heappush(Q, [-(A[ia]+B[ib+plus_i]+C[ic]),ia,ib+plus_i,ic])
  if ic+plus_i < Z and[-(A[ia]+B[ib]+C[ic+plus_i]),ia,ib,ic+plus_i] not in Q:heapq.heappush(Q, [-(A[ia]+B[ib]+C[ic+plus_i]),ia,ib,ic+plus_i])
  plus_i += 1
    
[print(-heapq.heappop(Q)[0]) for _ in range(K)]

Fixed submission:
import heapq

X,Y,Z,K = map(int,input().split())
A, B, C = [sorted(list(map(int,input().split())),reverse=True) for _ in range(3)]

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

Buggy python submission (verdict: Time Limit Exceeded):
X,Y,Z,K = map(int,input().split())
A, B, C = [sorted(list(map(int,input().split())),reverse=True) for _ in range(3)]
ans_list = []
for i in range(X):
  for j in range(Y):
    for k in range(Z):
      if i*j*k > K: break
      else: ans_list.append(A[i]+B[j]+C[k])
[print(ans) for ans in sorted(ans_list,reverse=True)[:K]]

Fixed submission:
import heapq

X,Y,Z,K = map(int,input().split())
A, B, C = [sorted(list(map(int,input().split())),reverse=True) for _ in range(3)]

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

Buggy python submission (verdict: Time Limit Exceeded):
X,Y,Z,K = map(int,input().split())
A, B, C = list(map(int,input().split())),  list(map(int,input().split())),  list(map(int,input().split()))
AB = sorted([a+b for a in A for b in B],reverse=True)
ABC = sorted([ab+c for ab in AB[:K] for c in sorted(C)[:K]],reverse=True)
[print(abc) for abc in sorted(ABC,reverse=True)[:K]]

Fixed submission:
import heapq

X,Y,Z,K = map(int,input().split())
A, B, C = [sorted(list(map(int,input().split())),reverse=True) for _ in range(3)]

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

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

X,Y,Z,K = map(int,input().split())
A, B, C = [], [], []
[heapq.heappush(A, -a) for a in map(int,input().split())]
[heapq.heappush(B, -b) for b in map(int,input().split())]
[heapq.heappush(C, -c) for c in map(int,input().split())]

max_A = [-heapq.heappop(A) for _ in range(min(K,X))]
max_B = [-heapq.heappop(B) for _ in range(min(K,Y))]
max_C = [-heapq.heappop(C) for _ in range(min(K,Z))]

ans_list = []
for max_a in max_A:
  for max_b in max_B:
    for max_c in max_C:
      heapq.heappush(ans_list, -sum([max_a,max_b,max_c]))
[print(-heapq.heappop(ans_list)) for _ in range(K)]

Fixed submission:
import heapq

X,Y,Z,K = map(int,input().split())
A, B, C = [sorted(list(map(int,input().split())),reverse=True) for _ in range(3)]

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

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

X,Y,Z,K = map(int,input().split())
A, B, C = [], [], []
[heapq.heappush(A, -a) for a in map(int,input().split())]
[heapq.heappush(B, -b) for b in map(int,input().split())]
[heapq.heappush(C, -c) for c in map(int,input().split())]

max_A = [-heapq.heappop(A) for _ in range(X)]
max_B = [-heapq.heappop(B) for _ in range(Y)]
max_C = [-heapq.heappop(C) for _ in range(Z)]

ans_list = []
for max_a in max_A:
  for max_b in max_B:
    for max_c in max_C:
      heapq.heappush(ans_list, -sum([max_a,max_b,max_c]))
[print(-heapq.heappop(ans_list)) for _ in range(K)]

Fixed submission:
import heapq

X,Y,Z,K = map(int,input().split())
A, B, C = [sorted(list(map(int,input().split())),reverse=True) for _ in range(3)]

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