AtCoder Beginner Contest 123 - Cake 123

The Patisserie AtCoder sells cakes with number-shaped candles.
There are X, Y and Z kinds of cakes with 1-shaped, 2-shaped and 3-shaped candles, respectively.
Each cake has an integer value called deliciousness, as follows:
 - The deliciousness of the cakes with 1-shaped candles are A_1, A_2, ..., A_X.
 - The deliciousness of the cakes with 2-shaped candles are B_1, B_2, ..., B_Y.
 - The deliciousness of the cakes with 3-shaped candles are C_1, C_2, ..., C_Z.
Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.

There are X \times Y \times Z such ways to choose three cakes.

We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes.

Print the sums of the deliciousness of the cakes for the first, second, ..., K-th ways in this list.

-----Constraints-----
 - 1 \leq X \leq 1 \ 000
 - 1 \leq Y \leq 1 \ 000
 - 1 \leq Z \leq 1 \ 000
 - 1 \leq K \leq \min(3 \ 000, X \times Y \times Z)
 - 1 \leq A_i \leq 10 \ 000 \ 000 \ 000
 - 1 \leq B_i \leq 10 \ 000 \ 000 \ 000
 - 1 \leq C_i \leq 10 \ 000 \ 000 \ 000
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
X Y Z K
A_1 \ A_2 \ A_3 \ ... \ A_X
B_1 \ B_2 \ B_3 \ ... \ B_Y
C_1 \ C_2 \ C_3 \ ... \ C_Z

-----Output-----
Print K lines. The i-th line should contain the i-th value stated in the problem statement.

-----Sample Input-----
2 2 2 8
4 6
1 5
3 8

-----Sample Output-----
19
17
15
14
13
12
10
8

There are 2 \times 2 \times 2 = 8 ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:
 - (A_2, B_2, C_2): 6 + 5 + 8 = 19
 - (A_1, B_2, C_2): 4 + 5 + 8 = 17
 - (A_2, B_1, C_2): 6 + 1 + 8 = 15
 - (A_2, B_2, C_1): 6 + 5 + 3 = 14
 - (A_1, B_1, C_2): 4 + 1 + 8 = 13
 - (A_1, B_2, C_1): 4 + 5 + 3 = 12
 - (A_2, B_1, C_1): 6 + 1 + 3 = 10
 - (A_1, B_1, C_1): 4 + 1 + 3 = 8

Source: atcoder | Difficulty: MEDIUM


Solutions:
(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()))
ab = []
for i in a:
	for j in b:
		ab.append(i + j)
ab.sort(reverse=True)
ab = ab[:k]
abc = []
for i in ab:
	for j in c:
		abc.append(i + j)
abc.sort(reverse=True)
for i in range(k):
	print(abc[i])


(X, Y, Z, K) = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
l = []
for a in A:
	for b in B:
		l.append(a + b)
l = sorted(l, reverse=True)[:K]
ans = []
for c in C:
	for k in l:
		ans.append(c + k)
ans = sorted(ans, reverse=True)
print(*ans[:K], sep='\n')


(X, Y, Z, K) = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))[::-1]
A_B = []
for a in A:
	for b in B:
		A_B.append(a + b)
A_B = sorted(A_B)[::-1][:K]
ans = []
for a_b in A_B:
	for c in C:
		ans.append(a_b + c)
for a in sorted(ans)[::-1][:K]:
	print(a)


(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()))
a.sort(reverse=1)
b.sort(reverse=1)
c.sort(reverse=1)
m = []
for i in range(x):
	for j in range(y):
		for k in range(z):
			if (i + 1) * (j + 1) * (k + 1) > K:
				break
			m.append(a[i] + b[j] + c[k])
m.sort(reverse=1)
for i in m[:K]:
	print(i)


import itertools
(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()))
AB = [a + b for (a, b) in itertools.product(A, B)]
AB.sort(reverse=True)
AB = AB[:K]
ABC = [ab + c for (ab, c) in itertools.product(AB, C)]
ABC.sort(reverse=True)
for i in range(K):
	print(ABC[i])


(x, y, z, k) = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
B = sorted(map(int, input().split()), reverse=True)
C = sorted(map(int, input().split()), reverse=True)
AB = sorted([a + b for a in A for b in B], reverse=True)
ans = sorted([ab + c for ab in AB[:k] for c in C], reverse=True)
for i in ans[:k]:
	print(i)


(x, y, z, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))[::-1]
a1 = sorted((a[i] + b[j] for i in range(x) for j in range(y)))[::-1]
a2 = sorted((a1[i] + c[j] for i in range(min(len(a1), k)) for j in range(z)))[::-1]
for i in range(k):
	print(a2[i])


(X, Y, Z, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
cakeList = []
for i in range(1, X + 1):
	for j in range(1, Y + 1):
		for k in range(1, Z + 1):
			if i * j * k <= K:
				cakeList.append(A[i - 1] + B[j - 1] + C[k - 1])
			else:
				break
cakeList.sort(reverse=True)
for i in range(K):
	print(cakeList[i])


(X, Y, Z, K) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AB = []
for a in A:
	for b in B:
		AB.append(a + b)
AB.sort(reverse=True)
AB = AB[0:K]
C = list(map(int, input().split()))
ABC = []
for ab in AB:
	for c in C:
		ABC.append(ab + c)
ABC.sort(reverse=True)
for i in range(K):
	print(ABC[i])


(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()))
lis = []
for i in a:
	for j in b:
		lis.append(i + j)
lis.sort(reverse=True)
ab = lis[:k]
kouho = []
for sm in ab:
	for tmp in c:
		kouho.append(sm + tmp)
kouho.sort(reverse=True)
kouho = kouho[:k]
for ans in kouho:
	print(ans)


from heapq import nlargest
(x, y, z, k) = map(int, input().split())
(A, B, C) = [list(map(int, input().split())) for _ in [0] * 3]
D = nlargest(k, (a + b for a in A for b in B))
E = nlargest(k, (d + c for c in C for d in D))
for i in E:
	print(i)


import sys
input = sys.stdin.readline
(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()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
l1 = sorted([i + j for i in a for j in b], reverse=True)[:k]
l2 = sorted([i + j for i in l1 for j in c], reverse=True)[:k]
for i in l2:
	print(i)


(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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ABC = []
for x in range(X):
	for y in range(Y):
		for z in range(Z):
			if (x + 1) * (y + 1) * (z + 1) <= K:
				ABC.append(A[x] + B[y] + C[z])
			else:
				break
ABC.sort(reverse=True)
for i in range(K):
	print(ABC[i])


(x, y, z, k) = list(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)
ans = []
for i in range(x):
	for j in range(y):
		for l in range(z):
			if (i + 1) * (j + 1) * (l + 1) <= k:
				ans.append(a[i] + b[j] + c[l])
			else:
				break
ans.sort(reverse=True)
for i in range(k):
	print(ans[i])


import sys
input = sys.stdin.readline
(X, Y, Z, K) = map(int, input().split())
a = map(int, input().split())
b = list(map(int, input().split()))
c = map(int, input().split())
d = (aa + bb for aa in a for bb in b)
d = sorted(d, reverse=True)[:K]
e = (cc + dd for cc in c for dd in d)
e = sorted(e, reverse=True)[:K]
print('\n'.join(map(str, e)))


(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()))
ab = []
for a in A:
	for b in B:
		ab += [a + b]
ab3000 = sorted(ab)[::-1][:3000]
abc = []
for ab in ab3000:
	for c in C:
		abc += [ab + c]
abc.sort(reverse=True)
for k in range(K):
	print(abc[k])


from heapq import nlargest
(x, y, z, k) = map(int, input().split())
(A, B, C) = [list(map(int, input().split())) for _ in [0] * 3]
AB = nlargest(k, [a + b for a in A for b in B])
ABC = nlargest(k, [ab + c for ab in AB for c in C])
print('\n'.join(map(str, ABC)))


from heapq import heappop, heappush
(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)
l = []
for a in A:
	for b in B:
		l.append(-a - b)
l.sort()
l = l[:K] if len(l) >= K else l + [0] * (K - len(l))
ans = []
for c in C:
	for i in l:
		heappush(ans, i - c)
for i in range(K):
	print(-heappop(ans))


(X, Y, Z, K) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()), reverse=True)
AB = []
for a in A:
	for b in B:
		AB.append(a + b)
AB.sort(reverse=True)
ans = []
for ab in AB[:K]:
	for c in C:
		ans.append(ab + c)
ans.sort(reverse=True)
print(*ans[:K], sep='\n')


import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
(X, Y, Z, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
(i, j, k) = (0, 0, 0)
heap = [(-A[i] - B[j] - C[k], i, j, k)]
heapq.heapify(heap)
used_set = set([(i, j, k)])
for _ in range(K):
	(oisi, i, j, k) = heapq.heappop(heap)
	print(-oisi)
	if (i + 1, j, k) in used_set:
		pass
	elif i + 1 < len(A):
		used_set.add((i + 1, j, k))
		heapq.heappush(heap, (-A[i + 1] - B[j] - C[k], i + 1, j, k))
	if (i, j + 1, k) in used_set:
		pass
	elif j + 1 < len(B):
		used_set.add((i, j + 1, k))
		heapq.heappush(heap, (-A[i] - B[j + 1] - C[k], i, j + 1, k))
	if (i, j, k + 1) in used_set:
		pass
	elif k + 1 < len(C):
		used_set.add((i, j, k + 1))
		heapq.heappush(heap, (-A[i] - B[j] - C[k + 1], i, j, k + 1))


from heapq import heappop, heappush
(X, Y, Z, K) = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)
hq = []
arg_hash = {}
val = -(a_list[0] + b_list[0] + c_list[0])
heappush(hq, (val, 0, 0, 0))
ans_arr = []
for i in range(K):
	(ans_val, p, q, r) = heappop(hq)
	ans_arr.append(-ans_val)
	arg_a = (p + 1, q, r)
	arg_b = (p, q + 1, r)
	arg_c = (p, q, r + 1)
	if p < X - 1 and arg_a not in arg_hash:
		arg_hash[arg_a] = 1
		heappush(hq, (-(a_list[p + 1] + b_list[q] + c_list[r]),) + arg_a)
	if q < Y - 1 and arg_b not in arg_hash:
		arg_hash[arg_b] = 1
		heappush(hq, (-(a_list[p] + b_list[q + 1] + c_list[r]),) + arg_b)
	if r < Z - 1 and arg_c not in arg_hash:
		arg_hash[arg_c] = 1
		heappush(hq, (-(a_list[p] + b_list[q] + c_list[r + 1]),) + arg_c)
for i in range(len(ans_arr)):
	print(ans_arr[i])


import numpy as np

def main():
	(X, Y, Z, K) = list(map(int, input().split(' ')))
	A = np.array(list(map(int, input().split(' '))))
	B = np.array(list(map(int, input().split(' '))))
	C = np.array(list(map(int, input().split(' '))))
	AB = np.array(np.meshgrid(A, B)).T.reshape(-1, 2).sum(axis=1)
	AB[::-1].sort()
	AB = AB[:min([K, X * Y])]
	ABC = np.array(np.meshgrid(AB, C)).T.reshape(-1, 2).sum(axis=1)
	ABC[::-1].sort()
	for ans in ABC[:K]:
		print(ans)

def __starting_point():
	main()
__starting_point()


(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()))
ab = []
for aa in a:
	for bb in b:
		ab.append(aa + bb)
ab.sort(reverse=True)
abk = ab[:k]
ans = []
for item in abk:
	for cc in c:
		ans.append(item + cc)
ans.sort(reverse=True)
for item in ans[:k]:
	print(item)


import heapq
(X, Y, Z, K) = list(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)
checked = {(0, 0, 0)}
h = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]

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


import heapq

def submit():
	(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()))
	a.sort(reverse=True)
	b.sort(reverse=True)
	c.sort(reverse=True)

	def get(i, j, k):
		return (a[i] + b[j] + c[k], (i, j, k))
	check = set()
	check.add((0, 0, 0))
	ans = [get(0, 0, 0)]
	q = []
	for _ in range(k - 1):
		(prev, (i, j, k)) = ans[-1]
		if i < x - 1:
			new_triple = (i + 1, j, k)
			if new_triple not in check:
				check.add(new_triple)
				(s, _) = get(*new_triple)
				heapq.heappush(q, (-s, new_triple))
		if j < y - 1:
			new_triple = (i, j + 1, k)
			if new_triple not in check:
				check.add(new_triple)
				(s, _) = get(*new_triple)
				heapq.heappush(q, (-s, new_triple))
		if k < z - 1:
			new_triple = (i, j, k + 1)
			if new_triple not in check:
				check.add(new_triple)
				(s, _) = get(*new_triple)
				heapq.heappush(q, (-s, new_triple))
		(next_s, next_triple) = heapq.heappop(q)
		ans.append((-next_s, next_triple))
	for (s, _) in ans:
		print(s)
submit()


