Problem:
 Score: 400 points    Problem Statement  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 1 2 2 2 8
4 6
1 5
3 8      Sample Output 1 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        Sample Input 2 3 3 3 5
1 10 100
2 20 200
1 10 100      Sample Output 2 400
310
310
301
301  There may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and the sum of A_3, B_3, C_1 are both 301 .
However, they are different ways of choosing cakes, so 301 occurs twice in the output.       Sample Input 3 10 10 10 20
7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488
1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338
4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736      Sample Output 3 23379871545
22444657051
22302177772
22095691512
21667941469
21366963278
21287912315
21279176669
21160477018
21085311041
21059876163
21017997739
20703329561
20702387965
20590247696
20383761436
20343962175
20254073196
20210218542
20150096547  Note that the input or output may not fit into a 32 -bit integer type.

Solution (Python):
import sys
input = sys.stdin.readline

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)

res = []

for a in A:
    for b in B:
        res.append(a+b)

res.sort(reverse=True)

res = res[:K]
ans = []

for ab in res:
    for c in C:
        ans.append(ab+c)
    
ans.sort(reverse=True)
ans = ans[:K]

for a in ans:
    print(a)

Solution (Python):
import heapq
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)]
used = set()
while K:
    s, i, j, k = heapq.heappop(que)
    if i + 1 < X and (i + 1, j, k) not in used:
        heapq.heappush(que, (-A[i + 1] - B[j] - C[k], i + 1, j, k))
        used.add((i + 1, j, k))
    if j + 1 < Y and (i, j + 1, k) not in used:
        heapq.heappush(que, (-A[i] - B[j + 1] - C[k], i, j + 1, k))
        used.add((i, j + 1, k))
    if k + 1 < Z and (i, j, k + 1) not in used:
        heapq.heappush(que, (-A[i] - B[j] - C[k + 1], i, j, k + 1))
        used.add((i, j, k + 1))
    s = -s
    print(s)
    K -= 1

Solution (Python):
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)




AB = []
ABC = []
for b in B:
    for a in A:
        AB.append(a+b)
AB.sort(reverse=True)
AB = AB[:K+1]


for c in C:
    for ab in AB:
        ABC.append(ab+c)
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])

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

Solution (Python):
x,y,z,k = map(int,input().split())
a = []
for i in input().split():
	a.append(int(i))
b = []
for i in input().split():
	b.append(int(i))
c = []
for i in input().split():
	c.append(int(i))





a_bsum = []

for i in range(x):
	for j in range(y):
			a_bsum.append(a[i]+b[j])
a_bsum.sort()
a_bsum.reverse()

a_bsum = a_bsum[0:k]

sum = []

c.sort()
c.reverse()
c = c[0:k]

for i in a_bsum:
	for j in c:
		sum.append(i+j)

sum.sort()
sum.reverse()

for i in range(k):
	print(sum[i])

Solution (Python):
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)))

Solution (Python):
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)

l=[]
for s in range(x):
    for t in range(y):
        for u in range(z):
            if (s+1)*(t+1)*(u+1)<= k:
                l.append(a[s]+b[t]+c[u])
            else:
                break
l.sort(reverse=True)
for i in range(k):
    print(l[i])

Solution (Python):
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)

apb =  []

for a in A:
    for b in B:
        apb.append(a+b)
apb.sort(reverse=True)

apb = apb[:K]
ans = []

for k in apb:
    for c in (C):
        ans.append(k+c)
ans.sort(reverse=True)

for k in range(K):
    print(ans[k])

Solution (Python):
import sys
X, Y, Z, K = map(int,input().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().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])

Solution (Python):
import sys,heapq
R=lambda:map(int,sys.stdin.readline().split())
x=list(R())
k=x.pop()
a=[sorted(R())for _ in range(3)]
h=set()
q=[[-sum(e[-1] for e in a)]+[e-1 for e in x]]
for _ in range(k):
	y=heapq.heappop(q)
	x=y.pop(0)
	print(-x)
	for i in range(3):
		ny=list(y)
		ny[i]-=1
		if y[i] and tuple(ny) not in h:
			h.add(tuple(ny))
			heapq.heappush(q,[x+a[i][y[i]]-a[i][y[i]-1]]+ny)

