Buggy python submission (verdict: Time Limit Exceeded):
import heapq
X,Y,Z,K=[int(s) for s in input().split()]
x=sorted([-int(s) for s in input().split()])
y=sorted([-int(s) for s in input().split()])
z=sorted([-int(s) for s in input().split()])
count=[[[0 for _ in range(X)]for _ in range(Y)]for _ in range(Z)]
count[0][0][0]=1
Q=[[x[0]+y[0]+z[0],0,0,0]]
heapq.heapify(Q)
X-=1
Y-=1
Z-=1
for i in range(K):
  cake,a,b,c=heapq.heappop(Q)
  print(-cake)
  if a<X and count[a+1][b][c]==0:
    heapq.heappush(Q,[x[a+1]+y[b]+z[c],a+1,b,c])
    count[a+1][b][c]=1
  if b<Y and count[a][b+1][c]==0:
    heapq.heappush(Q,[x[a]+y[b+1]+z[c],a,b+1,c])
    count[a][b+1][c]=1
  if c<Z and count[a][b][c+1]==0:
    heapq.heappush(Q,[x[a]+y[b]+z[c+1],a,b,c+1])
    count[a][b][c+1]=1

Fixed submission:
X,Y,Z,K=[int(s) for s in input().split()]
xls=sorted([int(s) for s in input().split()],reverse=True)
yls=sorted([int(s) for s in input().split()],reverse=True)
zls=sorted([int(s) for s in input().split()],reverse=True)
xyls=[]
for x in xls[:K]:
  for y in yls[:K]:
    xyls.append(x+y)
xyls=sorted(xyls,reverse=True)
cake=[]
for xy in xyls[:K]:
  for z in zls[:K]:
    cake.append(xy+z)
cake=sorted(cake,reverse=True)
for i in range(K):
  print(cake[i])

Buggy python submission (verdict: Runtime Error):
import heapq
X,Y,Z,K=[int(s) for s in input().split()]
x=sorted([-int(s) for s in input().split()])
y=sorted([-int(s) for s in input().split()])
z=sorted([-int(s) for s in input().split()])
count=[[[0 for _ in range(X)]for _ in range(Y)]for _ in range(Z)]
count[0][0][0]=1
Q=[[x[0]+y[0]+z[0],0,0,0]]
heapq.heapify(Q)
for i in range(K):
  cake,a,b,c=heapq.heappop(Q)
  print(-cake)
  if count[a+1][b][c]==0:
    heapq.heappush(Q,[x[a+1]+y[b]+z[c],a+1,b,c])
    count[a+1][b][c]=1
  if count[a][b+1][c]==0:
    heapq.heappush(Q,[x[a]+y[b+1]+z[c],a,b+1,c])
    count[a][b+1][c]=1
  if count[a][b][c+1]==0:
    heapq.heappush(Q,[x[a]+y[b]+z[c+1],a,b,c+1])
    count[a][b][c+1]=1

Fixed submission:
X,Y,Z,K=[int(s) for s in input().split()]
xls=sorted([int(s) for s in input().split()],reverse=True)
yls=sorted([int(s) for s in input().split()],reverse=True)
zls=sorted([int(s) for s in input().split()],reverse=True)
xyls=[]
for x in xls[:K]:
  for y in yls[:K]:
    xyls.append(x+y)
xyls=sorted(xyls,reverse=True)
cake=[]
for xy in xyls[:K]:
  for z in zls[:K]:
    cake.append(xy+z)
cake=sorted(cake,reverse=True)
for i in range(K):
  print(cake[i])

Buggy python submission (verdict: Time Limit Exceeded):
X,Y,Z,K=[int(s) for s in input().split()]
xls=sorted([int(s) for s in input().split()],reverse=True)
yls=sorted([int(s) for s in input().split()],reverse=True)
zls=sorted([int(s) for s in input().split()],reverse=True)
xyls=[]
for x in xls[:K]:
  for y in yls[:K]:
    xyls.append(x+y)
xyls=sorted(xyls,reverse=True)
cake=[]
for xy in xyls[:K]:
  for z in zls[:K]:
    cake.append(xy+z)
cake=sorted(cake,reverse=True)
for i in range(K):
  print(cake[i])

Fixed submission:
X,Y,Z,K=[int(s) for s in input().split()]
xls=sorted([int(s) for s in input().split()],reverse=True)
yls=sorted([int(s) for s in input().split()],reverse=True)
zls=sorted([int(s) for s in input().split()],reverse=True)
xyls=[]
for x in xls[:K]:
  for y in yls[:K]:
    xyls.append(x+y)
xyls=sorted(xyls,reverse=True)
cake=[]
for xy in xyls[:K]:
  for z in zls[:K]:
    cake.append(xy+z)
cake=sorted(cake,reverse=True)
for i in range(K):
  print(cake[i])

Buggy python submission (verdict: Time Limit Exceeded):
X,Y,Z,K=[int(s) for s in input().split()]
xls=[int(s) for s in input().split()]
yls=[int(s) for s in input().split()]
zls=[int(s) for s in input().split()]
xyls=[]
for x in xls:
  for y in yls:
    xyls.append(x+y)
xyls=sorted(xyls,reverse=True)
M=max([X*Y,K])
cake=[]
for xy in xyls[:M]:
  for z in zls:
    cake.append(xy+z)
cake=sorted(cake,reverse=True)
for i in range(K):
  print(cake[i])

Fixed submission:
X,Y,Z,K=[int(s) for s in input().split()]
xls=sorted([int(s) for s in input().split()],reverse=True)
yls=sorted([int(s) for s in input().split()],reverse=True)
zls=sorted([int(s) for s in input().split()],reverse=True)
xyls=[]
for x in xls[:K]:
  for y in yls[:K]:
    xyls.append(x+y)
xyls=sorted(xyls,reverse=True)
cake=[]
for xy in xyls[:K]:
  for z in zls[:K]:
    cake.append(xy+z)
cake=sorted(cake,reverse=True)
for i in range(K):
  print(cake[i])