(x, y, z, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
d = [e1 + e2 for e1 in a for e2 in b]
d.sort(reverse=True)
d = d[:k]
e = [e1 + e2 for e1 in d for e2 in c]
e.sort(reverse=True)
for i in range(k):
	print(e[i])


from heapq import heappush, heapify, heappop

def main():
	(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()))
	A.sort(reverse=True)
	B.sort(reverse=True)
	C.sort(reverse=True)
	que = []
	heapify(que)
	heappush(que, (-A[0] - B[0] - C[0], 0, 0, 0))
	s = set()
	for i in range(K):
		ans = heappop(que)
		print(-ans[0])
		if ans[1] < X - 1 and (not (ans[1] + 1, ans[2], ans[3]) in s):
			heappush(que, [-A[ans[1] + 1] - B[ans[2]] - C[ans[3]], ans[1] + 1, ans[2], ans[3]])
			s.add((ans[1] + 1, ans[2], ans[3]))
		if ans[2] < Y - 1 and (not (ans[1], ans[2] + 1, ans[3]) in s):
			heappush(que, [-A[ans[1]] - B[ans[2] + 1] - C[ans[3]], ans[1], ans[2] + 1, ans[3]])
			s.add((ans[1], ans[2] + 1, ans[3]))
		if ans[3] < Z - 1 and (not (ans[1], ans[2], ans[3] + 1) in s):
			heappush(que, [-A[ans[1]] - B[ans[2]] - C[ans[3] + 1], ans[1], ans[2], ans[3] + 1])
			s.add((ans[1], ans[2], ans[3] + 1))
main()


(x, y, z, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
a_max = min(k, len(a))
b_max = min(k, len(b))
c_max = min(k, len(c))
abc = []
for i in range(1, k + 1):
	if i > len(a):
		break
	for j in range(1, k // i + 1):
		if j > len(b):
			break
		for l in range(1, k // (i * j) + 1):
			if l > len(c):
				break
			abc.append(a[i - 1] + b[j - 1] + c[l - 1])
abc.sort(reverse=True)
for i in range(k):
	print(abc[i])


(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()))
xy = []
for aa in a:
	for bb in b:
		xy.append(aa + bb)
xy.sort(reverse=True)
t = []
for d in xy[:k]:
	for cc in c:
		t.append(d + cc)
t.sort(reverse=True)
for tt in t[:k]:
	print(tt)


from itertools import product
(X, Y, Z, K) = map(int, input().split())
AB = []
for ab in product(map(int, input().split()), map(int, input().split())):
	AB.append(ab[0] + ab[1])
AB.sort(reverse=True)
AB = AB[:K]
ABC = []
for abc in product(AB, map(int, input().split())):
	ABC.append(abc[0] + abc[1])
ABC.sort(reverse=True)
for i in range(K):
	print(ABC[i])


(X, Y, Z, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ans = []
for i in range(min(X, K)):
	D = int(K / (i + 1)) + 1
	for j in range(min(D, Y, K)):
		E = int(D / (j + 1)) + 1
		for k in range(min(E, Z, K)):
			ans.append(A[i] + B[j] + C[k])
ans.sort(reverse=True)
for i in range(K):
	print(ans[i])


I = lambda : map(int, input().split())
(*_, k) = I()
s = lambda *a: sorted((i + j for i in I() for j in a))[:-k - 1:-1]
print(*s(*s(*I())))


import itertools
(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()))
AB = [a + b for (a, b) in list(itertools.product(A, B))]
AB.sort(reverse=True)
ans = [ab + c for (ab, c) in list(itertools.product(AB[:min(3000, x * y * z)], C))]
ans.sort(reverse=True)
for i in range(k):
	print(ans[i])


(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()))
ab = sorted([s + t for s in a for t in b])[-1:-k - 1:-1]
abc = sorted([s + t for s in ab for t in c])[-1:-k - 1:-1]
for i in range(k):
	print(abc[i])


(x, y, z, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ab = []
for i in a:
	for j in b:
		ab.append(i + j)
ab.sort()
ab.reverse()
ans = []
for i in range(min(k, len(ab))):
	for j in c:
		ans.append(ab[i] + j)
ans.sort()
ans.reverse()
for i in range(k):
	print(ans[i])


import heapq
(x, y, z, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
hq = [[-a[0] - b[0] - c[0], 0, 0, 0]]
heapq.heapify(hq)
visited = {(0, 0, 0)}
for i in range(k):
	(ii, ia, ib, ic) = heapq.heappop(hq)
	print(-ii)
	na = min(ia + 1, x - 1)
	nb = min(ib + 1, y - 1)
	nc = min(ic + 1, z - 1)
	if not (na, ib, ic) in visited:
		heapq.heappush(hq, [-a[na] - b[ib] - c[ic], na, ib, ic])
		visited.add((na, ib, ic))
	if not (ia, nb, ic) in visited:
		heapq.heappush(hq, [-a[ia] - b[nb] - c[ic], ia, nb, ic])
		visited.add((ia, nb, ic))
	if not (ia, ib, nc) in visited:
		heapq.heappush(hq, [-a[ia] - b[ib] - c[nc], ia, ib, nc])
		visited.add((ia, ib, nc))


(X, Y, Z, K) = map(int, input().split())
(*A,) = map(int, input().split())
(*B,) = map(int, input().split())
(*C,) = map(int, input().split())
A.sort(reverse=True)
D = [i + j for j in C for i in B]
D.sort(reverse=True)
E = [i + j for j in D[:K] for i in A[:K]]
E.sort(reverse=True)
print(*E[:K], sep='\n')


def main():
	import heapq
	(x, y, z, k, *abc) = map(int, open(0).read().split())
	a = abc[:x]
	b = abc[x:x + y]
	c = abc[x + y:]
	s = set()
	a.sort(reverse=True)
	b.sort(reverse=True)
	c.sort(reverse=True)
	h = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
	heapq.heapify(h)
	ans = []
	for _ in range(k):
		(p, i, j, k) = heapq.heappop(h)
		ans.append(-p)
		for (p, q, r) in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]:
			if i + p < x and j + q < y and (k + r < z):
				if (i + p, j + q, k + r) not in s:
					s.add((i + p, j + q, k + r))
					v = -(a[i + p] + b[j + q] + c[k + r])
					heapq.heappush(h, (v, i + p, j + q, k + r))
	print(*ans, sep='\n')

def __starting_point():
	main()
__starting_point()


(x, y, z, k) = map(int, input().split())
list1 = [list(map(int, input().split())) for i in range(3)]
list_ab = []
list_ab_c = []
for i in list1[0]:
	for j in list1[1]:
		list_ab.append(i + j)
list_ab.sort(reverse=True)
for i in list_ab[:3000]:
	for j in list1[2]:
		list_ab_c.append(i + j)
list_ab_c.sort(reverse=True)
for i in range(k):
	print(list_ab_c[i])


from heapq import nlargest
(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()))
ab = nlargest(k, (x + y for x in a for y in b))
abc = nlargest(k, (xy + z for xy in ab for z in c))
for i in abc:
	print(i)


(x, y, z, K) = map(int, input().split())
abc = [sorted(list(map(int, input().split())), reverse=True) for i in range(3)]
ans = []
for i in range(x):
	for j in range(y):
		for k in range(z):
			if (i + 1) * (j + 1) * (k + 1) <= K:
				ans.append(abc[0][i] + abc[1][j] + abc[2][k])
			else:
				break
for i in sorted(ans)[::-1][:K]:
	print(i)


from heapq import *
(x, y, z, K) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))[::-1]
d = sorted([q + p for q in a for p in b], reverse=True)[:K]
e = sorted([q + p for q in d for p in c], reverse=True)[:K]
for i in e:
	print(i)


(X, Y, Z, K) = list(map(int, input().split()))
l_A = list(map(int, input().split()))
l_B = list(map(int, input().split()))
l_C = list(map(int, input().split()))
l_A.sort(reverse=True)
l_B.sort(reverse=True)
l_C.sort(reverse=True)
l = []
for i in range(len(l_A)):
	for j in range(len(l_B)):
		for k in range(len(l_C)):
			if (i + 1) * (j + 1) * (k + 1) > K:
				break
			l += [l_A[i] + l_B[j] + l_C[k]]
ans = sorted(l, reverse=True)[:K]
print(*ans, sep='\n')


import heapq
(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()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
li = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
heapq.heapify(li)
for i in range(k):
	ans = heapq.heappop(li)
	print(-ans[0])
	if x > ans[1] + 1 and (-(a[ans[1] + 1] + b[ans[2]] + c[ans[3]]), ans[1] + 1, ans[2], ans[3]) not in li:
		heapq.heappush(li, (-(a[ans[1] + 1] + b[ans[2]] + c[ans[3]]), ans[1] + 1, ans[2], ans[3]))
	if y > ans[2] + 1 and (-(a[ans[1]] + b[ans[2] + 1] + c[ans[3]]), ans[1], ans[2] + 1, ans[3]) not in li:
		heapq.heappush(li, (-(a[ans[1]] + b[ans[2] + 1] + c[ans[3]]), ans[1], ans[2] + 1, ans[3]))
	if z > ans[3] + 1 and (-(a[ans[1]] + b[ans[2]] + c[ans[3] + 1]), ans[1], ans[2], ans[3] + 1) not in li:
		heapq.heappush(li, (-(a[ans[1]] + b[ans[2]] + c[ans[3] + 1]), ans[1], ans[2], ans[3] + 1))


I = lambda : list(map(int, input().split()))
(x, y, z, k) = I()
s = lambda a, b: sorted((i + j for i in a for j in b))[:-k - 1:-1]
S = sorted
print(*s(s(S(I()), S(I())), S(I())))


import copy
num_list = list(map(int, input('').split(' ')))
rank = num_list[3]
lists = []
queue = []
for i in range(3):
	a_list = list(map(int, input('').split(' ')))
	list.sort(a_list, reverse=True)
	if num_list[i] <= rank:
		lists.append(a_list)
	else:
		lists.append(a_list[:rank])
queue.append([lists[0][0] + lists[1][0] + lists[2][0], 0, 0, 0])
for i in range(rank):
	poped = queue.pop(0)
	print(poped[0])
	if i == rank - 1:
		break
	for j in range(3):
		if len(lists[j]) > poped[j + 1] + 1:
			to_append = copy.copy(poped)
			to_append[j + 1] += 1
			to_append[0] += lists[j][to_append[j + 1]] - lists[j][poped[j + 1]]
			if len(queue) == 0:
				queue.append(to_append)
				continue
			Done = True
			for k in range(len(queue)):
				if queue[k] == to_append:
					Done = False
					break
				elif queue[k][0] < to_append[0]:
					queue = queue[:k] + [to_append] + queue[k:]
					Done = False
					break
			if Done == True:
				queue.append(to_append)
	if len(queue) > rank - i - 1:
		queue = queue[:rank - i - 1]


(x, y, z, K) = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
Z = list(map(int, input().split()))
XY = []
for i in range(x):
	for j in range(y):
		XY.append(X[i] + Y[j])
XY.sort()
Z.sort()
XYZ = []
for x in XY[::-1][:K]:
	for z in Z:
		XYZ.append(x + z)
XYZ.sort()
print(*XYZ[::-1][:K])


from heapq import *
(X, Y, Z, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
his = set()

def pushq(p, q, r):
	if (p, q, r) in his:
		return
	if p >= X or q >= Y or r >= Z:
		return
	his.add((p, q, r))
	heappush(Q, (-1 * (A[p] + B[q] + C[r]), (p, q, r)))
	return
pushq(0, 0, 0)
for _ in range(K):
	V = heappop(Q)
	print(-1 * V[0])
	(p, q, r) = V[1]
	pushq(p + 1, q, r)
	pushq(p, q + 1, r)
	pushq(p, q, r + 1)


(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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
K = min(K, 3000)
AB = [a + b for a in A for b in B]
AB.sort(reverse=True)
ABC = [ab + c for ab in AB[:K] for c in C[:K]]
ABC.sort(reverse=True)
for k in range(K):
	print(ABC[k])


(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)
ans = []
for i in range(X):
	for j in range(Y):
		ij = (i + 1) * (j + 1)
		if ij > K:
			break
		for k in range(Z):
			if ij * (k + 1) > K:
				break
			ans.append(A[i] + B[j] + C[k])
ans = sorted(ans, reverse=True)
for i in range(K):
	print(ans[i])


(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()))
ab = []
for ai in a:
	for bi in b:
		ab.append(ai + bi)
ab.sort(reverse=True)
abc = []
for abi in ab[:k]:
	for ci in c:
		abc.append(abi + ci)
abc.sort(reverse=True)
for abci in abc[:k]:
	print(abci)


(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()))
C.sort(reverse=True)
ab = sorted([aa + bb for aa in A for bb in B], reverse=True)[:K]
ans = sorted([aabb + cc for aabb in ab for cc in C], reverse=True)[:K]
for aa in ans:
	print(aa)


(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()))
AB = []
for i in A:
	for j in B:
		AB.append(i + j)
AB.sort(reverse=True)
AB = AB[:K]
ABC = []
for i in AB:
	for j in C:
		ABC.append(i + j)
ABC.sort(reverse=True)
for i in range(K):
	print(ABC[i])


