CodeEff/ECCO huggingface dataset:
# Original solution
while 1:
    x,y,z=list(map(int,input().split()))
    if x==0 and y==0 and z==0:break
    v=list(map(int,input().split()))
    event=[[] for _ in range(y+1)]
    maxm=0
    for i in range(z):
        n,e,a=list(map(int,input().split()))
        event[n].append(e)
        event[n].append(a)
        if e==2:
            maxm+=a

    dp=[[0]*(5005) for _ in range(y+1)]
    dp[0][0]=1
    x=float(x)
    for i in range(y):
        for k in range(maxm+1):
            for j in range(int(x)):
                if i+v[j]>=y:
                    dp[y][k]+=dp[i][k]/x
                    continue

                if event[i+v[j]]==[]:
                    dp[i+v[j]][k]+=dp[i][k]/x

                elif event[i+v[j]][0]==1:
                    skip=event[i+v[j]][1]
                    dp[min(y,i+skip)][k]+=dp[i][k]/x

                elif event[i+v[j]][0]==2:
                    m=event[i+v[j]][1]
                    dp[i+v[j]][k+m]+=dp[i][k]/x

                else:
                    m=event[i+v[j]][1]
                    dp[i+v[j]][max(0,k-m)]+=dp[i][k]/x

    ans=0.0
    for i in range(maxm+1):
        ans+=dp[y][i]*i
    print((int(ans)))

# Optimized solution
def solve(x,y,maxm):
    for i in range(y):
        for j in range(maxm+1):
            if dp[i][j]==0:continue
            for k in range(int(x)):

                if event[min(y,i+v[k])][0]==0:
                    dp[min(y,i+v[k])][j]+=dp[i][j]/x

                elif event[i+v[k]][0]==1:
                    skip=event[i+v[k]][1]
                    dp[min(y,i+v[k]+skip)][j]+=dp[i][j]/x

                elif event[i+v[k]][0]==2:
                    m=event[i+v[k]][1]
                    dp[i+v[k]][j+m]+=dp[i][j]/x

                else:
                    m=event[i+v[k]][1]
                    dp[i+v[k]][max(0,j-m)]+=dp[i][j]/x
    return dp

while 1:
    x,y,z=list(map(int,input().split()))
    if x==0 and y==0 and z==0:break
    v=list(map(int,input().split()))
    event=[[0]*2 for _ in range(y+1)]
    maxm=0
    for i in range(z):
        n,e,a=list(map(int,input().split()))
        event[n][0]=e
        event[n][1]=a
        if e==2:
            maxm+=a

    dp=[[0]*(5005) for _ in range(y+1)]
    dp[0][0]=1
    x=float(x)
    dp=solve(x,y,maxm)
    ans=0.0
    for i in range(maxm+1):
        ans+=dp[y][i]*i
    print((int(ans)))
# Original solution
import sys
readline = sys.stdin.readline
X,Y,Z,K = list(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)

ab = []
for ai in a:
    for bj in b:
        ab.append(ai+bj)
ab.sort(reverse=True)
ab = ab[:K]
cond = []
for abi in ab:
    for cj in c:
        cond.append(abi+cj)
cond = sorted(cond, reverse=True)[:K]
for condi in cond:
    print(condi)


# Optimized solution
import sys
readline = sys.stdin.readline
X, Y, Z, K = list(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)

ABC = []
for a in range(X):
    for b in range(Y):
        if (a+1)*(b+1) > K:
            break
        for c in range(Z):
            if (a+1)*(b+1)*(c+1) > K:
                break
            ABC.append(A[a] + B[b] + C[c])
            
for ai in sorted(ABC, reverse=True)[:K]:
    print(ai)
# Original solution
x,y,z,k = list(map(int,input().split()))
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))

Alist.sort(reverse=True)
Blist.sort(reverse=True)
Clist.sort(reverse=True)

ABlist = []
for i in Alist[:k]:
    for j in Blist[:k]:
        ABlist.append(i + j)

ABlist.sort(reverse=True)

ABClist = []
for i in ABlist[:k]:
    for j in Clist[:k]:
        ABClist.append(i + j)

ABClist.sort(reverse=True)

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


# Optimized solution
x,y,z,k = map(int,input().split())
Alist = list(map(int,input().split()))
Blist = list(map(int,input().split()))
Clist = list(map(int,input().split()))

Alist.sort(reverse=True)
Blist.sort(reverse=True)
Clist.sort(reverse=True)

ABlist = [i + j for i in Alist[:k] for j in Blist[:k]]

ABlist.sort(reverse=True)

ABClist = [l + m for l in ABlist[:k] for m in Clist[:k]]

ABClist.sort(reverse=True)