Solution (Python):
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])

Solution (Python):
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)

AB = []
ABC = []
for b in B:
    for a in A:
        AB.append(a+b)
AB.sort(reverse=True)

AB = AB[:min(3001, X*Y*Z+1)]

for c in C:
    for ab in AB:
        ABC.append(ab+c)
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])

Solution (Python):
import sys
X, Y, Z, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
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])

Solution (Python):

import itertools
import sys
import math
from functools import lru_cache





from queue import Queue
from operator import mul
from functools import reduce
from queue import Queue
from operator import mul
from functools import reduce
from functools import lru_cache

input = sys.stdin.readline


x, y, z, kk = 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)


ll = []
count = 0
for i in range(len(a)):
    for j in range(len(b)):
        if i * j > kk:

            break
        for k in range(len(c)):
            if i * j * k > kk:
                break
            ll.append(a[i] + b[j] + c[k])
ll.sort(reverse=True)

for i in range(kk):
    print(ll[i])

Solution (Python):
import sys
X, Y, Z, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
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])

Solution (Python):
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)
hq=[]
heapq.heappush(hq,(-(A[0]+B[0]+C[0]),0,0,0))
searched={(0,0,0)}
a,b,c=0,0,0
D=((1,0,0),(0,1,0),(0,0,1))
for _ in range(k):
    abc,a,b,c=heapq.heappop(hq)
    print(-abc)
    for dx,dy,dz in D:
        if not (a+dx,b+dy,c+dz) in searched:
            if a+dx<x and b+dy<y and c+dz<z:
                heapq.heappush(hq,(-(A[a+dx]+B[b+dy]+C[c+dz]),a+dx,b+dy,c+dz))
                searched.add((a+dx,b+dy,c+dz))

Solution (Python):
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)
hq=[]
heapq.heappush(hq,(-(A[0]+B[0]+C[0]),0,0,0))
searched={(0,0,0)}
a,b,c=0,0,0
D=((1,0,0),(0,1,0),(0,0,1))
for _ in range(k):
    abc,a,b,c=heapq.heappop(hq)
    print(-abc)
    for dx,dy,dz in D:
        if not (a+dx,b+dy,c+dz) in searched:
            if a+dx<x and b+dy<y and c+dz<z:
                heapq.heappush(hq,(-(A[a+dx]+B[b+dy]+C[c+dz]),a+dx,b+dy,c+dz))
                searched.add((a+dx,b+dy,c+dz))

Solution (Python):
import heapq

x, y, z, k = map(int, raw_input().split())
a = sorted(map(int, raw_input().split()))
b = sorted(map(int, raw_input().split()))
c = sorted(map(int, raw_input().split()))

q = []
memo = set()
def qpush(q, ai, bi, ci):
    if ai >= 0 and bi >= 0 and ci >= 0:
        t = (-(a[ai] + b[bi] + c[ci]), ai, bi, ci)
        if not t in memo:
            memo.add(t)
            heapq.heappush(q, t)

qpush(q, len(a) - 1, len(b) - 1, len(c) - 1)
for _ in range(k):
    s, ai, bi, ci = heapq.heappop(q)
    qpush(q, ai - 1, bi, ci)
    qpush(q, ai, bi - 1, ci)
    qpush(q, ai, bi, ci - 1)
    print -s

Solution (Python):

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])

Solution (Python):
a,b,c,k = map(int,input().split())

aa = list(map(int,input().split()))
aa.sort(reverse = True)
bb = list(map(int,input().split()))
bb.sort(reverse = True)
cc = list(map(int,input().split()))
cc.sort(reverse = True)
al = []
aal = []
for i in aa:
    for j in bb:
        al.append(i+j)
al.sort()
if len(al) > k:
    al = al[len(al)-k:]

for i in al:
    for j in cc:
        aal.append(i+j)
aal.sort()

if len(aal) > k:
    aal = aal[len(aal)-k:]
aal.reverse()
for i in aal:
    print(i)

Solution (Python):
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)

temp = []
for a in A:
	for b in B:
		temp.append(a+b)

temp = sorted(temp, reverse=True)
temp = temp[:K]

ans = []
for c in C:
	for num in temp:
		ans.append(num+c)

ans = sorted(ans, reverse=True)
for i in range(K):
	print(ans[i])

