Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

 
# なんこか入力
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()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
t = np.array([[-1,-1,-1,-1] for i in range(3*k)]).astype(np.int64)
t[0] = [a[x-1]+b[y-1]+c[z-1],x-1,y-1,z-1]
t_a = 1
#print(s)
 
for i in range(0,k):
    ma = 0
    ma_j = -1
    temp = [-1,-1,-1,-1]
    for j in range(len(t)):
        if ma <= t[j][0] :
            temp = t[j]
            ma = t[j][0]
            ma_j = j
#    print(temp)
    print(temp[0])
    t[ma_j][0]=0
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    f =1
    if temp[1] > 0:
        for j in range(len(t)):
            if temp[1]-1 == t[j][1] and temp[2]==t[j][2] and temp[3]==t[j][3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]-1]+b[temp[2]]+c[temp[3]],temp[1]-1,temp[2],temp[3]]
            t_a += 1
    f =1
    if temp[2] > 0:
        for j in range(len(t)):
            if temp[1] == t[j][1] and temp[2]-1==t[j][2] and temp[3]==t[j][3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]]+b[temp[2]-1]+c[temp[3]],temp[1],temp[2]-1,temp[3]]
            t_a += 1
    f =1
    if temp[3] > 0:
        for j in range(len(t)):
            if temp[1] == t[j][1] and temp[2]==t[j][2] and temp[3]-1==t[j][3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]]+b[temp[2]]+c[temp[3]-1],temp[1],temp[2],temp[3]-1]
            t_a += 1


Fixed submission:
# -*- coding: utf-8 -*-
# ヒープキューを使う

import math
import sys
import itertools
import numpy as np
import heapq
 
# なんこか入力
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()

h = [] # heap
g = set() #使用済み

heapq.heappush(h,(-(a[x-1]+b[y-1]+c[z-1]),x-1,y-1,z-1))
g.add((x-1,y-1,z-1))

#print(h)

for i in range(k):
#    heapq.heapify(h)
    temp =[]
    temp = heapq.heappop(h)
    print(-temp[0])
    for j in range(3):
        if temp[j+1]==0:
            continue
        if j == 0:
            temp2 = (-(a[temp[1]-1]+b[temp[2]]+c[temp[3]]),temp[1]-1,temp[2],temp[3])
        elif j == 1:
            temp2 = (-(a[temp[1]]+b[temp[2]-1]+c[temp[3]]),temp[1],temp[2]-1,temp[3])
        else:
            temp2 = (-(a[temp[1]]+b[temp[2]]+c[temp[3]-1]),temp[1],temp[2],temp[3]-1)
        if (temp2[1],temp2[2],temp2[3]) in g:
            continue
        heapq.heappush(h,temp2)
        g.add((temp2[1],temp2[2],temp2[3]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# なんかおかしい！！
import math
import sys
import itertools
import numpy as np

 
# なんこか入力
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()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
t = [[-1,-1,-1,-1] for i in range(3*k)]
t[0] = [a[x-1]+b[y-1]+c[z-1],x-1,y-1,z-1]
t_a = 1
#print(s)
 
for i in range(0,k):
    ma = 0
    ma_j = -1
    temp = [-1,-1,-1,-1]
    for j in range(len(t)):
        if ma <= t[j][0] :
            temp = t[j]
            ma = t[j][0]
            ma_j = j
#    print(temp)
    print(temp[0])
    t[ma_j][0]=0
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    f =1
    if temp[1] > 0:
        for j in range(len(t)):
            if temp[1]-1 == t[j][1] and temp[2]==t[j][2] and temp[3]==t[j][3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]-1]+b[temp[2]]+c[temp[3]],temp[1]-1,temp[2],temp[3]]
            t_a += 1
    f =1
    if temp[2] > 0:
        for j in range(len(t)):
            if temp[1] == t[j][1] and temp[2]-1==t[j][2] and temp[3]==t[j][3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]]+b[temp[2]-1]+c[temp[3]],temp[1],temp[2]-1,temp[3]]
            t_a += 1
    f =1
    if temp[3] > 0:
        for j in range(len(t)):
            if temp[1] == t[j][1] and temp[2]==t[j][2] and temp[3]-1==t[j][3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]]+b[temp[2]]+c[temp[3]-1],temp[1],temp[2],temp[3]-1]
            t_a += 1


Fixed submission:
# -*- coding: utf-8 -*-
# ヒープキューを使う

import math
import sys
import itertools
import numpy as np
import heapq
 
# なんこか入力
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()

h = [] # heap
g = set() #使用済み

heapq.heappush(h,(-(a[x-1]+b[y-1]+c[z-1]),x-1,y-1,z-1))
g.add((x-1,y-1,z-1))