print(*ABClist[:k], sep = '\n')
# Original solution
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    C.sort(reverse=True)
    
    count = 0
    AB = []

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

    ABC = []
    for k in range(Z):
        for ab_index in range(len(AB)):
            ABC.append(C[k]+AB[ab_index])

    ABC.sort(reverse=True)
    ABC = ABC[:K]
    for i in range(len(ABC)):
        print((ABC[i]))
    return


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

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    AB = []

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

    ABC = []
    for k in range(Z):
        for ab_index in range(len(AB)):
            ABC.append(C[k]+AB[ab_index])

    ABC.sort(reverse=True)
    ABC = ABC[:K]
    for i in range(len(ABC)):
        print((ABC[i]))
    return


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

if __name__ == '__main__':
    main()
# Original solution
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)
p = []
for i in a:
    for j in b:
        p.append(i+j)
p.sort(reverse=True)
p = p[:min(3001, x*y*z+1)]
q = []
for i in p:
    for j in c:
        q.append(i+j)
q.sort(reverse=True)
for i in range(k):
    print((q[i]))

# Optimized solution
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)
p = []
for i in a:
    for j in b:
        p.append(i+j)
p.sort(reverse=True)
p = p[:min(3001, x*y*z+1)]
q = []
for j in c:
    for i in p:
        q.append(i+j)
q.sort(reverse=True)
for i in range(k):
    print((q[i]))
# Original solution
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)
p = []
for h in range(min(x,k)):
    for i in range(y):
        if h*i <= k:
            for j in range(z):
                if h*i*j <= k:
                    p.append(a[h]+b[i]+c[j])

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

# Optimized solution
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)
p = []
for h in range(min(x,k)):
    for i in range(y):
        if h*i > k:
            break
        for j in range(z):
            if h*i*j > k:
                break
            p.append(a[h]+b[i]+c[j])

p.sort(reverse=True)
for i in range(k):
    print((p[i]))
# Original solution
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()))
sorted_abcsum = sorted([A[x] + B[y] + C[z] for x in range(X) for y in range(Y) for z in range(Z)],reverse=True)
for k in range(K):
    print((sorted_abcsum[k]))

# Optimized solution
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()))
asort,bsort,csort = sorted(A,reverse=True),sorted(B,reverse=True),sorted(C,reverse=True)
print((asort[0] + bsort[0] + csort[0]))
already = [[0,0,0]]
x,y,z = 0,0,0
place_sum = []
check = []
for k in range(K - 1):
    if [x + 1,y,z] not in already and x + 1 < X:
        already.append([x + 1,y,z])
        place_sum.append([x + 1,y,z])
        check.append(asort[x + 1] + bsort[y] + csort[z])
    if [x,y + 1,z] not in already and y + 1 < Y:
        already.append([x,y + 1,z])
        place_sum.append([x,y + 1,z])
        check.append(asort[x] + bsort[y + 1] + csort[z])
    if [x,y,z + 1] not in already and z + 1 < Z:
        already.append([x,y,z + 1])
        place_sum.append([x,y,z + 1])
        check.append(asort[x] + bsort[y] + csort[z + 1])
    print((max(check)))
    x,y,z = place_sum[check.index(max(check))][0],place_sum[check.index(max(check))][1],place_sum[check.index(max(check))][2]
    place_sum.pop(check.index(max(check)))
    check.remove(max(check))
# Original solution
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()))
asort,bsort,csort = sorted(A,reverse=True),sorted(B,reverse=True),sorted(C,reverse=True)
already = [[0,0,0]]
print((asort[0] + bsort[0] + csort[0]))
x,y,z = 0,0,0
check = []
for k in range(K - 1):
    if [x + 1,y,z] not in already and x + 1 < X:
        already.append([x + 1,y,z])
        heapq.heappush(check,(-(asort[x + 1] + bsort[y] + csort[z]),x + 1,y,z))
    if [x,y + 1,z] not in already and y + 1 < Y:
        already.append([x,y + 1,z])
        heapq.heappush(check,(-(asort[x] + bsort[y + 1] + csort[z]),x,y + 1,z))
    if [x,y,z + 1] not in already and z + 1 < Z:
        already.append([x,y,z + 1])
        heapq.heappush(check,(-(asort[x] + bsort[y] + csort[z + 1]),x,y,z + 1))
    maxsum = heapq.heappop(check)
    print((-maxsum[0]))
    x,y,z = maxsum[1],maxsum[2],maxsum[3]

# Optimized solution
import heapq
 
_x, _y, _z, k = list(map(int, input().split()))
aa = list(reversed(sorted(map(int, input().split()))))
bb = list(reversed(sorted(map(int, input().split()))))
cc = list(reversed(sorted(map(int, input().split()))))
 
ar = []
history = set()
 
 
def push(x, y, z):
    if (x, y, z) in history:
        pass
    else:
        v = aa[x] + bb[y] + cc[z]
        heapq.heappush(ar, (-v, x, y, z))
        history.add((x, y, z))
 
 