(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()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ab = sorted((i + j for i in a for j in b))[:-k - 1:-1]
c = c[:k]
abc = sorted((i + j for i in ab for j in c))[:-k - 1:-1]
print(*abc[:k], sep='\n')


(x, y, z, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
ab = []
for i in range(x):
	for j in range(y):
		ab.append(a[i] + b[j])
ab = sorted(ab, reverse=True)[:3001]
abc = []
for i in ab:
	for j in c:
		abc.append(i + j)
abc = sorted(abc, reverse=True)
for i in range(k):
	print(abc[i])


def main():
	import heapq
	from collections import defaultdict
	(x, y, z, k, *abc) = map(int, open(0).read().split())
	a = abc[:x]
	b = abc[x:x + y]
	c = abc[x + y:]
	d = defaultdict(list)
	a.sort(reverse=True)
	b.sort(reverse=True)
	c.sort(reverse=True)
	h = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
	heapq.heapify(h)
	ans = []
	for _ in range(k):
		(p, i, j, k) = heapq.heappop(h)
		ans.append(-p)
		for (p, q, r) in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]:
			if i + p < x and j + q < y and (k + r < z):
				if (j + q, k + r) not in d[i + p]:
					d[i + p].append((j + q, k + r))
					v = -(a[i + p] + b[j + q] + c[k + r])
					heapq.heappush(h, (v, i + p, j + q, k + r))
	print(*ans, sep='\n')

def __starting_point():
	main()
__starting_point()


(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()))
res = []
for a in A:
	for b in B:
		res.append(a + b)
res.sort(reverse=True)
res2 = []
for v in res[:K]:
	for c in C:
		res2.append(v + c)
res2.sort(reverse=True)
for i in range(K):
	print(res2[i])


import sys
from heapq import heappush, heapify, heappop
input = sys.stdin.readline

def make_kth(A, B, k):
	(n, m) = (len(A), len(B))
	q = [(-A[0] - B[0], 0, 0)]
	r = []
	for _ in range(min(k, n * m)):
		(v, s, t) = heappop(q)
		r.append(-v)
		if t + 1 < m:
			heappush(q, (-A[s] - B[t + 1], s, t + 1))
		if t == 0 and s + 1 < n:
			heappush(q, (-A[s + 1] - B[0], s + 1, 0))
	return r

def main():
	(_, _, _, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	a.sort(reverse=1)
	b.sort(reverse=1)
	c.sort(reverse=1)
	r = make_kth(a, b, k)
	r = make_kth(c, r, k)
	print(*r, sep='\n')
main()


from itertools import product

def f(A, B, k):
	S = [a + b for (a, b) in product(A, B)]
	S.sort(reverse=True)
	return S[:k]
(x, y, z, k) = map(int, input().split())
(*A,) = map(int, input().split())
(*B,) = map(int, input().split())
(*C,) = map(int, input().split())
S = f(f(A, B, k), C, k)
for s in S:
	print(s)


(x, y, z, K) = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))[::-1]
b = sorted(list(map(int, input().split())))[::-1]
c = sorted(list(map(int, input().split())))[::-1]
ans = []
for i in range(x):
	for j in range(y):
		if i * j > K:
			break
		for k in range(z):
			if i * j * k > K:
				break
			ans.append(a[i] + b[j] + c[k])
ans = sorted(ans)[::-1]
for i in range(K):
	print(ans[i])


import sys
input = sys.stdin.readline
(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()))
ab = [ai + bi for bi in b[:k] for ai in a[:k]]
ab.sort(reverse=True)
s = [ci + abi for abi in ab[:k] for ci in c[:k]]
s.sort(reverse=True)
for si in s[:k]:
	print(si)


(x, y, z, k) = map(int, input().split())
m = []
for _ in range(3):
	m.append(sorted(list(map(int, input().split())), reverse=True))

def sorted_sum(list_a, list_b):
	s = []
	for x in list_a:
		for y in list_b:
			s.append(x + y)
	return sorted(s, reverse=True)
ans = sorted_sum(sorted_sum(m[0], m[1])[0:k], m[2])[0:k]
for i in range(0, k):
	print(ans[i])


import heapq
(x, y, z, k) = list(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)
que = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
is_pushed = {(0, 0, 0): 1}
for _ in range(k):
	(v, p, q, r) = heapq.heappop(que)
	print(-v)
	if p + 1 < x and (not is_pushed.get((p + 1, q, r))):
		heapq.heappush(que, (-(a[p + 1] + b[q] + c[r]), p + 1, q, r))
		is_pushed[p + 1, q, r] = 1
	if q + 1 < y and (not is_pushed.get((p, q + 1, r))):
		heapq.heappush(que, (-(a[p] + b[q + 1] + c[r]), p, q + 1, r))
		is_pushed[p, q + 1, r] = 1
	if r + 1 < z and (not is_pushed.get((p, q, r + 1))):
		heapq.heappush(que, (-(a[p] + b[q] + c[r + 1]), p, q, r + 1))
		is_pushed[p, q, r + 1] = 1


(x, y, z, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))[::-1]
b = sorted(list(map(int, input().split())))[::-1]
c = sorted(list(map(int, input().split())))[::-1]
d = []
for i in a:
	for j in b:
		d += [i + j]
ans = []
d = sorted(d)[::-1][:k]
for i in c:
	for j in d:
		ans += [i + j]
print(*sorted(ans)[::-1][:k], sep='\n')


from itertools import product
(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()))
D = sorted([a + b for (a, b) in product(A, B)], reverse=True)[:k]
E = sorted([c + d for (c, d) in product(C, D)], reverse=True)[:k]
[print(ans) for ans in E]


(x, y, z, k) = map(int, input().split())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ccc = list(map(int, input().split()))
aabb = [a + b for a in aaa for b in bbb]
aabb.sort(reverse=True)
aabb = aabb[:k]
aabbcc = [ab + c for ab in aabb for c in ccc]
aabbcc.sort(reverse=True)
aabbcc = aabbcc[:k]
print('\n'.join(map(str, aabbcc)))


from heapq import nlargest
(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()))
A.sort()
B.sort()
E = nlargest(K, [a + b for a in A for b in B])
F = nlargest(K, [e + c for e in E for c in C])
print('\n'.join(map(str, F)))


(X, Y, Z, K) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()), reverse=True)
AB = [0] * (X * Y)
i = 0
for a in A:
	for b in B:
		AB[i] = a + b
		i += 1
AB.sort(reverse=True)
ans = [0] * (K * Z)
j = 0
for ab in AB[:K]:
	for c in C:
		ans[j] = ab + c
		j += 1
ans.sort(reverse=True)
print(*ans[:K], sep='\n')


(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()))
for l in [b, c]:
	p = []
	for i in a:
		for j in l:
			p.append(i + j)
	a = sorted(p, reverse=True)[:k]
for i in a:
	print(i)


(x, y, z, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
b = list(map(int, input().split()))
b.sort(reverse=True)
c = list(map(int, input().split()))
c.sort(reverse=True)
d = [i + j for i in a for j in b]
d.sort(reverse=True)
e = [i + j for i in c for j in d[:k]]
e.sort(reverse=True)
for i in range(k):
	print(e[i])


import sys
read = sys.stdin.readline

def read_ints():
	return list(map(int, read().split()))
(X, Y, Z, K) = read_ints()
A = read_ints()
B = read_ints()
C = read_ints()
from itertools import product
AB = [a + b for (a, b) in product(A, B)]
AB.sort(reverse=True)
ABC = [ab + c for (ab, c) in product(AB[:K], C)]
ABC.sort(reverse=True)
ABC = ABC[:K]
print(*ABC, sep='\n')


(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()))
AB = [a + b for a in A for b in B]
AB.sort()
AB = AB[-K:]
ABC = [ab + c for ab in AB for c in C]
ABC.sort()
for v in ABC[-1:-K - 1:-1]:
	print(v)


(X, Y, Z, K) = list(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)
E = sorted([a + b for a in A for b in B], reverse=True)
E = E[:K]
nums = sorted([e + c for e in E for c in C], reverse=True)
for n in nums[:K]:
	print(n)


(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()))
goukei = []
for a in A:
	for b in B:
		goukei.append(a + b)
goukei.sort()
goukei2 = goukei[-k:]
goukei3 = []
for c in C:
	for ab in goukei2:
		goukei3.append(ab + c)
goukei3.sort(reverse=True)
print(*goukei3[:k], sep='\n')


(X, Y, Z, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
C = sorted(C, reverse=True)
AB = sorted([a + b for a in A for b in B], reverse=True)
ABC_k = sorted([ab + c for ab in AB[:K] for c in C], reverse=True)
for ans in ABC_k[:K]:
	print(ans)


(x, y, z, K) = list(map(int, input().split()))
A = sorted(map(int, input().split()), reverse=True)
B = sorted(map(int, input().split()), reverse=True)
C = sorted(map(int, input().split()), reverse=True)
ans = []
for i in range(x):
	for j in range(y):
		for k in range(z):
			if (i + 1) * (j + 1) * (k + 1) <= K:
				ans.append(A[i] + B[j] + C[k])
				continue
			break
ans.sort(reverse=True)
for i in range(K):
	print(ans[i])


(X, Y, Z, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ab = []
for i in A:
	for j in B:
		ab.append(i + j)
ab.sort(reverse=True)
abc = []
for i in ab[:3000]:
	for j in C:
		abc.append(i + j)
abc.sort(reverse=True)
for i in range(K):
	print(abc[i])


import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().strip()
NI = lambda : int(input())
NMI = lambda : map(int, input().split())
NLI = lambda : list(NMI())
SI = lambda : input()

def make_grid(h, w, num):
	return [[int(num)] * w for _ in range(h)]

def main():
	(X, Y, Z, K) = NMI()
	A = NLI()
	B = NLI()
	C = NLI()
	AB = []
	for a in A:
		for b in B:
			AB.append(a + b)
	AB.sort(reverse=True)
	C.sort(reverse=True)
	S = []
	for c_idx in range(min(len(C), 3000)):
		for ab_idx in range(min(len(AB), 3000)):
			S.append(C[c_idx] + AB[ab_idx])
	S.sort(reverse=True)
	for i in range(K):
		print(S[i])

def __starting_point():
	main()
__starting_point()


from heapq import heappop, heappush
import sys
input = sys.stdin.readline
(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())))
(q, h, l) = ([], [], 0)
for i in a:
	for j in b:
		heappush(q, -(i + j))
		l += 1
for _ in range(min(l, k)):
	t = heappop(q)
	for i in c:
		heappush(h, t - i)
for i in range(k):
	print(-heappop(h))


(x, y, z, k) = list(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)
ans = []
for ai in a:
	for bi in b:
		ans.append(-ai - bi)
ans.sort()
ans = ans[:k] if len(ans) >= k else ans + [0] * (k - len(ans))
ans1 = []
from heapq import heapify, heappop, heappush
for ci in c:
	for ansi in ans:
		heappush(ans1, ansi - ci)
for i in range(k):
	print(-heappop(ans1))


from heapq import heappush, heappop
from collections import defaultdict

def main():
	(X, Y, Z, K) = list(map(int, input().split(' ')))
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	C = list(map(int, input().split(' ')))
	A.sort(reverse=True)
	B.sort(reverse=True)
	C.sort(reverse=True)
	que = [(-A[0] - B[0] - C[0], 0, 0, 0)]
	already_inserted = defaultdict(int)
	answer = list()
	for _ in range(K):
		(q, i, j, k) = heappop(que)
		answer.append(-q)
		if i + 1 < X:
			item_a = (-A[i + 1] - B[j] - C[k], i + 1, j, k)
			if already_inserted[item_a] == 0:
				heappush(que, item_a)
				already_inserted[item_a] = 1
		if j + 1 < Y:
			item_b = (-A[i] - B[j + 1] - C[k], i, j + 1, k)
			if already_inserted[item_b] == 0:
				heappush(que, item_b)
				already_inserted[item_b] = 1
		if k + 1 < Z:
			item_c = (-A[i] - B[j] - C[k + 1], i, j, k + 1)
			if already_inserted[item_c] == 0:
				heappush(que, item_c)
				already_inserted[item_c] = 1
	for ans in answer:
		print(ans)

def __starting_point():
	main()
__starting_point()


(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()))
sumsofAandB = sorted([a + b for a in A for b in B], reverse=True)[:K]
sumsofAll = sorted([ab + c for ab in sumsofAandB for c in C], reverse=True)
for i in range(K):
	print(sumsofAll[i])


def solve(string):
	(x, y, z, k, *abc) = map(int, string.split())
	a = abc[:x]
	b = abc[x:x + y]
	c = abc[x + y:]
	ab = sorted([_a + _b for _b in b for _a in a])[-k:]
	(*abc,) = map(str, sorted([_ab + _c for _c in c for _ab in ab], reverse=True)[:k])
	return '\n'.join(abc)
print(solve('\n'.join([input() for _ in range(4)])))