Solution (Python):
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(list(map(str, ans[:K]))))

Solution (Python):

import numpy as np
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 = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for i in range(min(K,X)):
    for j in range(min((K//(i+1),Y))):
        for k in range(min(((K//(i+1)+1)//(j+1)),Z)):
            D.append(A[i]+B[j]+C[k])
D.sort(reverse=True)
for i in range(K):
    print(int(D[i]))

Solution (Python):
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)
b = sorted(b)
c = sorted(c)

la = []

for i in range(x):
    s = x-i
    for n in range(max(y-5-3000//s,0),y):
        u = y-n
        for m in range(max(z-5-3000//(s*u),0),z):
            
            la.append(a[i]+b[n]+c[m])

la = sorted(la)

for i in range(k):
    print(la[-i-1])

Solution (Python):
import numpy as np
import bisect
from collections import deque

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)

YZ = Y * Z

def createBitArray(X, Y, Z):
    size = X*Y*Z // 60 + 1
    return(np.zeros(size, 'int64'))

def getBit(R, a, b, c):
    pos = a * YZ + b * Z + c
    loc = pos // 60
    bit = 2 ** (pos % 60)
    return(R[loc] & bit)

def putBit(R, a, b, c):
    pos = a * YZ + b * Z + c
    loc = pos // 60
    bit = 2 ** (pos % 60)
    R[loc] = R[loc] | bit

R = createBitArray(X, Y, Z)

l = []
m = []

M = A[0] + B[0] + C[0]
position = bisect.bisect(l, M)
bisect.insort(l, M)
m.insert(position, (0, 0, 0))
putBit(R, 0, 0, 0)

for i in range(K):
    print(l[len(m)-1])

    a, b, c = m[len(m)-1]

    del l[len(m)-1]
    del m[len(m)-1]

    if a+1 < X and getBit(R, a+1, b, c) == 0:
        M = A[a+1] + B[b] + C[c]
        position = bisect.bisect(l, M)
        bisect.insort(l, M)
        m.insert(position, (a+1, b, c))
        putBit(R, a+1, b, c)

    if b+1 < Y and getBit(R, a, b+1, c) == 0:
        M = A[a] + B[b+1] + C[c]
        position = bisect.bisect(l, M)
        bisect.insort(l, M)
        m.insert(position, (a, b+1, c))
        putBit(R, a, b+1, c)

    if c+1 < Z and getBit(R, a, b, c+1) == 0:
        M = A[a] + B[b] + C[c+1]
        position = bisect.bisect(l, M)
        bisect.insort(l, M)
        m.insert(position, (a, b, c+1))
        putBit(R, a, b, c+1)

Solution (Python):
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)

ABC=[]
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1)<=K:
                ABC.append(A[i] + B[j] + C[k])
            else:
                break

ABC.sort(reverse=True)

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

Solution (Python):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

X,Y,Z,K=rl()
A=rl()
B=rl()
C=rl()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ans = []
for a in range(1,X+1):
    for b in range(1,Y+1):
        for c in range(1,Z+1):
            if a*b*c<=K:
                ans.append(A[a-1]+B[b-1]+C[c-1])
            else:
                break
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

Solution (Python):



import numpy as np
[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()))

D = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)


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

Solution (Python):
X,Y,Z,K=map(int,input().split())
Ax=sorted(list(map(int,input().split())), reverse=True)
By=sorted(list(map(int,input().split())), reverse=True)
Cz=sorted(list(map(int,input().split())), reverse=True)

a=b=c=0
s = set([(a,b,c)])
t = set()
for k in range(K):
    best_value = 0
    best_tuple = None
    for x,y,z in s:
        if (x,y,z) not in t:
            m = Ax[x]+By[y]+Cz[z]
            if m > best_value:
                best_value = m
                best_tuple = (x,y,z)
    print(best_value)

    t.add(best_tuple)
    s.remove(best_tuple)
    x,y,z=best_tuple
    if x < X-1:
        if (x+1,y,z) not in s:
            s.add((x+1,y,z))
    if y < Y-1:
        if (x,y+1,z) not in s:
            s.add((x,y+1,z))
    if z < Z-1:
        if (x,y,z+1) not in s:
            s.add((x,y,z+1))

Solution (Python):
x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
    for nu in lisa:
        an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Solution (Python):
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_total_list = []
total_list = []

A.sort()
A.reverse()
if len(A) > K:
    A = A[0:K+1]

B.sort()
B.reverse()
if len(B) > K:
    B = B[0:K+1]

C.sort()
C.reverse()
if len(C) > K:
    C = C[0:K+1]

ab_total_list = []
for i in A:
    for j in B:
        ab_total_list.append(i+j)

ab_total_list.sort()
ab_total_list.reverse()
if len(ab_total_list) > K:
    ab_total_list = ab_total_list[0:K+1]

for i in range(0, K):
    for j in range(0, int(K/(i+1))):
        if j >= len(C) or i >= len(ab_total_list):
            break
        total = ab_total_list[i] + C[j]
        total_list.append(total)
        if (i*j) > K:
            break

total_list.sort()
total_list.reverse()
for i in range(0, K):
    print(total_list[i])

Solution (Python):
import heapq

x, y, z, k = map(int, raw_input().split())
a = sorted(map(int, raw_input().split()))
b = sorted(map(int, raw_input().split()))
c = sorted(map(int, raw_input().split()))

q = []
memo = set()
def qpush(q, ai, bi, ci):
    t = (-(a[ai] + b[bi] + c[ci]), ai, bi, ci)
    if not t in memo:
        memo.add(t)
        heapq.heappush(q, t)

qpush(q, len(a) - 1, len(b) - 1, len(c) - 1)
for _ in range(k):
    s, ai, bi, ci = heapq.heappop(q)
    if ai > 0:
        qpush(q, ai - 1, bi, ci)
    if bi > 0:
        qpush(q, ai, bi - 1, ci)
    if ci > 0:
        qpush(q, ai, bi, ci - 1)
    print -s

Solution (Python):

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)


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])

Solution (Python):
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)
if k>x: a=a[:k]
if k>y: b=b[:k]
if k>z: c=c[:k]
d=[]
ans=[]
for i in a:
    for j in b:
        d.append(i+j)
d.sort(reverse=True)
if len(d)>k: d=d[:k]
for i in c:
    for j in d:
        ans.append(i+j)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Solution (Python):
x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
    for nu in lisa:
        an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Solution (Python):

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)