#print(h)

for i in range(k):
#    heapq.heapify(h)
    temp =[]
    temp = heapq.heappop(h)
    print(-temp[0])
    for j in range(3):
        if temp[j+1]==0:
            continue
        if j == 0:
            temp2 = (-(a[temp[1]-1]+b[temp[2]]+c[temp[3]]),temp[1]-1,temp[2],temp[3])
        elif j == 1:
            temp2 = (-(a[temp[1]]+b[temp[2]-1]+c[temp[3]]),temp[1],temp[2]-1,temp[3])
        else:
            temp2 = (-(a[temp[1]]+b[temp[2]]+c[temp[3]-1]),temp[1],temp[2],temp[3]-1)
        if (temp2[1],temp2[2],temp2[3]) in g:
            continue
        heapq.heappush(h,temp2)
        g.add((temp2[1],temp2[2],temp2[3]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# なんかおかしい！！
import math
import sys
import itertools
import numpy as np

 
# なんこか入力
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()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
t = [[-1,-1,-1,-1] for i in range(3*k)]
t[0] = [a[x-1]+b[y-1]+c[z-1],x-1,y-1,z-1]
t_a = 1
#print(s)
 
for i in range(0,k):
    ma = 0
    temp = [-1,-1,-1,-1]
    for j in t:
        if ma <= j[0] :
            temp = j
            ma = j[0]
#    print(temp)
    print(temp[0])
    t[t.index(temp)][0]=0
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    f =1
    if temp[1] > 0:
        for j in t:
            if temp[1]-1 == j[1] and temp[2]==j[2] and temp[3]==j[3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]-1]+b[temp[2]]+c[temp[3]],temp[1]-1,temp[2],temp[3]]
            t_a += 1
    f =1
    if temp[2] > 0:
        for j in t:
            if temp[1] == j[1] and temp[2]-1==j[2] and temp[3]==j[3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]]+b[temp[2]-1]+c[temp[3]],temp[1],temp[2]-1,temp[3]]
            t_a += 1
    f =1
    if temp[3] > 0:
        for j in t:
            if temp[1] == j[1] and temp[2]==j[2] and temp[3]-1==j[3]:
                f = 0
                break
        if f == 1:
            t[t_a] = [a[temp[1]]+b[temp[2]]+c[temp[3]-1],temp[1],temp[2],temp[3]-1]
            t_a += 1


Fixed submission:
# -*- coding: utf-8 -*-
# ヒープキューを使う

import math
import sys
import itertools
import numpy as np
import heapq
 
# なんこか入力
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()

h = [] # heap
g = set() #使用済み

heapq.heappush(h,(-(a[x-1]+b[y-1]+c[z-1]),x-1,y-1,z-1))
g.add((x-1,y-1,z-1))

#print(h)

