Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop , heappush

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)

# 処理済みフラグ
confilm = []

q = [(-(A[0] + B[0] + C[0]) , 0,0,0)]

for _ in range(K) :
    val , i , j , k = heappop(q)

    print(-val)

    t = (i+1,j,k)
    if i + 1 < X and not t in confilm :
        heappush(q,(-(A[i+1] + B[j] + C[k]),) + t)
        confilm.append(t)

    t = (i,j+1,k)
    if j + 1 < Y and not t in confilm :
        heappush(q,(-(A[i] + B[j+1] + C[k]),) + t)
        confilm.append(t)

    t = (i,j,k+1)
    if k + 1 < Z and not t in confilm :
        heappush(q,(-(A[i] + B[j] + C[k+1]),) + t)
        confilm.append(t)




Fixed submission:
from heapq import heappop , heappush

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)

# 処理済みフラグ
confilm = []

q = [(-(A[0] + B[0] + C[0]) , 0,0,0)]

for _ in range(K) :
    val , i , j , k = heappop(q)

    print(-val)

    t = (i+1,j,k)
    if i + 1 < X and not t in confilm :
        heappush(q,(-(A[i+1] + B[j] + C[k]),) + t)
        confilm.append(t)

    t = (i,j+1,k)
    if j + 1 < Y and not t in confilm :
        heappush(q,(-(A[i] + B[j+1] + C[k]),) + t)
        confilm.append(t)

    t = (i,j,k+1)
    if k + 1 < Z and not t in confilm :
        heappush(q,(-(A[i] + B[j] + C[k+1]),) + t)
        confilm.append(t)

Buggy python submission (verdict: Time Limit Exceeded):
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)

# 処理済みフラグ
confilm = []

q = [(-(A[0] + B[0] + C[0]) , 0,0,0)]
confilm.append((0,0,0))

for _ in range(K) :
    val , i , j , k = heapq.heappop(q)

    print(-val)

    t = (i+1,j,k)
    if i + 1 < X and not t in confilm :
        heapq.heappush(q,(-(A[i+1] + B[j] + C[k]),) + t)
        confilm.append(t)
    t = (i,j+1,k)
    if j + 1 < Y and not t in confilm :
        heapq.heappush(q,(-(A[i] + B[j+1] + C[k]),) + t)
        confilm.append(t)
    t = (i,j,k+1)
    if k + 1 < Z and not t in confilm :
        heapq.heappush(q,(-(A[i] + B[j] + C[k+1]),) + t)
        confilm.append(t)




Fixed submission:
from heapq import heappop , heappush

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)

# 処理済みフラグ
confilm = []

q = [(-(A[0] + B[0] + C[0]) , 0,0,0)]

for _ in range(K) :
    val , i , j , k = heappop(q)

    print(-val)

    t = (i+1,j,k)
    if i + 1 < X and not t in confilm :
        heappush(q,(-(A[i+1] + B[j] + C[k]),) + t)
        confilm.append(t)

    t = (i,j+1,k)
    if j + 1 < Y and not t in confilm :
        heappush(q,(-(A[i] + B[j+1] + C[k]),) + t)
        confilm.append(t)

    t = (i,j,k+1)
    if k + 1 < Z and not t in confilm :
        heappush(q,(-(A[i] + B[j] + C[k+1]),) + t)
        confilm.append(t)

Buggy python submission (verdict: Time Limit Exceeded):
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)


# 処理済みフラグ
confilm = []

q = [(-(A[0] + B[0] + C[0]) , 0,0,0)]
confilm.append((0,0,0))

for _ in range(K) :
    val , i , j , k = heapq.heappop(q)

    print(-val)

    if i + 1 < X and not (i+1,j,k) in confilm :
        heapq.heappush(q,(-(A[i+1] + B[j] + C[k]), i+1,j,k))
        confilm.append((i+1,j,k))
    if j + 1 < Y and not (i,j+1,k) in confilm :
        heapq.heappush(q,(-(A[i] + B[j+1] + C[k]), i,j+1,k))
        confilm.append((i,j+1,k))
    if k + 1 < Z and not (i,j,k+1) in confilm :
        heapq.heappush(q,(-(A[i] + B[j] + C[k+1]), i,j,k+1))
        confilm.append((i,j,k+1))