ans = []
for index_i, i in enumerate(a):
    for index_j, j in enumerate(b):
        for index_l, l in enumerate(c):
            if ((index_i+1)*(index_j+1)*(index_l+1) <= k):
                ans.append(i+j+l)
            else:
                break
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

Solution (Python):
x, y, z, kk = 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)

p = []
for i in range(x):
    for j in range(y):
        for k in range(z):
            if (i + 1) * (j + 1) * (k + 1) <= kk:
                p.append(a[i] + b[j] + c[k])
            else:
                break
p.sort(reverse=True)
for i in range(kk):
    print(p[i])

Solution (Python):

def main():
    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()]

    a.sort(reverse=True)
    b.sort(reverse=True)
    c.sort(reverse=True)

    ans = []

    for i in range(x):
        if i > k:
            break
        for j in range(y):
            if i * j > k:
                break
            for m in range(z):
                if i * j * m > k:
                    break
                ans.append(a[i]+b[j]+c[m])

    ans.sort(reverse=True)
    for i in range(k):
        print(ans[i])


main()

Solution (Python):
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)
k=min(K,X*Y)
AB=AB[:k]
ABC=[]
for i in range(k):
    for j in range(Z):
        ABC.append(AB[i]+C[j])
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])

Solution (Python):
import heapq
X,Y,Z,K=map(int,input().split())
A=sorted([-int(i) for i in input().split()])
B=sorted([-int(i) for i in input().split()])
C=sorted([-int(i) for i in input().split()])
q=[]
heapq.heappush(q,(A[0]+B[0]+C[0],0,0,0))
S={(0,0,0)}
for n in range(K):
    p,i,j,k=heapq.heappop(q)
    if i+1<X and not((i+1,j,k) in S):
        S.add((i+1,j,k))
        heapq.heappush(q,(A[i+1]+B[j]+C[k],i+1,j,k))
    if j+1<Y and not((i,j+1,k) in S):
        S.add((i,j+1,k))
        heapq.heappush(q,(A[i]+B[j+1]+C[k],i,j+1,k))
    if k+1<Z and not((i,j,k+1) in S):
        S.add((i,j,k+1))
        heapq.heappush(q,(A[i]+B[j]+C[k+1],i,j,k+1))
    print(-p)