def pop():
    (v, x, y, z) = heapq.heappop(ar)
    return (-v, x, y, z)
 
 
push(0, 0, 0)
for _ in range(k):
    (total, x, y, z) = pop()
    print(total)
    if x + 1 < len(aa):
        push(x + 1, y, z)
    if y + 1 < len(bb):
        push(x, y + 1, z)
    if z + 1 < len(cc):
        push(x, y, z + 1)
# Original solution
X, Y, Z, K = list(map(int, input().split()))
x = sorted(list(map(int, input().split())))
y = sorted(list(map(int, input().split())))
z = sorted(list(map(int, input().split())))
import heapq
shou = 3 * 10**10 + 1
ans = []
for i in range(X-1, -1, -1):
  for j in range(Y-1, -1, -1):
    for k in range(Z-1, -1, -1):
      if (X-i)*(Y-j)*(Z-k) <= K:
        sub = x[i]+y[j]+z[k]
        ans.append(sub)
ans = list([x*(-1) for x in ans]) 
heapq.heapify(ans)
for i in range(K):
  print((heapq.heappop(ans)*(-1)))

# Optimized solution
X, Y, Z, K = list(map(int, input().split()))
x = sorted(list(map(int, input().split())))
y = sorted(list(map(int, input().split())))
z = sorted(list(map(int, input().split())))


import heapq
ans = []
for i in range(X-1, -1, -1):
  for j in range(Y-1, -1, -1):
    for k in range(Z-1, -1, -1):
      if (X-i)*(Y-j)*(Z-k) <= K:
        sub = x[i]+y[j]+z[k]
        ans.append(sub)
      else:
        break
ans = list([x*(-1) for x in ans]) 
heapq.heapify(ans)
for i in range(K):
  print((heapq.heappop(ans)*(-1)))
# Original solution
X, Y, Z, K = list(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)

def bin_search(mid):
    res = 0
    idx = 0
    ans = [] 
    for c in C:
        while idx < len(A_B):
            if c + A_B[idx] >= mid:
                res += len(A_B) - idx
                ans.append((c, idx))
                break
            else:
                idx += 1

    return res, ans

ok = 0
ng = pow(10, 10) * 3 + 1

while ok + 1 < ng:
    mid = (ok + ng) // 2
    res, ans = bin_search(mid)
    if res >= K:
        ok = mid
    else:
        ng = mid

res, ans = bin_search(ok)

tmp_ans = []
for c, idx in ans:
    for i in range(idx, len(A_B)):
        tmp_ans.append(A_B[i] + c)
for ans in sorted(tmp_ans)[::-1][:K]:
    print(ans)

# Optimized solution
X, Y, Z, K = list(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)
# Original solution
x, y, z, k = list(map(int, input().split()))
Lis = []
for _ in range(3):
    L = list(map(int, input().split()))
    L.sort(reverse=True)
    Lis.append(L)

Li = [[0, 0, 0]]
def search():
    global dic
    L = []
    for a, b, c in Li:
        for d, e, f in [[1, 0, 0], [0, 1, 0], [0, 0, 1]]:
            if a+d < x and b+e < y and c+f < z and [a+d, b+e, c+f] not in Li:
                re = Lis[0][a+d] + Lis[1][b+e] + Lis[2][c+f]
                L.append([re, a+d, b+e, c+f])
    L.sort(reverse=True)
    Li.append([L[0][1], L[0][2], L[0][3]])
    return L[0][0]
    

for i in range(k):
    if i == 0:
        ans = Lis[0][0] + Lis[1][0] + Lis[2][0]
        print(ans)
    else:
        print((search()))


# Optimized solution
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 = []
Q.append([A[0]+B[0]+C[0], 0, 0, 0])
M = {(0, 0, 0):True}

def search():
    global Q
    q = Q.pop()
    a = q[1]
    b = q[2]
    c = q[3]
    if a+1 < x and (a+1, b, c) not in M:
        Q.append([A[a+1]+B[b]+C[c], a+1, b, c])
        M[(a+1, b, c)] = True
    if b+1 < y and (a, b+1, c) not in M:
        Q.append([A[a]+B[b+1]+C[c], a, b+1, c])
        M[(a, b+1, c)] = True
    if c+1 < z and (a, b, c+1) not in M:
        Q.append([A[a]+B[b]+C[c+1], a, b, c+1])
        M[(a, b, c+1)] = True
    Q.sort()
    return q[0]

for _ in range(k):
    print((search()))
# Original solution
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)

p = []
for i in range(x):
  for j in range(y):
    for l in range(z):
      if (i+1) * (j+1) * (l+1) <= k:
        p.append(a[i]+b[j]+c[l])

p.sort(reverse=True)

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

# Optimized solution
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)

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