import heapq
import itertools
from collections import defaultdict
(x, y, z, k) = list(map(int, input().split()))
A = list((int(a) for a in input().split()))
B = list((int(b) for b in input().split()))
C = list((int(c) for c in input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
hq = []
hqAns = []
d = defaultdict(int)
heapq.heappush(hq, ((A[0] + B[0] + C[0]) * -1, 0, 0, 0))
d[0, 0, 0] = 1
while len(hqAns) < k:
	(val, l, m, n) = heapq.heappop(hq)
	heapq.heappush(hqAns, val)
	if d[l + 1, m, n] == 0 and l + 1 < x:
		heapq.heappush(hq, ((A[l + 1] + B[m] + C[n]) * -1, l + 1, m, n))
		d[l + 1, m, n] = 1
	if d[l, m + 1, n] == 0 and m + 1 < y:
		heapq.heappush(hq, ((A[l] + B[m + 1] + C[n]) * -1, l, m + 1, n))
		d[l, m + 1, n] = 1
	if d[l, m, n + 1] == 0 and n + 1 < z:
		heapq.heappush(hq, ((A[l] + B[m] + C[n + 1]) * -1, l, m, n + 1))
		d[l, m, n + 1] = 1
for i in range(k):
	print(heapq.heappop(hqAns) * -1)


import heapq
(X, Y, Z, K) = [int(x) for x in input().split()]
XYZ = [0] * 3
for i in range(3):
	XYZ[i] = [int(x) for x in input().split()]
	XYZ[i].sort(reverse=True)
tmp = (-1 * (XYZ[0][0] + XYZ[1][0] + XYZ[2][0]), 0, 0, 0)
q = [tmp]
inq = {tmp[1:]}
heapq.heapify(q)
for ik in range(K):
	max = heapq.heappop(q)
	print(-max[0])
	(i, j, k) = (max[1], max[2], max[3])
	if not (i + 1, j, k) in inq and i + 1 < X:
		heapq.heappush(q, (-1 * (XYZ[0][i + 1] + XYZ[1][j] + XYZ[2][k]), i + 1, j, k))
		inq.add((i + 1, j, k))
	if not (i, j + 1, k) in inq and j + 1 < Y:
		heapq.heappush(q, (-1 * (XYZ[0][i] + XYZ[1][j + 1] + XYZ[2][k]), i, j + 1, k))
		inq.add((i, j + 1, k))
	if not (i, j, k + 1) in inq and k + 1 < Z:
		heapq.heappush(q, (-1 * (XYZ[0][i] + XYZ[1][j] + XYZ[2][k + 1]), i, j, k + 1))
		inq.add((i, j, k + 1))
print()


import itertools
(X, Y, Z, K) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
list_ = [b + c for (b, c) in itertools.product(B, C)]
list_.sort(reverse=True)
list__ = [ab + c for (ab, c) in itertools.product(list_[:K], A)]
list__.sort(reverse=True)
for N in list__[:K]:
	print(N)


import heapq
(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()))
AB = []
for i in A:
	for j in B:
		heapq.heappush(AB, -i - j)
ABC = []
for i in range(min(K, X * Y)):
	temp = heapq.heappop(AB)
	for j in C:
		heapq.heappush(ABC, temp - j)
for i in range(min(K, X * Y * Z)):
	print(-heapq.heappop(ABC))


(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()))
l = []
for i in a:
	for j in b:
		l.append(i + j)
c.sort(reverse=True)
l.sort(reverse=True)
l = l[:k]
l2 = []
for i in c:
	for j in l:
		l2.append(i + j)
l2.sort(reverse=True)
print(*l2[:k], sep='\n')


(x, y, z, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort()
b.sort()
c.sort()
ab = [a[i] + b[j] for j in range(y) for i in range(x)]
ab.sort(reverse=True)
ab = ab[:k]
l = len(ab)
abc = [ab[i] + c[j] for j in range(z) for i in range(l)]
abc.sort(reverse=True)
for i in range(k):
	print(abc[i])


(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()))
from itertools import product
D = sorted([a + b for (a, b) in product(A, B)], reverse=True)
D = D[:K]
E = sorted([d + c for (d, c) in product(D, C)], reverse=True)
for i in range(K):
	print(E[i])


def ca():
	(x, y, z, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]
	c.sort(reverse=True)
	AB = [i + j for i in a for j in b]
	AB.sort(reverse=True)
	ans = [i + j for i in AB[:k] for j in c]
	ans.sort(reverse=True)
	for i in ans[:k]:
		print(i)
	exit()
print(ca())


(X, Y, Z, K) = map(int, input().split())
(A, B, C) = [sorted(list(map(int, input().split())))[::-1][:K] for _ in range(3)]
D = []
for ai in A:
	for bi in B:
		D.append(ai + bi)
D = sorted(D)[::-1][:K]
res = []
for di in D:
	for ci in C:
		res.append(di + ci)
res = sorted(res)[::-1][:K]
for ans in res:
	print(ans)


(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()))
D = []
for i in A:
	for j in B:
		D.append(i + j)
D = sorted(D)[::-1]
if X * Y > K:
	D = D[:K]
E = []
for i in D:
	for j in C:
		E.append(i + j)
E = sorted(E)[::-1]
E = E[:K]
for i in E:
	print(i)


(X, Y, X, K) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ab = [a + b for a in A for b in B]
ab.sort(reverse=True)
ans = [x + c for x in ab[:K] for c in C]
ans.sort(reverse=True)
print('\n'.join(map(str, ans[:K])))


from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge

def solve():
	(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()))
	A.sort(reverse=True)
	B.sort(reverse=True)
	C.sort(reverse=True)
	Cake = []
	heapify(Cake)
	for i in range(X):
		for j in range(min(Y, K // (i + 1) + 1)):
			for k in range(min(Z, K // ((i + 1) * (j + 1)) + 1)):
				heappush(Cake, -A[i] - B[j] - C[k])
	ans = []
	for i in range(K):
		ans.append(abs(heappop(Cake)))
	return ans
print(*solve(), sep='\n')


(x, y, z, q) = map(int, input().split())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(map(int, input().split()), reverse=True)
c = sorted(map(int, input().split()), reverse=True)
l = []
for i in range(x):
	for j in range(y):
		if i * j > q:
			break
		for k in range(z):
			if i * j * k > q:
				break
			l += [a[i] + b[j] + c[k]]
l.sort(reverse=True)
for w in l[:q]:
	print(w)


(x, y, z, w) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(3)]
for i in range(3):
	a[i].sort(reverse=True)
li = []
for i in range(1, x + 1):
	for j in range(1, y + 1):
		if i * j > w:
			break
		for k in range(1, z + 1):
			if i * j * k > w:
				break
			li.append(a[0][i - 1] + a[1][j - 1] + a[2][k - 1])
li.sort(reverse=True)
print('\n'.join(map(str, li[:w])))


(X, Y, Z, K) = map(int, input().split())
(*A,) = map(int, input().split())
(*B,) = map(int, input().split())
(*C,) = map(int, input().split())
AB = [a + b for a in A for b in B]
AB.sort(reverse=True)
AB = AB[:K]
ABC = [ab + c for c in C for ab in AB]
ABC.sort(reverse=True)
ABC = ABC[:K]
for abc in ABC:
	print(abc)


I = lambda : list(map(int, input().split()))
k = I()[3]
s = lambda a: sorted((i + j for i in I() for j in a))[:-k - 1:-1]
print(*s(s(I())))


from heapq import heappop, heappush

def main():

	def push(i, j, k):
		nonlocal A, B, C, ADD
		if i >= x or j >= y or k >= z:
			return
		if (i, j, k) not in ADD:
			heappush(H, (A[i] + B[j] + C[k], i, j, k))
			ADD.add((i, j, k))
	(x, y, z, k) = list(map(int, input().split()))
	INF = 10 ** 11
	A = sorted(list([-int(x) for x in input().split()]))
	B = sorted(list([-int(x) for x in input().split()]))
	C = sorted(list([-int(x) for x in input().split()]))
	H = []
	ADD = set()
	push(0, 0, 0)
	for _ in range(k):
		(ans, i, j, k) = heappop(H)
		push(i + 1, j, k)
		push(i, j + 1, k)
		push(i, j, k + 1)
		print(-ans)

def __starting_point():
	main()
__starting_point()


r = range
(x, y, z, k) = map(int, input().split())
(a, b, c) = eval('list(map(int,input().split())), ' * 3)
ab = sorted([a[i] + b[j] for i in r(x) for j in r(y)], reverse=True)
abc = sorted([ab[i] + c[j] for i in r(min(3000, x * y)) for j in r(z)], reverse=True)
print(*[abc[i] for i in r(k)])


import sys
import heapq
(X, Y, Z, K) = map(int, sys.stdin.readline().split())
A = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
B = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
C = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
ans_heapq = []
i = 0
j = 0
k = 0
heapq.heappush(ans_heapq, [-1 * (A[0] + B[0] + C[0]), i, j, k])
ijk_list = [[0, 0, 0]]
for _ in range(K):
	(ans, i, j, k) = heapq.heappop(ans_heapq)
	print(-1 * ans)
	if i < X - 1 and [i + 1, j, k] not in ijk_list:
		abc = -1 * (A[i + 1] + B[j] + C[k])
		heapq.heappush(ans_heapq, [abc, i + 1, j, k])
		ijk_list.append([i + 1, j, k])
	if j < Y - 1 and [i, j + 1, k] not in ijk_list:
		abc = -1 * (A[i] + B[j + 1] + C[k])
		heapq.heappush(ans_heapq, [abc, i, j + 1, k])
		ijk_list.append([i, j + 1, k])
	if k < Z - 1 and [i, j, k + 1] not in ijk_list:
		abc = -1 * (A[i] + B[j] + C[k + 1])
		heapq.heappush(ans_heapq, [abc, i, j, k + 1])
		ijk_list.append([i, j, k + 1])


import heapq
from collections import defaultdict
(x, y, z, K) = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))[::-1]
b = sorted(list(map(int, input().split())))[::-1]
c = sorted(list(map(int, input().split())))[::-1]
used = defaultdict(bool)
pq = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
used[0, 0, 0] = True
heapq.heapify(pq)
for _ in range(K):
	(d, i, j, k) = heapq.heappop(pq)
	print(-d)
	if i + 1 < x and (not used[i + 1, j, k]):
		heapq.heappush(pq, (-(a[i + 1] + b[j] + c[k]), i + 1, j, k))
		used[i + 1, j, k] = True
	if j + 1 < y and (not used[i, j + 1, k]):
		heapq.heappush(pq, (-(a[i] + b[j + 1] + c[k]), i, j + 1, k))
		used[i, j + 1, k] = True
	if k + 1 < z and (not used[i, j, k + 1]):
		heapq.heappush(pq, (-(a[i] + b[j] + c[k + 1]), i, j, k + 1))
		used[i, j, k + 1] = True


(x, y, z, k) = map(int, input().split())
aa = sorted(map(int, input().split()))
bb = sorted(map(int, input().split()))
cc = sorted(map(int, input().split()))
ab = sorted((a + b for a in aa for b in bb))[:-k - 1:-1]
abc = sorted((s + c for s in ab[:k] for c in cc))[:-k - 1:-1]
print(*abc, sep='\n')


(X, Y, Z, K) = map(int, input().split())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
ab = sorted((s + t for t in B for s in A))[-1:-K - 1:-1]
abc = sorted((i + x for i in ab for x in C))[-1:-K - 1:-1]
print(*abc, sep='\n')


(numx, numy, numz, k) = list(map(int, input().split()))
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
Z = list(map(int, input().split()))
XY = [x + y for x in X for y in Y]
XY.sort(reverse=True)
XY = XY[:k]
XYZ = [xy + z for xy in XY for z in Z]
XYZ.sort(reverse=True)
for i in range(k):
	print(XYZ[i])


(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()))
AB = []
ans = []
for a in A:
	for b in B:
		AB.append(a + b)
AB.sort(reverse=True)
AB = AB[:min(3001, X * Y * Z + 1)]
for c in C:
	for ab in AB:
		ans.append(c + ab)
ans.sort(reverse=True)
for i in range(K):
	print(ans[i])