Fixed submission:
from heapq import heappop , heappush

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)

# 処理済みフラグ
confilm = []

q = [(-(A[0] + B[0] + C[0]) , 0,0,0)]

for _ in range(K) :
    val , i , j , k = heappop(q)

    print(-val)

    t = (i+1,j,k)
    if i + 1 < X and not t in confilm :
        heappush(q,(-(A[i+1] + B[j] + C[k]),) + t)
        confilm.append(t)

    t = (i,j+1,k)
    if j + 1 < Y and not t in confilm :
        heappush(q,(-(A[i] + B[j+1] + C[k]),) + t)
        confilm.append(t)

    t = (i,j,k+1)
    if k + 1 < Z and not t in confilm :
        heappush(q,(-(A[i] + B[j] + C[k+1]),) + t)
        confilm.append(t)

Buggy python submission (verdict: Runtime Error):
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)


# 処理済みフラグ
confilm = [[[False for _ in range(Z)] for _ in range(Y)] for _ in range(X)]

q = [(-(A[0] + B[0] + C[0]) , 0,0,0)]
confilm[0][0][0] = True

count = 0

while q :
    now = heapq.heappop(q)

    print(-now[0])
    count += 1
    if count >= K :
        break

    i , j , k = now[1] , now[2] , now[3]

    if not confilm[i+1][j][k] :
        heapq.heappush(q,(-(A[i+1] + B[j] + C[k]), i+1,j,k))
        confilm[i+1][j][k] = True
    if not confilm[i][j+1][k] :
        heapq.heappush(q,(-(A[i] + B[j+1] + C[k]), i,j+1,k))
        confilm[i][j+1][k] = True
    if not confilm[i][j][k+1] :
        heapq.heappush(q,(-(A[i] + B[j] + C[k+1]), i,j,k+1))
        confilm[i][j][k+1] = True




Fixed submission:
from heapq import heappop , heappush

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)

# 処理済みフラグ
confilm = []

q = [(-(A[0] + B[0] + C[0]) , 0,0,0)]

for _ in range(K) :
    val , i , j , k = heappop(q)

    print(-val)

    t = (i+1,j,k)
    if i + 1 < X and not t in confilm :
        heappush(q,(-(A[i+1] + B[j] + C[k]),) + t)
        confilm.append(t)

    t = (i,j+1,k)
    if j + 1 < Y and not t in confilm :
        heappush(q,(-(A[i] + B[j+1] + C[k]),) + t)
        confilm.append(t)

    t = (i,j,k+1)
    if k + 1 < Z and not t in confilm :
        heappush(q,(-(A[i] + B[j] + C[k+1]),) + t)
        confilm.append(t)

Buggy python submission (verdict: Time Limit Exceeded):
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()))

# A,Bでソート
D = list(itertools.product(A,B))
D.sort(key=lambda A : A[0] + A[1], reverse=True)

subD = D[:K]

E = list(itertools.product(D,C))

E.sort(key=lambda A : A[0][0] + A[0][1] + A[1], reverse=True)

for (i , j) , k in E[:K] :
    print(i+j+k)

Fixed submission:
from heapq import heappop , heappush

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)

# 処理済みフラグ
confilm = []

q = [(-(A[0] + B[0] + C[0]) , 0,0,0)]

for _ in range(K) :
    val , i , j , k = heappop(q)

    print(-val)

    t = (i+1,j,k)
    if i + 1 < X and not t in confilm :
        heappush(q,(-(A[i+1] + B[j] + C[k]),) + t)
        confilm.append(t)

    t = (i,j+1,k)
    if j + 1 < Y and not t in confilm :
        heappush(q,(-(A[i] + B[j+1] + C[k]),) + t)
        confilm.append(t)

    t = (i,j,k+1)
    if k + 1 < Z and not t in confilm :
        heappush(q,(-(A[i] + B[j] + C[k+1]),) + t)
        confilm.append(t)