p.sort(reverse=True)

for i in range(k):
  print((p[i]))
# Original solution
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 = []

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 abc[:K]:
      print(i)

# Optimized solution


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(X):
    if (i+1) > K: break
    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
            ans.append(A[i]+B[j]+C[k])

ans.sort(reverse=True)

for i in range(K):
    print((ans[i]))
# Original solution
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)
To = [[[True] * Z for _ in range(Y)] for __ in range(X)]
Q = []
To[0][0][0] = False
heapq.heappush(Q, (-(A[0] + B[0] + C[0]), 0, 0, 0))
cnt = K
while cnt > 0:
    cnt -= 1
    ans, a, b, c = heapq.heappop(Q)
    print((-ans))
    if (a + 1 < X) and (To[a+1][b][c]):
        heapq.heappush(Q, (-(A[a + 1] + B[b] + C[c]), a + 1, b, c))
        To[a+1][b][c] = False
    if (b + 1 < Y) and (To[a][b+1][c]):
        heapq.heappush(Q, (-(A[a] + B[b + 1] + C[c]), a, b + 1, c))
        To[a][b+1][c] = False
    if (c + 1 < Z) and (To[a][b][c+1]):
        heapq.heappush(Q, (-(A[a] + B[b] + C[c + 1]), a, b, c + 1))
        To[a][b][c+1] = False


# Optimized solution
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)


def calc(p):
    cnt = 0
    for a in A:
        for b in B:
            for c in C:
                if a + b + c < p:
                    break
                cnt += 1
                if cnt >= K:
                    return True
    return False


end = A[0] + B[0] + C[0] + 1
start = 0
while end - start > 1:
    mid = (end + start)//2
    if calc(mid):
        start = mid
    else:
        end = mid

D = []

for a in A:
    for b in B:
        for c in C:
            if a + b + c < start:
                break
            D.append(a + b + c)
D.sort(reverse=True)
for d in D[:K]:
    print(d)
# Original solution
import itertools
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()))
result = [a + b + c for (a,b,c) in list(itertools.product(A, B, C))]
result.sort(reverse = True)
for i in range(K):
    print((result[i]))

# Optimized solution
import itertools
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()))
result = [a + b  for (a,b) in list(itertools.product(A, B))]
result.sort(reverse = True)
result = [s + c for (s,c) in list(itertools.product(result[:K], C))]
result.sort(reverse = True)
for i in range(K):
    print((result[i]))
# Original solution
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 = [A[i]+B[j]+C[k] for i in range(X) for j in range(Y) for k in range(Z) if (i+1)*(j+1)*(k+1) <= K]
ans.sort(reverse=True)
for i in range(K):
    print((ans[i]))

# Optimized solution
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)
t =[]
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k) <= K:
                t.append(A[i]+B[j]+C[k])
            else:break
t.sort(reverse=True)
for i in range(K):
    print((t[i]))
# Original solution
from heapq import nlargest
x,y,z,k=list(map(int,input().split()))
A,B,C=[list(map(int,input().split()))for _ in[0]*3]
E=nlargest(k,(a+b+c for a in A for b in B for c in C))
for i in E:
    print(i)


# Optimized solution
from heapq import nlargest
x,y,z,k=list(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)
# Original solution
#coding:utf-8
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True

def main():
    X,Y,Z,K = LMIIS()
    A = LMIIS()
    B = LMIIS()
    C = LMIIS()
    
    # A.sort(reverse=True)
    # B.sort(reverse=True)
    # C.sort(reverse=True)
    
    h = []
    from heapq import heappush,heappop
    for a in A:
        for b in B:
            for c in C:
                heappush(h,-(a+b+c))
    for _ in range(K):
        print(-heappop(h))
    # A.append(0)
    # B.append(0)
    # C.append(0)

    # # ai = bi = ci = 0

    # # for i in range(min(3000,X*Y*Z)):
    # #     print(A[ai],B[bi],C[ci])
    # #     print(A[ai]+B[bi]+C[ci])
    # #     nextai = ai + 1 if ai < X else ai
    # #     nextbi = bi + 1 if bi < Y else bi
    # #     nextci = ci + 1 if ci < Z else ci

    # #     #aiを更新する場合
    # #     if  A[nextai] >= B[nextbi]:
    # #         if A[nextai] >= C[nextci]:
    # #             ai = nextai
    # #         else:
    # #             ci = nextci
    # #     else:
    # #         if B[nextbi] >= C[nextci]:
    # #             bi = nextbi
    # #         else:
    # #             ci = nextci






    pass
if __name__ == '__main__':
    main()


# Optimized solution
#coding:utf-8
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True

def main():
    X,Y,Z,K = LMIIS()
    A = LMIIS()
    B = LMIIS()
    C = LMIIS()
    

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

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

    pass
if __name__ == '__main__':
    main()