Solution (Python):
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])

Solution (Python):



import numpy as np
[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()))

D = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)


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

Solution (Python):
from heapq import heappop, heappush

X, Y, Z, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
counted = set()
h = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]
for _ in range(K):
    s, i, j, k = heappop(h)
    print(-s)
    if X > i+1 and (i+1, j, k) not in counted:
        heappush(h, (-(A[i+1] + B[j] + C[k]), i+1, j, k))
        counted.add((i+1, j, k))
    if Y > j+1 and (i, j+1, k) not in counted:
        heappush(h, (-(A[i] + B[j+1] + C[k]), i, j+1, k))
        counted.add((i, j+1, k))
    if Z > k+1 and (i, j, k+1) not in counted:
        heappush(h, (-(A[i] + B[j] + C[k+1]), i, j, k+1))
        counted.add((i, j, k+1))

Solution (Python):
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)


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

ans = []
for ab in AB:
    for c in C:
        ans.append(ab + c)
        
ans.sort(reverse=True)
print(*ans[:K], sep='\n')

Solution (Python):
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])

Solution (Python):
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)[:k]
B = sorted(B,reverse=True)[:k]
C = sorted(C,reverse=True)[:k]

list_ans = []
for index_a,a in enumerate(A):
  for index_b,b in enumerate(B):
    for index_c,c in enumerate(C):
      if (index_a + 1) * (index_b + 1) * (index_c + 1) > k:
        break
      list_ans.append(a+b+c)


list_ans.sort(reverse=True)
for i in list_ans[:k]:
  print(i)

Solution (Python):
X, Y, Z, K = map(int, input().split())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
A = sorted(A)[::-1]
B = sorted(B)[::-1]
C = sorted(C)[::-1]

List = []

for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1) > K:
                break
            else:
                List.append(A[i]+B[j]+C[k])

List = sorted(List)[-1:-K-1:-1]
for i in range(K):
    print(List[i])

Solution (Python):
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])

Solution (Python):

import heapq
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
def li(): return map(int, stdin.readline().split())
i_a, i_b, i_c, K = tuple(li())
A = list(li())
B = list(li())
C = list(li())
A.sort()
B.sort()
C.sort()

memo = {}
heap = []
def val(a,b,c):
    if a<0 or b<0 or c<0:
        return False
    return A[a] + B[b] + C[c]
total = val(i_a-1, i_b-1, i_c-1)
heap = [(-total, i_a-1, i_b-1, i_c-1)]
while K > 0:
    K -= 1
    cur = heapq.heappop(heap)
    print(-cur[0])
    a,b,c = cur[1], cur[2], cur[3]
    if (a-1, b,c) not in memo:
        va = val(a-1,b,c)
        if va:
            memo[(a-1,b,c)] = True
            heapq.heappush(heap, [-va, a-1, b, c])
    if (a, b-1,c) not in memo:
        vb = val(a,b-1,c)
        if vb:
            memo[(a,b-1,c)] = True
            heapq.heappush(heap, [-vb, a, b-1, c])

    if (a, b,c-1) not in memo:
        vc = val(a,b,c-1)
        if vc:
            memo[(a,b,c-1)] = True
            heapq.heappush(heap, [-vc, a, b, c-1])

Solution (Python):
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])

Solution (Python):
from collections import deque
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()]

ABsum=[]
for i in A:
    for j in B:
        ABsum.append(i+j)
ABsum=sorted(list(ABsum),reverse=True)
sumu=[]
for i in range(min(K,X*Y)):
    for j in C:
        sumu.append(ABsum[i]+j)
sumu=sorted(list(sumu),reverse=True)
for i in range(K):
    print(sumu[i])

Solution (Python):
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)
t = []

for i in range(x):
    for j in range(y):
        for r in range(z):
            if (i+1)*(j+1)*(r+1) > k:
                break
            else:
                t.append(a[i]+b[j]+c[r])

t.sort(reverse = True)

for i in range(k):
    print(t[i])