from heapq import *
(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()))
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
cake = []
heapify(cake)
for x in range(X):
	for y in range(min(Y, K // (x + 1) + 1)):
		for k in range(min(Z, K // ((x + 1) * (y + 1)) + 1)):
			heappush(cake, -(A[x] + B[y] + C[k]))
for _ in range(K):
	print(abs(heappop(cake)))


def MAP():
	return list(map(int, input().split()))

def INT():
	return int(input())

def FLOAT():
	return float(input())
MOD = 10 ** 9 + 7
(x, y, z, k) = MAP()
a = MAP()
b = MAP()
c = MAP()
a.sort()
b.sort()
l = []
for i in a:
	for j in b:
		l.append(i + j)
l.sort()
c.sort()
l2 = []
for i in l[-k:]:
	for j in c[-k:]:
		l2.append(i + j)
l2.sort(reverse=True)
for i in l2[:k]:
	print(i)


(X, Y, Z, K) = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
AB = sorted([a + b for a in A for b in B])[-1:-K - 1:-1]
ABC = sorted([ab + c for ab in AB for c in C])[-1:-K - 1:-1]
print('\n'.join(map(str, ABC)))


from itertools import product
from heapq import *
(X, Y, Z, K, *f) = map(int, open(0).read().split())
A = f[:X]
B = f[X:X + Y]
C = f[X + Y:]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
AB = [sum(x) * -1 for x in product(A, B)]
heapify(AB)
AB_picked = []
for i in range(K):
	if AB:
		AB_picked.append(heappop(AB) * -1)
	else:
		break
ABC = [sum(x) * -1 for x in product(AB_picked, C)]
heapify(ABC)
for i in range(K):
	print(heappop(ABC) * -1)


from itertools import product
(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()))
p = [i + k for (i, k) in product(a, b)]
p.sort(reverse=True)
q = [i + k for (i, k) in product(p[:k], c)]
q.sort(reverse=True)
print('\n'.join(map(str, q[:k])))


(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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
AB = [a + b for a in A for b in B]
AB.sort(reverse=True)
ABC = [ab + c for ab in AB[:min(k, x * y)] for c in C]
ABC.sort(reverse=True)
for i in range(k):
	print(ABC[i])


def main():
	(x, y, z, k) = map(int, input().split())
	lia = sorted(list(map(int, input().split())))
	lib = sorted(list(map(int, input().split())))
	lic = sorted(list(map(int, input().split())))
	li2 = sorted(list((a + b for a in lia for b in lib)), reverse=True)[:k]
	li3 = sorted(list((ab + c for ab in li2 for c in lic)), reverse=True)[:k]
	print('\n'.join(map(str, li3)))
main()


import sys
input = sys.stdin.readline
(x, y, z, k) = map(int, input().split())
lisa = sorted(map(int, input().split()))
lisb = sorted(map(int, input().split()))
lisc = sorted(map(int, input().split()))
ab = sorted((a + b for a in lisa for b in lisb))[:-k - 1:-1]
abc = sorted((ab + c for ab in ab[:k] for c in lisc))[:-k - 1:-1]
print(*abc, sep='\n')


(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()))
AB = []
for a in A:
	for b in B:
		AB.append(a + b)
AB = sorted(AB, reverse=True)[:k]
ABC = []
for ab in AB:
	for c in C:
		ABC.append(ab + c)
ABC.sort(reverse=True)
for abc in ABC[:k]:
	print(abc)


from itertools import product
(x, y, z, k) = map(int, input().split())
A = map(int, input().split())
B = map(int, input().split())
C = map(int, input().split())
AB = [sum(ab) for ab in product(A, B)]
AB.sort(reverse=True)
AB = AB[:k]
ABC = [sum(abc) for abc in product(AB, C)]
ABC.sort(reverse=True)
for i in range(k):
	print(ABC[i])


import sys
import heapq
input = sys.stdin.readline

def main():
	(X, Y, Z, K) = list(map(int, input().split()))
	A = list([-int(x) for x in input().split()])
	B = list([-int(x) for x in input().split()])
	C = list([-int(x) for x in input().split()])
	A.sort()
	B.sort()
	C.sort()
	p_queue = [(A[0] + B[0] + C[0], 0, 0, 0)]
	visited = set()
	visited.add((0, 0, 0))
	ans = []
	while len(ans) < K:
		(s, i_A, i_B, i_C) = heapq.heappop(p_queue)
		ans.append(-s)
		if i_A < X - 1 and (i_A + 1, i_B, i_C) not in visited:
			visited.add((i_A + 1, i_B, i_C))
			t = s - A[i_A] + A[i_A + 1]
			heapq.heappush(p_queue, (t, i_A + 1, i_B, i_C))
		if i_B < Y - 1 and (i_A, i_B + 1, i_C) not in visited:
			visited.add((i_A, i_B + 1, i_C))
			t = s - B[i_B] + B[i_B + 1]
			heapq.heappush(p_queue, (t, i_A, i_B + 1, i_C))
		if i_C < Z - 1 and (i_A, i_B, i_C + 1) not in visited:
			visited.add((i_A, i_B, i_C + 1))
			t = s - C[i_C] + C[i_C + 1]
			heapq.heappush(p_queue, (t, i_A, i_B, i_C + 1))
	print('\n'.join(map(str, ans)))

def __starting_point():
	main()
__starting_point()


(num_x, num_y, num_z, k) = map(int, input().split())
x_list = sorted(list(map(int, input().split())))
y_list = sorted(list(map(int, input().split())))
z_list = sorted(list(map(int, input().split())))
xy_list = sorted([x + y for x in x_list for y in y_list], reverse=True)[:k]
xyz_list = sorted([xy + z for xy in xy_list for z in z_list], reverse=True)[:k]
for xyz in xyz_list:
	print(xyz)


import heapq
(X, Y, Z, K) = list(map(int, input().split()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
h = []
heapq.heappush(h, (-A[0] - B[0] - C[0], 0, 0, 0))
ans = []
st = set()
for _ in range(K):
	(s, i, j, k) = heapq.heappop(h)
	ans.append(-s)
	if i + 1 < X and (not (i + 1, j, k) in st):
		heapq.heappush(h, (-A[i + 1] - B[j] - C[k], i + 1, j, k))
		st.add((i + 1, j, k))
	if j + 1 < Y and (not (i, j + 1, k) in st):
		heapq.heappush(h, (-A[i] - B[j + 1] - C[k], i, j + 1, k))
		st.add((i, j + 1, k))
	if k + 1 < Z and (not (i, j, k + 1) in st):
		heapq.heappush(h, (-A[i] - B[j] - C[k + 1], i, j, k + 1))
		st.add((i, j, k + 1))
for v in ans:
	print(v)


(x, y, z, k) = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
import heapq
V = {(0, 0, 0)}
Q = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
heapq.heapify(Q)

def isIn(tup):
	return tup[0] < x and tup[1] < y and (tup[2] < z)
for i in range(k):
	now = heapq.heappop(Q)
	print(-now[0])
	nex = (now[1] + 1, now[2], now[3])
	if not nex in V and isIn(nex):
		V.add(nex)
		heapq.heappush(Q, (-(A[nex[0]] + B[nex[1]] + C[nex[2]]),) + nex)
	nex = (now[1], now[2] + 1, now[3])
	if not nex in V and isIn(nex):
		V.add(nex)
		heapq.heappush(Q, (-(A[nex[0]] + B[nex[1]] + C[nex[2]]),) + nex)
	nex = (now[1], now[2], now[3] + 1)
	if not nex in V and isIn(nex):
		V.add(nex)
		heapq.heappush(Q, (-(A[nex[0]] + B[nex[1]] + C[nex[2]]),) + nex)


(x, y, z, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
li = []
for i in a:
	for j in b:
		li.append(i + j)
li.sort(reverse=True)
ansli = []
for i in c:
	for j in range(min(k, len(li))):
		ansli.append(i + li[j])
ansli.sort(reverse=True)
for i in range(k):
	print(ansli[i])


(x, y, z, k) = map(int, input().split())
info = [list(map(int, input().split())) for i in range(3)]
li = []
ans = []
li_append = li.append
ans_append = ans.append
for i in info[0]:
	for j in info[1]:
		li_append(i + j)
li = sorted(li, reverse=True)
for i in li[:3000]:
	for j in info[2]:
		ans_append(i + j)
ans = sorted(ans, reverse=True)
for i in range(k):
	print(ans[i])


import heapq
(x, y, z, k) = map(int, input().split())
alist = sorted(list(map(int, input().split())), reverse=True)
blist = sorted(list(map(int, input().split())), reverse=True)
clist = sorted(list(map(int, input().split())), reverse=True)
l = [(-(alist[0] + blist[0] + clist[0]), 0, 0, 0)]
heapq.heapify(l)
count = 0
ai = bi = ci = 0
selected = set()
selected.add((0, 0, 0))
while len(l) != 0:
	temp = heapq.heappop(l)
	(tempa, tempb, tempc) = temp[1:]
	print(-temp[0])
	count += 1
	if count == k:
		break
	if tempa + 1 <= x - 1:
		if not (tempa + 1, tempb, tempc) in selected:
			heapq.heappush(l, (-(alist[tempa + 1] + blist[tempb] + clist[tempc]), tempa + 1, tempb, tempc))
			selected.add((tempa + 1, tempb, tempc))
	if tempb + 1 <= y - 1:
		if not (tempa, tempb + 1, tempc) in selected:
			heapq.heappush(l, (-(alist[tempa] + blist[tempb + 1] + clist[tempc]), tempa, tempb + 1, tempc))
			selected.add((tempa, tempb + 1, tempc))
	if tempc + 1 <= z - 1:
		if not (tempa, tempb, tempc + 1) in selected:
			heapq.heappush(l, (-(alist[tempa] + blist[tempb] + clist[tempc + 1]), tempa, tempb, tempc + 1))
			selected.add((tempa, tempb, tempc + 1))


import heapq as hq
(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()))
ab = []
for a in A:
	for b in B:
		hq.heappush(ab, -a - b)
abc = []
cnt = 0
while cnt < k and ab:
	cnt += 1
	a = hq.heappop(ab)
	for b in C:
		hq.heappush(abc, a - b)
cnt = 0
while cnt < k:
	print(-hq.heappop(abc))
	cnt += 1


(X, Y, Z, K) = map(int, input().split())
l_a = list(map(int, input().split()))
l_b = list(map(int, input().split()))
l_c = list(map(int, input().split()))
ll = []
li = []
for i in l_a:
	for m in l_b:
		ll.append(i + m)
ll.sort(reverse=True)
del ll[K + 1:]
for c in l_c:
	for i in ll:
		li.append(c + i)
li.sort(reverse=True)
for i in range(K):
	print(li[i])


import heapq as hq
(x, y, z, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
abc = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
used = set((0, 0, 0))
while K > 0:
	K -= 1
	(p, i, j, k) = hq.heappop(abc)
	print(-p)
	for (a, b, c) in [(i + 1, j, k), (i, j + 1, k), (i, j, k + 1)]:
		if a < x and b < y and (c < z) and ((a, b, c) not in used):
			used.add((a, b, c))
			hq.heappush(abc, (-(A[a] + B[b] + C[c]), a, b, c))


(x, y, z, K) = list(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)
lst = []
for i in range(len(a)):
	for j in range(len(b)):
		for k in range(len(c)):
			if (i + 1) * (j + 1) * (k + 1) > K:
				break
			lst.append(a[i] + b[j] + c[k])
new_lst = sorted(lst, reverse=True)
for i in range(K):
	print(new_lst[i])


from heapq import heappop, heappush
(X, Y, Z, K) = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)
h = []
a = a_list[0]
b = b_list[0]
c = c_list[0]
heappush(h, (-(a + b + c), 0, 0, 0))
key_dict = dict()
key_dict[0, 0, 0] = 1
ans_list = []
for i in range(K):
	(ans, a, b, c) = heappop(h)
	ans_list.append(-ans)
	a1 = (a + 1, b, c)
	b1 = (a, b + 1, c)
	c1 = (a, b, c + 1)
	if a + 1 < X and (not a1 in key_dict):
		heappush(h, (-(a_list[a + 1] + b_list[b] + c_list[c]), a + 1, b, c))
		key_dict[a + 1, b, c] = 1
	if b + 1 < Y and (not b1 in key_dict):
		heappush(h, (-(a_list[a] + b_list[b + 1] + c_list[c]), a, b + 1, c))
		key_dict[a, b + 1, c] = 1
	if c + 1 < Z and (not c1 in key_dict):
		heappush(h, (-(a_list[a] + b_list[b] + c_list[c + 1]), a, b, c + 1))
		key_dict[a, b, c + 1] = 1
for ans in ans_list:
	print(ans)


def main():
	(x, y, z, k) = map(int, input().split())
	al = [int(i) for i in input().split()]
	bl = [int(i) for i in input().split()]
	cl = [int(i) for i in input().split()]
	lst = [i + j for i in al for j in bl]
	lst.sort(reverse=True)
	num = min(x * y, k)
	lst = lst[:num]
	L = [i + j for i in cl for j in lst]
	L.sort(reverse=True)
	for i in range(k):
		print(L[i])
main()


(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()))
c.sort(reverse=True)
e = [a_i + b_j for b_j in b for a_i in a]
e.sort(reverse=True)
ans = [e_i + c_j for c_j in c[:k] for e_i in e[:k]]
ans.sort(reverse=True)
for i in ans[:k]:
	print(i)


import heapq
(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 va in a:
	for vb in b:
		e.append(va + vb)
e.sort(reverse=True)
e = e[:k]
d = []
for ve in e:
	for vc in c:
		heapq.heappush(d, -(ve + vc))
for i in range(k):
	print(-heapq.heappop(d))


(x, y, z, k) = map(int, input().split())
(a, b, c) = [sorted(list(map(int, input().split())), reverse=True) for i in range(3)]
L = []
for i in range(x):
	for j in range(y):
		if (i + 1) * (j + 1) > k:
			break
		for m in range(z):
			if (i + 1) * (j + 1) * (m + 1) > k:
				break
			else:
				L.append(a[i] + b[j] + c[m])
for i in sorted(L, reverse=True)[:k]:
	print(i)


(X, Y, Z, K) = map(int, input().split())
(*A,) = sorted(map(int, input().split()))
(*B,) = sorted(map(int, input().split()))
(*C,) = sorted(map(int, input().split()))
ab = [i + j for i in A for j in B]
ab = sorted(ab, reverse=True)[:K]
abc = [i + j for i in ab for j in C]
abc.sort(reverse=True)
for i in abc[:K]:
	print(i)


(x, y, z, k) = list(map(int, input().split()))
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
ab = sorted((x + y for x in a for y in b))[:-k - 1:-1]
abc = sorted((x + y for x in ab[:k] for y in c))[:-k - 1:-1]
print(*abc, sep='\n')


import heapq
(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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
dic = {}
dic[0, 0, 0] = 1
lst = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
heapq.heapify(lst)
for r in range(K):
	a = lst[0][1]
	b = lst[0][2]
	c = lst[0][3]
	print(lst[0][0] * -1)
	heapq.heappop(lst)
	if a < X - 1:
		if (a + 1, b, c) not in dic:
			heapq.heappush(lst, (-(A[a + 1] + B[b] + C[c]), a + 1, b, c))
			dic[a + 1, b, c] = 1
	if b < Y - 1:
		if (a, b + 1, c) not in dic:
			heapq.heappush(lst, (-(A[a] + B[b + 1] + C[c]), a, b + 1, c))
			dic[a, b + 1, c] = 1
	if c < Z - 1:
		if (a, b, c + 1) not in dic:
			heapq.heappush(lst, (-(A[a] + B[b] + C[c + 1]), a, b, c + 1))
			dic[a, b, c + 1] = 1


from sys import stdin
import heapq

def main():
	readline = stdin.readline
	(x, y, z, k) = map(int, readline().split())
	a = list(map(int, readline().split()))
	a.sort(reverse=True)
	b = list(map(int, readline().split()))
	b.sort(reverse=True)
	c = list(map(int, readline().split()))
	c.sort(reverse=True)
	s = {(0, 0, 0)}
	h = [[-(a[0] + b[0] + c[0]), (0, 0, 0)]]
	heapq.heapify(h)
	for _ in range(k):
		li = heapq.heappop(h)
		n = -li[0]
		co = li[1]
		print(n)
		if co[0] + 1 < x:
			co_1 = (co[0] + 1, co[1], co[2])
			n_1 = a[co_1[0]] + b[co_1[1]] + c[co_1[2]]
			n_1 = -n_1
			if co_1 not in s:
				heapq.heappush(h, [n_1, co_1])
				s.add(co_1)
		if co[1] + 1 < y:
			co_2 = (co[0], co[1] + 1, co[2])
			n_2 = a[co_2[0]] + b[co_2[1]] + c[co_2[2]]
			n_2 = -n_2
			if co_2 not in s:
				heapq.heappush(h, [n_2, co_2])
				s.add(co_2)
		if co[2] + 1 < z:
			co_3 = (co[0], co[1], co[2] + 1)
			n_3 = a[co_3[0]] + b[co_3[1]] + c[co_3[2]]
			n_3 = -n_3
			if co_3 not in s:
				heapq.heappush(h, [n_3, co_3])
				s.add(co_3)

def __starting_point():
	main()
__starting_point()


from itertools import product
(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()))
d = sorted([s + t for (s, t) in product(a, b)], reverse=True)[:3000]
e = sorted([s + t for (s, t) in product(c, d)], reverse=True)[:k]
[print(i) for i in e]


def main():
	import heapq
	(x, y, z, k, *abc) = list(map(int, open(0).read().split()))
	a = sorted(abc[:x], reverse=True)
	b = sorted(abc[x:x + y], reverse=True)
	c = sorted(abc[x + y:], reverse=True)
	s = set()
	h = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
	heapq.heapify(h)
	num = []
	for _ in range(k):
		(p, i, j, k) = heapq.heappop(h)
		num.append(-p)
		for (p, q, r) in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]:
			(p, q, r) = (min(i + p, x - 1), min(j + q, y - 1), min(k + r, z - 1))
			if (p, q, r) not in s:
				s.add((p, q, r))
				v = -(a[p] + b[q] + c[r])
				heapq.heappush(h, (v, p, q, r))
	ans = '\n'.join(map(str, num))
	print(ans)

def __starting_point():
	main()
__starting_point()


import heapq
(X, Y, Z, K) = [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
C = [int(i) for i in input().split(' ')]
AB = []
for a in A:
	for b in B:
		AB.append(a + b)
AB = heapq.nlargest(K, AB)
ABC = []
for ab in AB:
	for c in C:
		ABC.append(ab + c)
for cake in heapq.nlargest(K, ABC):
	print(cake)


(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 ai in a:
	for bi in b:
		e.append(ai + bi)
e.sort(reverse=True)
e = e[:k]
ans = []
for ci in c:
	for ei in e:
		ans.append(ci + ei)
ans.sort(reverse=True)
for i in range(k):
	print(ans[i])


(X, Y, Z, K) = list(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)
e = []
s = []
for i in A:
	for j in B:
		e.append(i + j)
e = sorted(e, reverse=True)
if K < len(e):
	e = e[0:K]
for i in e:
	for j in C:
		s.append(i + j)
s = sorted(s, reverse=True)
for i in range(K):
	print(s[i])


(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()))
l = []
L = []
for ix in range(x):
	for iy in range(y):
		l.append(a[ix] + b[iy])
l.sort()
l.reverse()
if len(l) > k:
	l = l[0:k]
for iz in range(z):
	for i in range(len(l)):
		L.append(c[iz] + l[i])
L.sort()
L.reverse()
for i in range(k):
	print(L[i])


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(X, Y, Z, K) = map(int, readline().split())
	A = list(map(int, readline().split()))
	B = list(map(int, readline().split()))
	C = list(map(int, readline().split()))
	A.sort(reverse=True)
	B.sort(reverse=True)
	C.sort(reverse=True)
	AB = [a + b for a in A[:K] for b in B[:K]]
	AB.sort(reverse=True)
	ABC = [ab + c for ab in AB[:K] for c in C[:K]]
	ABC.sort(reverse=True)
	print(*ABC[:K], sep='\n')
	return

def __starting_point():
	main()
__starting_point()


(x, y, z, k) = map(int, input().split())
a = map(int, input().split())
b = list(map(int, input().split()))
c = map(int, input().split())
d = sorted((ai + bi for ai in a for bi in b), reverse=True)[:k]
e = sorted((ci + di for ci in c for di in d), reverse=True)[:k]
print(*e)


import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate
sys.setrecursionlimit(10 ** 6)
INF = 10 ** 12
m = 10 ** 9 + 7

def main():
	(X, Y, Z, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(map(int, input().split()))
	A.sort(reverse=True)
	B.sort(reverse=True)
	C.sort(reverse=True)
	q = []
	heappush(q, (-(A[0] + B[0] + C[0]), 0, 0, 0))
	count = 0
	used = set()
	while count < K:
		(num, s, t, u) = heappop(q)
		print(-num)
		used.add((s, t, u))
		if s + 1 < X and (s + 1, t, u) not in used:
			heappush(q, (-(A[s + 1] + B[t] + C[u]), s + 1, t, u))
			used.add((s + 1, t, u))
		if t + 1 < Y and (s, t + 1, u) not in used:
			heappush(q, (-(A[s] + B[t + 1] + C[u]), s, t + 1, u))
			used.add((s, t + 1, u))
		if u + 1 < Z and (s, t, u + 1) not in used:
			heappush(q, (-(A[s] + B[t] + C[u + 1]), s, t, u + 1))
			used.add((s, t, u + 1))
		count += 1

def __starting_point():
	main()
__starting_point()


(x, y, z, k) = [int(it) for it in input().split()]
al = [int(it) for it in input().split()]
bl = [int(it) for it in input().split()]
cl = [int(it) for it in input().split()]
abl = [a + b for a in al for b in bl]
abl.sort()
abl.reverse()
abl = abl[:k]
abcl = [ab + c for ab in abl for c in cl]
abcl.sort()
abcl.reverse()
abcl = abcl[:k]
print('\n'.join([str(it) for it in abcl]))


import heapq
(x, y, z, k) = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
al = []
hq = []
heapq.heappush(hq, (-(a[0] + b[0] + c[0]), 0, 0, 0))
for i in range(k):
	(hqi, ai, bi, ci) = heapq.heappop(hq)
	print(-hqi)
	if ai + 1 < x and (not (ai + 1, bi, ci) in al):
		heapq.heappush(hq, (-(a[ai + 1] + b[bi] + c[ci]), ai + 1, bi, ci))
		al.append((ai + 1, bi, ci))
	if bi + 1 < y and (not (ai, bi + 1, ci) in al):
		heapq.heappush(hq, (-(a[ai] + b[bi + 1] + c[ci]), ai, bi + 1, ci))
		al.append((ai, bi + 1, ci))
	if ci + 1 < z and (not (ai, bi, ci + 1) in al):
		heapq.heappush(hq, (-(a[ai] + b[bi] + c[ci + 1]), ai, bi, ci + 1))
		al.append((ai, bi, ci + 1))


(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()))
N = []
for a in A:
	for b in B:
		N.append(a + b)
N.sort(reverse=True)
N = N[:K]
M = []
for n in N:
	for c in C:
		M.append(n + c)
M.sort(reverse=True)
M = M[:K]
print(*M, sep='\n')


import itertools
(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()))
mix_ab = [a_ + b_ for (a_, b_) in itertools.product(a, b)]
mix_ab.sort(reverse=True)
c.sort(reverse=True)
mix_abc = [ab_ + c_ for (ab_, c_) in itertools.product(mix_ab[:k], c[:k])]
mix_abc.sort(reverse=True)
print(*mix_abc[:k], sep='\n')


inf = float('INF')
(x, y, z, k) = map(int, input().split())
dp = [0] * 3000
l = []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in a:
	for j in b:
		l.append(i + j)
l.sort()
l = l[::-1]
t = []
for i in l[:k]:
	for j in c:
		t.append(i + j)
t.sort()
t = t[::-1]
for (i, n) in enumerate(t):
	print(n)
	if i == k - 1:
		break


(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()))
AB = [a + b for a in A for b in B]
AB.sort(reverse=True)
AB = AB[:k]
ABC = [ab + c for ab in AB for c in C]
ABC.sort(reverse=True)
ABC = ABC[:k]
print('\n'.join(map(str, ABC)))


from heapq import heapify, heappop, heappush
(X, Y, Z, K) = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
B = sorted(map(int, input().split()), reverse=True)
C = sorted(map(int, input().split()), reverse=True)
que = [[-(A[0] + B[0] + C[0]), 0, 0, 0]]
heapify(que)
s = set()
for i in range(K):
	p = heappop(que)
	print(-p[0])
	if p[1] < X - 1 and (not (p[1] + 1, p[2], p[3]) in s):
		heappush(que, [-sum([A[p[1] + 1], B[p[2]], C[p[3]]]), p[1] + 1, p[2], p[3]])
		s.add((p[1] + 1, p[2], p[3]))
	if p[2] < Y - 1 and (not (p[1], p[2] + 1, p[3]) in s):
		heappush(que, [-sum([A[p[1]], B[p[2] + 1], C[p[3]]]), p[1], p[2] + 1, p[3]])
		s.add((p[1], p[2] + 1, p[3]))
	if p[3] < Z - 1 and (not (p[1], p[2], p[3] + 1) in s):
		heappush(que, [-sum([A[p[1]], B[p[2]], C[p[3] + 1]]), p[1], p[2], p[3] + 1])
		s.add((p[1], p[2], p[3] + 1))


(X, Y, Z, K) = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
AB = [a + b for a in A for b in B]
AB.sort(reverse=True)
AB = AB[:min(3001, X * Y * Z + 1)]
ABC = [ab + c for ab in AB for c in C]
ABC.sort(reverse=True)
for i in range(K):
	print(ABC[i])


(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()))
tmp = []
for a in A:
	for b in B:
		tmp.append(a + b)
tmp.sort(reverse=True)
tmp = tmp[:K]
ans = []
for ab in tmp:
	for c in C:
		ans.append(ab + c)
ans.sort(reverse=True)
for i in range(K):
	print(ans[i])


from heapq import heappop, heappush
(x, y, z, k) = [int(i) for i in input().split()]
a_list = sorted([-int(i) for i in input().split()])
b_list = sorted([-int(i) for i in input().split()])
c_list = sorted([-int(i) for i in input().split()])
hq = []
flag_set = set()
heappush(hq, (a_list[0] + b_list[0] + c_list[0], 0, 0, 0))
flag_set.add((0, 0, 0))
for _ in range(k):
	(d, ai, bi, ci) = heappop(hq)
	print(-d)
	temp = (ai + 1, bi, ci)
	if temp[0] < x and temp not in flag_set:
		heappush(hq, (a_list[ai + 1] + b_list[bi] + c_list[ci], ai + 1, bi, ci))
		flag_set.add(temp)
	temp = (ai, bi + 1, ci)
	if temp[1] < y and temp not in flag_set:
		heappush(hq, (a_list[ai] + b_list[bi + 1] + c_list[ci], ai, bi + 1, ci))
		flag_set.add(temp)
	temp = (ai, bi, ci + 1)
	if temp[2] < z and temp not in flag_set:
		heappush(hq, (a_list[ai] + b_list[bi] + c_list[ci + 1], ai, bi, ci + 1))
		flag_set.add(temp)


(x, y, z, k) = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
lst = [a + b for a in A for b in B]
lst.sort(reverse=True)
lst = [e + c for e in lst[:k] for c in C]
lst.sort(reverse=True)
for i in range(k):
	print(lst[i])


import heapq
(X, Y, Z, K) = list(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)
done = {(0, 0, 0)}
hq = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
heapq.heapify(hq)
ans = 0
D = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
for _ in range(K):
	(s, i, j, k) = heapq.heappop(hq)
	print(-s)
	for d in D:
		(ni, nj, nk) = (i + d[0], j + d[1], k + d[2])
		if ni < X and nj < Y and (nk < Z) and ((ni, nj, nk) not in done):
			heapq.heappush(hq, (-(A[ni] + B[nj] + C[nk]), ni, nj, nk))
			done.add((ni, nj, nk))


import sys
from heapq import heappop, heappush
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(X, Y, Z, K) = map(int, readline().split())
	A = list(map(int, readline().split()))
	B = list(map(int, readline().split()))
	C = list(map(int, readline().split()))
	A.sort(reverse=True)
	B.sort(reverse=True)
	C.sort(reverse=True)
	hq = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
	ans = [0] * K
	added = {(0, 0, 0)}
	for idx in range(K):
		(taste, i, j, k) = heappop(hq)
		ans[idx] = -taste
		if i < X - 1 and (i + 1, j, k) not in added:
			heappush(hq, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))
			added.add((i + 1, j, k))
		if j < Y - 1 and (i, j + 1, k) not in added:
			heappush(hq, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))
			added.add((i, j + 1, k))
		if k < Z - 1 and (i, j, k + 1) not in added:
			heappush(hq, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))
			added.add((i, j, k + 1))
	print(*ans, sep='\n')
	return