for i in range(k):
#    heapq.heapify(h)
    temp =[]
    temp = heapq.heappop(h)
    print(-temp[0])
    for j in range(3):
        if temp[j+1]==0:
            continue
        if j == 0:
            temp2 = (-(a[temp[1]-1]+b[temp[2]]+c[temp[3]]),temp[1]-1,temp[2],temp[3])
        elif j == 1:
            temp2 = (-(a[temp[1]]+b[temp[2]-1]+c[temp[3]]),temp[1],temp[2]-1,temp[3])
        else:
            temp2 = (-(a[temp[1]]+b[temp[2]]+c[temp[3]-1]),temp[1],temp[2],temp[3]-1)
        if (temp2[1],temp2[2],temp2[3]) in g:
            continue
        heapq.heappush(h,temp2)
        g.add((temp2[1],temp2[2],temp2[3]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# なんかおかしい！！
import math
import sys
import itertools
import numpy as np


# なんこか入力
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()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
s = [[x-1,y-1,z-1]]
t = [[-1,-1,-1] for i in range(3*k)]
t[0] = [x-1,y-1,z-1]
t_a = 1
#print(s)

for i in range(0,k):
    ma = 0
    temp = [-1,-1,-1]
    for j in s:
        if ma <= a[j[0]]+b[j[1]]+c[j[2]] :
            temp = j
            ma = a[j[0]]+b[j[1]]+c[j[2]]
#    print(temp)
    print(a[temp[0]]+b[temp[1]]+c[temp[2]])
#    print(a[temp[0]],b[temp[1]],c[temp[2]])
    s.remove(temp)
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    if temp[0] > 0:
        if [temp[0]-1,temp[1],temp[2]] in t:
            pass
        else:
            s.append([temp[0]-1,temp[1],temp[2]])
            t[t_a] = [temp[0]-1,temp[1],temp[2]]
            t_a += 1
    if temp[1] > 0:
        if [temp[0],temp[1]-1,temp[2]] in t:
            pass
        else:
            s.append([temp[0],temp[1]-1,temp[2]])
            t[t_a] = [temp[0],temp[1]-1,temp[2]]
            t_a += 1
    if temp[2] > 0:
        if [temp[0],temp[1],temp[2]-1] in t:
            pass
        else:
            s.append([temp[0],temp[1],temp[2]-1])
            t[t_a] = [temp[0],temp[1],temp[2]-1]
            t_a += 1


Fixed submission:
# -*- coding: utf-8 -*-
# ヒープキューを使う

import math
import sys
import itertools
import numpy as np
import heapq
 
# なんこか入力
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()

h = [] # heap
g = set() #使用済み

heapq.heappush(h,(-(a[x-1]+b[y-1]+c[z-1]),x-1,y-1,z-1))
g.add((x-1,y-1,z-1))

#print(h)

for i in range(k):
#    heapq.heapify(h)
    temp =[]
    temp = heapq.heappop(h)
    print(-temp[0])
    for j in range(3):
        if temp[j+1]==0:
            continue
        if j == 0:
            temp2 = (-(a[temp[1]-1]+b[temp[2]]+c[temp[3]]),temp[1]-1,temp[2],temp[3])
        elif j == 1:
            temp2 = (-(a[temp[1]]+b[temp[2]-1]+c[temp[3]]),temp[1],temp[2]-1,temp[3])
        else:
            temp2 = (-(a[temp[1]]+b[temp[2]]+c[temp[3]-1]),temp[1],temp[2],temp[3]-1)
        if (temp2[1],temp2[2],temp2[3]) in g:
            continue
        heapq.heappush(h,temp2)
        g.add((temp2[1],temp2[2],temp2[3]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# なんかおかしい！！
import math
import sys
import itertools
import numpy as np


# なんこか入力
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()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
s = [[x-1,y-1,z-1]]
t = [[x-1,y-1,z-1]]
#print(s)

for i in range(0,k):
    ma = 0
    temp = [-1,-1,-1]
    for j in s:
        if ma <= a[j[0]]+b[j[1]]+c[j[2]] :
            temp = j
            ma = a[j[0]]+b[j[1]]+c[j[2]]
#    print(temp)
    print(a[temp[0]]+b[temp[1]]+c[temp[2]])
#    print(a[temp[0]],b[temp[1]],c[temp[2]])
    s.remove(temp)
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    if temp[0] > 0:
        if [temp[0]-1,temp[1],temp[2]] in t:
            pass
        else:
            s.append([temp[0]-1,temp[1],temp[2]])
            t.append([temp[0]-1,temp[1],temp[2]])
    if temp[1] > 0:
        if [temp[0],temp[1]-1,temp[2]] in t:
            pass
        else:
            s.append([temp[0],temp[1]-1,temp[2]])
            t.append([temp[0],temp[1]-1,temp[2]])
    if temp[2] > 0:
        if [temp[0],temp[1],temp[2]-1] in t:
            pass
        else:
            s.append([temp[0],temp[1],temp[2]-1])
            t.append([temp[0],temp[1],temp[2]-1])



Fixed submission:
# -*- coding: utf-8 -*-
# ヒープキューを使う

import math
import sys
import itertools
import numpy as np
import heapq
 
# なんこか入力
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()

h = [] # heap
g = set() #使用済み

heapq.heappush(h,(-(a[x-1]+b[y-1]+c[z-1]),x-1,y-1,z-1))
g.add((x-1,y-1,z-1))

#print(h)

for i in range(k):
#    heapq.heapify(h)
    temp =[]
    temp = heapq.heappop(h)
    print(-temp[0])
    for j in range(3):
        if temp[j+1]==0:
            continue
        if j == 0:
            temp2 = (-(a[temp[1]-1]+b[temp[2]]+c[temp[3]]),temp[1]-1,temp[2],temp[3])
        elif j == 1:
            temp2 = (-(a[temp[1]]+b[temp[2]-1]+c[temp[3]]),temp[1],temp[2]-1,temp[3])
        else:
            temp2 = (-(a[temp[1]]+b[temp[2]]+c[temp[3]-1]),temp[1],temp[2],temp[3]-1)
        if (temp2[1],temp2[2],temp2[3]) in g:
            continue
        heapq.heappush(h,temp2)
        g.add((temp2[1],temp2[2],temp2[3]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# なんかおかしい！！
import math
import sys
import itertools
import numpy as np


# なんこか入力
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()
#cake = [[0 for i in range(3)] for j in range(3000)]
#cake[0][0]=x-1
#cake[0][1]=y-1
#cake[0][2]=z-1
#print(a[x-1]+b[y-1]+c[z-1])
#print(a[cake[0][0]],b[cake[0][1]],c[cake[0][2]])
s = [[x-1,y-1,z-1]]
t = [[x-1,y-1,z-1]]
#print(s)

for i in range(0,k):
    ma = 0
    temp = [-1,-1,-1]
    for j in s:
        if ma <= a[j[0]]+b[j[1]]+c[j[2]] :
            temp = j
            ma = a[j[0]]+b[j[1]]+c[j[2]]
#    print(temp)
    print(a[temp[0]]+b[temp[1]]+c[temp[2]])
#    print(a[temp[0]],b[temp[1]],c[temp[2]])
    s.remove(temp)
#    print("s=",s)
#    print("t=",t)
#    print(temp)
    f = 0
    if temp[0] > 0:
        for j in t:
            if temp[0]-1 == j[0] and temp[1]== j[1] and temp[2]==j[2]:
                f=1
                break
        if f==0:
            s.append([temp[0]-1,temp[1],temp[2]])
            t.append([temp[0]-1,temp[1],temp[2]])
    f = 0
    if temp[1] > 0:
        for j in t:
            if temp[0] == j[0] and temp[1]-1== j[1] and temp[2]==j[2]:
                f=1
                break
        if f==0:
            s.append([temp[0],temp[1]-1,temp[2]])
            t.append([temp[0],temp[1]-1,temp[2]])
    f = 0
    if temp[2] > 0:
        for j in t:
            if temp[0] == j[0] and temp[1]== j[1] and temp[2]-1==j[2]:
                f=1
                break
        if f==0:
            s.append([temp[0],temp[1],temp[2]-1])
            t.append([temp[0],temp[1],temp[2]-1])

  


Fixed submission:
# -*- coding: utf-8 -*-
# ヒープキューを使う

import math
import sys
import itertools
import numpy as np
import heapq
 
# なんこか入力
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()

h = [] # heap
g = set() #使用済み

heapq.heappush(h,(-(a[x-1]+b[y-1]+c[z-1]),x-1,y-1,z-1))
g.add((x-1,y-1,z-1))

#print(h)

for i in range(k):
#    heapq.heapify(h)
    temp =[]
    temp = heapq.heappop(h)
    print(-temp[0])
    for j in range(3):
        if temp[j+1]==0:
            continue
        if j == 0:
            temp2 = (-(a[temp[1]-1]+b[temp[2]]+c[temp[3]]),temp[1]-1,temp[2],temp[3])
        elif j == 1:
            temp2 = (-(a[temp[1]]+b[temp[2]-1]+c[temp[3]]),temp[1],temp[2]-1,temp[3])
        else:
            temp2 = (-(a[temp[1]]+b[temp[2]]+c[temp[3]-1]),temp[1],temp[2],temp[3]-1)
        if (temp2[1],temp2[2],temp2[3]) in g:
            continue
        heapq.heappush(h,temp2)
        g.add((temp2[1],temp2[2],temp2[3]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
#
import math
import sys
import itertools
import numpy as np


# なんこか入力
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)
d = []
e = []
s = 0
for i in range(x):
    for j in range(y):
        d.append(a[i]+b[j])

d.sort(reverse=True)
p = min(k,len(d))

for i in range(p):
    for j in range(z):
        e.append(d[i]+c[j])

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


Fixed submission:
# -*- coding: utf-8 -*-
# ヒープキューを使う

import math
import sys
import itertools
import numpy as np
import heapq
 
# なんこか入力
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()

h = [] # heap
g = set() #使用済み

heapq.heappush(h,(-(a[x-1]+b[y-1]+c[z-1]),x-1,y-1,z-1))
g.add((x-1,y-1,z-1))

#print(h)

for i in range(k):
#    heapq.heapify(h)
    temp =[]
    temp = heapq.heappop(h)
    print(-temp[0])
    for j in range(3):
        if temp[j+1]==0:
            continue
        if j == 0:
            temp2 = (-(a[temp[1]-1]+b[temp[2]]+c[temp[3]]),temp[1]-1,temp[2],temp[3])
        elif j == 1:
            temp2 = (-(a[temp[1]]+b[temp[2]-1]+c[temp[3]]),temp[1],temp[2]-1,temp[3])
        else:
            temp2 = (-(a[temp[1]]+b[temp[2]]+c[temp[3]-1]),temp[1],temp[2],temp[3]-1)
        if (temp2[1],temp2[2],temp2[3]) in g:
            continue
        heapq.heappush(h,temp2)
        g.add((temp2[1],temp2[2],temp2[3]))