def __starting_point():
	main()
__starting_point()


from heapq import heappush, heappop
(X, Y, Z, K, *L) = map(int, open(0).read().split())
A = L[:X]
B = L[X:X + Y]
C = L[X + Y:]
ab = []
for i in range(X):
	for j in range(Y):
		ab += [A[i] + B[j]]
ab.sort(reverse=True)
ls = []
for i in range(Z):
	heappush(ls, (-ab[0] - C[i], i, 0))
for i in range(K):
	(m, j, cnt) = heappop(ls)
	print(-m)
	if cnt + 1 < X * Y:
		heappush(ls, (-ab[cnt + 1] - C[j], j, cnt + 1))


import sys
input = sys.stdin.readline
(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()))
AB = []
for a in A:
	for b in B:
		AB.append(a + b)
AB.sort(reverse=True)
AB = AB[:K]
ALL = []
for ab in AB:
	for c in C:
		ALL.append(ab + c)
ALL.sort(reverse=True)
for k in range(K):
	print(ALL[k])


(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()))
AB = [0] * (X * Y)
t = 0
for i in A:
	for j in B:
		AB[t] = i + j
		t += 1
AB.sort(reverse=True)
ABA = AB[0:min(K, X * Y)]
D = [0] * (Z * len(ABA))
t = 0
for i in ABA:
	for j in C:
		D[t] = i + j
		t += 1
D.sort(reverse=True)
for i in range(K):
	print(D[i])


(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 a:
	for j in b:
		e.append(i + j)
e = sorted(e, reverse=True)[:k]
ans = []
for i in e:
	for j in c:
		ans.append(i + j)
ans = sorted(ans, reverse=True)[:k]
for i in ans:
	print(i)


from heapq import nlargest
(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()))
AB = nlargest(k, (a + b for a in A for b in B))
ABC = nlargest(k, (ab + c for ab in AB for c in C))
[print(abc) for abc in ABC]


from itertools import product
(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()))
AB = sorted([a + b for (a, b) in product(A, B)], reverse=True)[:K]
ans = sorted([a + b for (a, b) in product(AB, C)], reverse=True)[:K]
for i in ans:
	print(i)


(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()))
bc = [i + j for i in b for j in c]
bc.sort(reverse=True)
abc = [i + j for i in a for j in bc[:min(k, len(bc))]]
abc.sort(reverse=True)
for i in range(k):
	print(abc[i])


import heapq
import sys
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def input():
	return sys.stdin.readline().strip()

def main():
	(X, Y, Z, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(map(int, input().split()))
	A.sort(reverse=True)
	B.sort(reverse=True)
	C.sort(reverse=True)

	def bfs():
		used = set()
		used.add((0, 0, 0))
		q = []
		heapq.heapify(q)
		heapq.heappush(q, (-(A[0] + B[0] + C[0]), 0, 0, 0))
		res = []
		while q:
			(v, i, j, k) = heapq.heappop(q)
			res.append(-v)
			if len(res) == K:
				return res
			for (di, dj, dk) in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]:
				ni = i + di
				nj = j + dj
				nk = k + dk
				if ni >= X or nj >= Y or nk >= Z:
					continue
				if (ni, nj, nk) in used:
					continue
				used.add((ni, nj, nk))
				heapq.heappush(q, (-(A[ni] + B[nj] + C[nk]), ni, nj, nk))
		return res
	res = bfs()
	res.sort(reverse=True)
	for i in range(K):
		print(res[i])

def __starting_point():
	main()
__starting_point()


(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)
L = []
for i in range(min(x, k)):
	for j in range(min(y, k // (i + 1))):
		for l in range(min(z, k // (i + 1) // (j + 1))):
			L.append(A[i] + B[j] + C[l])
print(*sorted(L)[::-1][:k], sep='\n')


(X, Y, Z, K) = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
B = [int(x) for x in input().split()]
B.sort(reverse=True)
C = [int(x) for x in input().split()]
C.sort(reverse=True)
D = [a + b for a in A for b in B]
D.sort(reverse=True)
D = D[:3000]
E = [ab + c for ab in D for c in C]
E.sort(reverse=True)
for i in range(K):
	print(E[i])


(x, y, z, k) = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
(a, b, c) = (0, 0, 0)
AB = []
for a in A:
	for b in B:
		AB.append(a + b)
AB.sort(reverse=True)
AB = AB[:k]
ABC = []
for ab in AB:
	for c in C:
		ABC.append(ab + c)
ABC.sort(reverse=True)
print(*ABC[:k], sep='\n')


(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)
sumAB = sorted([ai + bi for ai in a for bi in b], reverse=True)[:k]
sumABC = sorted([ci + abi for ci in c for abi in sumAB], reverse=True)[:k]
for i in range(k):
	print(sumABC[i])


(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()))
L = []
for i in A:
	for j in B:
		L.append(i + j)
S = sorted(L, reverse=True)[:k]
T = []
for i in S:
	for j in sorted(C, reverse=True)[:k]:
		T.append(i + j)
print(*sorted(T, reverse=True)[:k], sep='\n')


(x, y, z, k, *L) = map(int, open(0).read().split())
a = L[:x]
b = L[x:x + y]
c = sorted(L[x + y:])[::-1]
ab = sorted((i + j for i in a for j in b))[::-1][:min(x * y, k)]
print(*sorted((i + j for i in ab for j in c))[::-1][:k], sep='\n')


(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()))
AB = []
for i in range(x):
	for j in range(y):
		AB.append(A[i] + B[j])
AB.sort(reverse=True)
ABC = []
for i in range(min(k, x * y)):
	for j in range(z):
		ABC.append(AB[i] + C[j])
ABC.sort(reverse=True)
for i in range(min(k, x * y * z)):
	print(ABC[i])


import sys
from heapq import heappush, heappop
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(X, Y, Z, K) = list(map(int, readline().split()))
	A = list(map(int, readline().split()))
	B = list(map(int, readline().split()))
	C = list(map(int, readline().split()))
	A.sort(reverse=True)
	B.sort(reverse=True)
	C.sort(reverse=True)
	hq = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
	seen = set()
	ans = []
	while len(ans) < K:
		(s, i, j, k) = heappop(hq)
		ans.append(-s)
		if i < X - 1 and (i + 1, j, k) not in seen:
			heappush(hq, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))
			seen.add((i + 1, j, k))
		if j < Y - 1 and (i, j + 1, k) not in seen:
			heappush(hq, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))
			seen.add((i, j + 1, k))
		if k < Z - 1 and (i, j, k + 1) not in seen:
			heappush(hq, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))
			seen.add((i, j, k + 1))
	print('\n'.join(map(str, ans)))
	return

def __starting_point():
	main()
__starting_point()


(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())))
aa = []
for i in a:
	for j in b:
		aa.append(i + j)
aa.sort(reverse=1)
aa = aa[:k + 1]
s = []
for i in aa:
	for j in c:
		s.append(i + j)
s.sort(reverse=1)
for i in range(k):
	print(s[i])


from itertools import product
import sys
try:
	from typing import List
except ImportError:
	pass

def solve(X: int, Y: int, Z: int, K: int, A: 'List[int]', B: 'List[int]', C: 'List[int]'):
	z = [0]

	def f(a: 'List[int]'):
		nonlocal z
		a.sort(reverse=True)
		z = [zi + ai for (zi, ai) in product(z, a[:K])]
		z.sort(reverse=True)
		z = z[:K]
	f(A)
	f(B)
	f(C)
	for zi in z:
		print(zi)

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	X = int(next(tokens))
	Y = int(next(tokens))
	Z = int(next(tokens))
	K = int(next(tokens))
	A = [int(next(tokens)) for _ in range(X)]
	B = [int(next(tokens)) for _ in range(Y)]
	C = [int(next(tokens)) for _ in range(Z)]
	solve(X, Y, Z, K, A, B, C)

def __starting_point():
	main()
__starting_point()


(x, y, z, k) = map(int, input().split())
alst = list(map(int, input().split()))
blst = list(map(int, input().split()))
clst = list(map(int, input().split()))
alst.sort(reverse=True)
blst.sort(reverse=True)
clst.sort(reverse=True)
ans = []
for i in range(x):
	for j in range(y):
		if i * j > k:
			break
		for l in range(z):
			if i * j * l > k:
				break
			ans.append(alst[i] + blst[j] + clst[l])
ans.sort(reverse=True)
print(*ans[:k], sep='\n')


import math
from math import gcd, pi, sqrt
INF = float('inf')
MOD = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
import bisect
from collections import Counter, deque

def i_input():
	return int(input())

def i_map():
	return map(int, input().split())

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]

def main():
	import heapq
	(X, Y, Z, K) = i_map()
	A = i_list()
	B = i_list()
	C = i_list()
	A.sort(reverse=True)
	B.sort(reverse=True)
	C.sort(reverse=True)
	Q = []
	heapq.heappush(Q, [-(A[0] + B[0] + C[0]), 0, 0, 0])
	added_idx = set((0, 0, 0))
	for i in range(K):
		(nega_ans, x, y, z) = heapq.heappop(Q)
		print(-nega_ans)
		if x + 1 < X and (x + 1, y, z) not in added_idx:
			heapq.heappush(Q, [-(A[x + 1] + B[y] + C[z]), x + 1, y, z])
			added_idx.add((x + 1, y, z))
		if y + 1 < Y and (x, y + 1, z) not in added_idx:
			heapq.heappush(Q, [-(A[x] + B[y + 1] + C[z]), x, y + 1, z])
			added_idx.add((x, y + 1, z))
		if z + 1 < Z and (x, y, z + 1) not in added_idx:
			heapq.heappush(Q, [-(A[x] + B[y] + C[z + 1]), x, y, z + 1])
			added_idx.add((x, y, z + 1))

def __starting_point():
	main()
__starting_point()


from heapq import *
(x, y, z, k) = map(int, input().split())
(A, B, C) = [list(map(int, input().split())) for n in range(3)]
D = nlargest(k, (a + b for a in A for b in B))
E = nlargest(k, (d + c for d in D for c in C))
print('\n'.join(map(str, E)))


(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()))
tmp = []
for i in range(x):
	for j in range(y):
		tmp.append(a[i] + b[j])
tmp.sort()
tmp2 = []
for i in range(min(k, x * y)):
	for j in range(z):
		tmp2.append(tmp[-1 - i] + c[j])
tmp2.sort()
for i in range(k):
	print(tmp2[-1 - i])


import itertools
(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()))
d = list(sorted(map(sum, itertools.product(a, b)), reverse=True))
c.sort(reverse=True)
e = list(sorted(map(sum, itertools.product(c[:k], d[:k])), reverse=True))
for v in e[:k]:
	print(v)


from heapq import *

def solve():
	(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()))
	A.sort(reverse=True)
	B.sort(reverse=True)
	C.sort(reverse=True)
	a = []
	heapify(a)
	ans = []
	for i in range(X):
		for j in range(Y):
			if (i + 1) * (j + 1) > K:
				break
			for k in range(Z):
				if (i + 1) * (j + 1) * (k + 1) > K:
					break
				heappush(a, -A[i] - B[j] - C[k])
	for _ in range(K):
		ans.append(-heappop(a))
	return ans
print(*solve(), sep='\n')


import sys
readline = sys.stdin.readline
(X, Y, Z, K) = map(int, readline().split())
A = sorted(list(map(int, readline().split())), reverse=True)
B = sorted(list(map(int, readline().split())), reverse=True)
C = sorted(list(map(int, readline().split())), reverse=True)
ans = []
for a in range(len(A)):
	for b in range(len(B)):
		for c in range(len(C)):
			if (a + 1) * (b + 1) * (c + 1) > K:
				break
			ans += [A[a] + B[b] + C[c]]
ans = sorted(ans, reverse=True)[:K]
print(*ans, sep='\n')


from heapq import heappop, heappush
(X, Y, Z, K) = map(int, input().split())
(*A,) = map(int, input().split())
(*B,) = map(int, input().split())
(*C,) = map(int, input().split())
A.sort(reverse=True)
D = [i + j for j in C for i in B]
D.sort(reverse=True)
q = []
for i in A[:K]:
	for j in D[:K]:
		heappush(q, -(i + j))
for _ in range(K):
	print(-heappop(q))


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10 ** 9))
write = lambda x: sys.stdout.write(x + '\n')
import numpy as np
(x, y, z, K) = list(map(int, input().split()))
a = np.array(list(map(int, input().split())), dtype=np.int64)
b = np.array(list(map(int, input().split())), dtype=np.int64)
c = np.array(list(map(int, input().split())), dtype=np.int64)
ab = (a + b.reshape(-1, 1)).reshape(-1)
ab.sort()
c.sort()
abk = ab[-K:]
ck = c[-K:]
l = (abk + ck.reshape(-1, 1)).reshape(-1)
l.sort()
l = l[::-1]
write('\n'.join(map(str, l[:K])))


(X, Y, Z, K) = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
AB = sorted([a + b for a in A for b in B], reverse=True)[:K]
ABC = sorted([ab + c for ab in AB for c in C], reverse=True)[:K]
for a in ABC:
	print(a)


import sys
input = sys.stdin.readline
from itertools import product

def read():
	(X, Y, Z, K) = list(map(int, input().strip().split()))
	A = list(map(int, input().strip().split()))
	B = list(map(int, input().strip().split()))
	C = list(map(int, input().strip().split()))
	return (X, Y, Z, K, A, B, C)

def solve(X, Y, Z, K, A, B, C, INF=10000000001):
	AB = [a + b for (a, b) in product(A, B)]
	AB.sort(reverse=True)
	AB = AB[:K]
	C.sort(reverse=True)
	D = [AB[k] + C[0] for k in range(len(AB))]
	E = [0 for k in range(len(AB))]
	j = 0
	for k in range(K):
		hi = 0
		for i in range(len(D)):
			if D[hi] < D[i]:
				hi = i
		print(D[hi])
		E[hi] += 1
		if E[hi] >= len(C):
			D[hi] = -INF
		else:
			D[hi] = AB[hi] + C[E[hi]]

def __starting_point():
	inputs = read()
	solve(*inputs)
__starting_point()


(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()))
AB = []
for i in A:
	for j in B:
		AB.append(i + j)
AB = sorted(AB, reverse=True)[:K]
ABC = []
for i in AB:
	for j in C:
		ABC.append(i + j)
ABC = sorted(ABC, reverse=True)[:K]
for a in ABC:
	print(a)


import heapq
from collections import defaultdict
(x, y, z, K) = list(map(int, input().split()))
A = sorted(map(int, input().split()), reverse=True)
B = sorted(map(int, input().split()), reverse=True)
C = sorted(map(int, input().split()), reverse=True)
visited = defaultdict(bool)
Q = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
for _ in range(K):
	(S, i, j, k) = heapq.heappop(Q)
	print(-S)
	if i + 1 < x and (not visited[i + 1, j, k]):
		heapq.heappush(Q, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))
		visited[i + 1, j, k] = True
	if j + 1 < y and (not visited[i, j + 1, k]):
		heapq.heappush(Q, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))
		visited[i, j + 1, k] = True
	if k + 1 < z and (not visited[i, j, k + 1]):
		heapq.heappush(Q, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))
		visited[i, j, k + 1] = True


import heapq
import itertools
(x, y, z, k) = map(int, input().split())
A = list((int(a) for a in input().split()))
B = list((int(b) for b in input().split()))
C = list((int(c) for c in input().split()))
hq = []
for (i, j) in itertools.product(A, B):
	heapq.heappush(hq, (i + j) * -1)
AB = []
while len(hq) > 0 and len(AB) <= k:
	AB.append(heapq.heappop(hq) * -1)
hq = []
for (i, j) in itertools.product(AB, C):
	heapq.heappush(hq, (i + j) * -1)
for _ in range(k):
	print(heapq.heappop(hq) * -1)


def getlist():
	return list(map(int, input().split()))
(X, Y, Z, K) = getlist()
A = getlist()
B = getlist()
C = getlist()
L = []
for i in A:
	for j in B:
		L.append(i + j)
L = sorted(L)
l = []
n = min(len(L), K)
for i in range(n):
	l.append(L[-1 - i])
ans = []
for i in l:
	for j in C:
		ans.append(i + j)
ans = sorted(ans)
for i in range(K):
	print(ans[-1 - i])


import heapq
import itertools
(x, y, z, k) = list(map(int, input().split()))
A = list((int(a) for a in input().split()))
B = list((int(b) for b in input().split()))
C = list((int(c) for c in input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
hq = []
for i in range(x):
	for j in range(y):
		for l in range(z):
			if (i + 1) * (j + 1) * (l + 1) <= k:
				heapq.heappush(hq, (A[i] + B[j] + C[l]) * -1)
			else:
				break
for _ in range(k):
	print(heapq.heappop(hq) * -1)


from itertools import combinations, product
(*_, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ab = []
for (i, j) in product(a, b):
	ab.append(i + j)
ab.sort(reverse=True)
ab = ab[:k]
abc = []
for (i, j) in product(ab, c):
	abc.append(i + j)
abc.sort(reverse=True)
print(*abc[:k], sep='\n')


(X, Y, Z, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
AB = [A[i] + B[j] for i in range(X) for j in range(Y)]
AB = sorted(AB, reverse=True)[:K]
ABC = [AB[i] + C[j] for i in range(len(AB)) for j in range(Z)]
ABC = sorted(ABC, reverse=True)[:K]
for one in ABC:
	print(one)


from heapq import heapify, heappop, heappush, heappushpop

class PriorityQueue:

	def __init__(self, heap):
		self.heap = heap
		heapify(self.heap)

	def push(self, item):
		heappush(self.heap, item)

	def pop(self):
		return heappop(self.heap)

	def pushpop(self, item):
		return heappushpop(self.heap, item)

	def __call__(self):
		return self.heap

	def __len__(self):
		return len(self.heap)
(x, y, z, k) = list(map(int, input().split()))
a_ls = list(map(int, input().split()))
b_ls = list(map(int, input().split()))
c_ls = list(map(int, input().split()))
a_ls.sort()
a_ls.reverse()
b_ls.sort()
b_ls.reverse()
c_ls.sort()
c_ls.reverse()
heap = []
q = PriorityQueue(heap)
q.push((-(a_ls[0] + b_ls[0] + c_ls[0]), 0, 0, 0))
considered = set()
for i in range(k):
	(val, i, j, k) = q.pop()
	print(-val)
	for (di, dj, dk) in zip([1, 0, 0], [0, 1, 0], [0, 0, 1]):
		ni = i + di
		nj = j + dj
		nk = k + dk
		if ni >= x or nj >= y or nk >= z:
			continue
		if (ni, nj, nk) not in considered:
			considered.add((ni, nj, nk))
			q.push((-(a_ls[ni] + b_ls[nj] + c_ls[nk]), ni, nj, nk))


(a, b, c, k) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = list(map(int, input().split()))
xy = []
for x0 in x:
	for y0 in y:
		xy.append(x0 + y0)
xy.sort(reverse=True)
if a * b > 3000:
	xy = xy[:3000]
xyz = []
for xy0 in xy:
	for z0 in z:
		xyz.append(xy0 + z0)
xyz.sort(reverse=True)
for i in range(k):
	print(xyz[i])


import sys
input = sys.stdin.readline
import heapq
from collections import defaultdict

def read():
	(X, Y, Z, K) = list(map(int, input().strip().split()))
	A = list(map(int, input().strip().split()))
	B = list(map(int, input().strip().split()))
	C = list(map(int, input().strip().split()))
	return (X, Y, Z, K, A, B, C)

def solve(X, Y, Z, K, A, B, C, INF=10000000001):
	A.sort(reverse=True)
	B.sort(reverse=True)
	C.sort(reverse=True)
	used = defaultdict(bool)
	h = []
	(p, q, r) = (0, 0, 0)
	heapq.heappush(h, (-A[p] - B[q] - C[r], p, q, r))
	used[p, q, r] = True
	for k in range(K):
		(a, p, q, r) = heapq.heappop(h)
		print(-a)
		if p + 1 < len(A) and (not used[p + 1, q, r]):
			heapq.heappush(h, (-A[p + 1] - B[q] - C[r], p + 1, q, r))
			used[p + 1, q, r] = True
		if q + 1 < len(B) and (not used[p, q + 1, r]):
			heapq.heappush(h, (-A[p] - B[q + 1] - C[r], p, q + 1, r))
			used[p, q + 1, r] = True
		if r + 1 < len(C) and (not used[p, q, r + 1]):
			heapq.heappush(h, (-A[p] - B[q] - C[r + 1], p, q, r + 1))
			used[p, q, r + 1] = True

def __starting_point():
	inputs = read()
	solve(*inputs)
__starting_point()


import heapq
(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()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
q = []
s = set()
heapq.heappush(q, (-a[0] - b[0] - c[0], 0, 0, 0))
for i in range(k):
	(ans, ai, bi, ci) = heapq.heappop(q)
	print(-ans)
	if ai < x - 1 and (ai + 1, bi, ci) not in s:
		heapq.heappush(q, (-a[ai + 1] - b[bi] - c[ci], ai + 1, bi, ci))
		s.add((ai + 1, bi, ci))
	if bi < y - 1 and (ai, bi + 1, ci) not in s:
		heapq.heappush(q, (-a[ai] - b[bi + 1] - c[ci], ai, bi + 1, ci))
		s.add((ai, bi + 1, ci))
	if ci < z - 1 and (ai, bi, ci + 1) not in s:
		heapq.heappush(q, (-a[ai] - b[bi] - c[ci + 1], ai, bi, ci + 1))
		s.add((ai, bi, ci + 1))


(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()))
AB = [a + b for a in A for b in B]
AB.sort()
AB = AB[-K:]
ans = [ab + c for ab in AB for c in C]
ans.sort()
for x in ans[-K:][::-1]:
	print(x)


from itertools import product
(X, Y, Z, K) = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
BC = [i + j for (i, j) in list(product(B, C))]
BC.sort(reverse=True)
ans = [i + j for (i, j) in list(product(BC[:min(3000, X * Y * Z)], A))]
ans.sort(reverse=True)
[print(ans[i]) for i in range(K)]


(X, Y, Z, K) = list(map(int, input().split()))
A = [sorted(list(map(int, input().split())))[::-1] for i in range(3)]
b = sorted([i + j for i in A[0] for j in A[1]])[-K:]
for i in sorted([i + j for i in b for j in A[2]])[-K:][::-1]:
	print(i)


(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()))
result = []

def func1():
	E = [a + b for a in A for b in B]
	E.sort()
	if len(E) > k:
		E = E[-k:]
	F = [c + e for c in C for e in E]
	F.sort()
	return F[-k:][::-1]
[print(val) for val in func1()]


(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()))
a.sort(reverse=True)
bc = [x + y for y in c for x in b]
bc.sort(reverse=True)
ans = [x + y for y in a for x in bc[:k]]
ans.sort(reverse=True)
print(*ans[:k], sep='\n')


import heapq
(X, Y, Z, K) = map(int, input().split())
A = list(map(lambda x: -1 * int(x), input().split()))
B = list(map(lambda x: -1 * int(x), input().split()))
C = list(map(lambda x: -1 * int(x), input().split()))
A.sort()
B.sort()
C.sort()
Q = []
heapq.heappush(Q, (A[0] + B[0] + C[0], 0, 0, 0))
for _ in range(K):
	(SUM, a, b, c) = heapq.heappop(Q)
	print(-1 * SUM)
	if a <= X - 2 and (not (A[a + 1] + B[b] + C[c], a + 1, b, c) in Q):
		heapq.heappush(Q, (A[a + 1] + B[b] + C[c], a + 1, b, c))
	if b <= Y - 2 and (not (A[a] + B[b + 1] + C[c], a, b + 1, c) in Q):
		heapq.heappush(Q, (A[a] + B[b + 1] + C[c], a, b + 1, c))
	if c <= Z - 2 and (not (A[a] + B[b] + C[c + 1], a, b, c + 1) in Q):
		heapq.heappush(Q, (A[a] + B[b] + C[c + 1], a, b, c + 1))


r = range
(x, y, z, k) = map(int, input().split())
(a, b, c) = eval('sorted(list(map(int,input().split())),reverse=True),' * 3)
abc = []
for l in r(x):
	for m in r(y):
		if -~l * -~m > k:
			break
		for n in r(z):
			if -~l * -~m * -~n > k:
				break
			abc += [a[l] + b[m] + c[n]]
print(*sorted(abc, reverse=True)[:k])


(x, y, z, k) = map(int, input().split())
(a, b, c) = [list(map(int, input().split())) for i in range(3)]
l = sorted([bb + cc for bb in b for cc in c], reverse=1)[:k]
t = sorted([ll + aa for aa in a for ll in l], reverse=1)
for i in range(k):
	print(t[i])


(x, y, z, k) = map(int, input().split())
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]
Z = [int(i) for i in input().split()]
X.sort(reverse=1)
Y.sort(reverse=1)
Z.sort(reverse=1)
answer = [i + j for i in X[:k] for j in Y[:k]]
answer.sort(reverse=1)
answer2 = [i + j for i in Z[:k] for j in answer[:k]]
answer2.sort(reverse=1)
for p in answer2[:k]:
	print(p)