qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys,bisect
input = sys.stdin.readline

x,y,z,k = map(int,input().split())
a = tuple(map(int,input().split()))
b = tuple(map(int,input().split()))
c = list(map(int,input().split()))

ab = []
for e in a:
    for w in b:
        ab.append(e+w)
ab.sort()

ok = -1
ng = 10**12
while abs(ok-ng)>1:
    mid = (ok+ng)//2
    cnt = 0
    for e in c:
        cnt += len(ab)-bisect.bisect_left(ab,mid-e)
    if cnt >= k:
        ok = mid
    else:
        ng = mid

res = []
for e in c:
    ind = bisect.bisect_left(ab,ok-e)
    for i in range(ind,len(ab)):
        res.append(e+ab[i])
res.sort()
for i in range(k):
    print(res[-i])
        



Fixed code:
import sys,bisect
input = sys.stdin.readline

x,y,z,k = map(int,input().split())
a = tuple(map(int,input().split()))
b = tuple(map(int,input().split()))
c = list(map(int,input().split()))

ab = []
for e in a:
    for w in b:
        ab.append(e+w)
ab.sort()

ok = -1
ng = 10**12
while abs(ok-ng)>1:
    mid = (ok+ng)//2
    cnt = 0
    for e in c:
        cnt += len(ab)-bisect.bisect_left(ab,mid-e)
    if cnt >= k:
        ok = mid
    else:
        ng = mid

res = []
for e in c:
    ind = bisect.bisect_left(ab,ok-e)
    for i in range(ind,len(ab)):
        res.append(e+ab[i])
res.sort()
for i in range(1,k+1):
    print(res[-i])
Buggy code:
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 = sorted(a+b for a in a for b in b)[:-k-1:-1]
abc = sorted(ab+c for ab in ab[:k] for c in c)[:-k-1:-1]

print(*abc, sep="\n")

Fixed code:
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")
Buggy code:
import heapq

a,b,c,k=map(int,input())
arr1=list(map(int,input().split()))
arr1=sorted(arr1,reverse=True)
arr2=list(map(int,input().split()))
arr2=sorted(arr2,reverse=True)
arr3=list(map(int,input().split()))
arr3=sorted(arr3,reverse=True)
heap=[]
heapq.heappush(heap,(-(arr1[0]+arr2[0]+arr3[0]),0,0,0))
s={(0,0,0)}
for _ in range(k):
  v,i,j,k=heapq.heappop(heap)
  if i+1<a and (i+1,j,k) not in s:
    s.add((i+1,j,k))
    heapq.heappush(heap,(-(arr1[i+1]+arr2[j]+arr3[k]),i+1,j,k))
  if j+1<b and (i,j+1,k) not in s:
    s.add((i,j+1,k))
    heapq.heappush(heap,(-(arr1[i]+arr2[j+1]+arr3[k]),i,j+1,k))
  if k+1<c and (i,j,k+1) not in s:
    s.add((i,j,k+1))
    heapq.heappush(heap,(-(arr1[i]+arr2[j]+arr3[k+1]),i,j,k+1))
  print(-v)

Fixed code:
import heapq

a,b,c,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr1=sorted(arr1,reverse=True)
arr2=list(map(int,input().split()))
arr2=sorted(arr2,reverse=True)
arr3=list(map(int,input().split()))
arr3=sorted(arr3,reverse=True)
heap=[]
heapq.heappush(heap,(-(arr1[0]+arr2[0]+arr3[0]),0,0,0))
s={(0,0,0)}
for _ in range(k):
  v,i,j,k=heapq.heappop(heap)
  if i+1<a and (i+1,j,k) not in s:
    s.add((i+1,j,k))
    heapq.heappush(heap,(-(arr1[i+1]+arr2[j]+arr3[k]),i+1,j,k))
  if j+1<b and (i,j+1,k) not in s:
    s.add((i,j+1,k))
    heapq.heappush(heap,(-(arr1[i]+arr2[j+1]+arr3[k]),i,j+1,k))
  if k+1<c and (i,j,k+1) not in s:
    s.add((i,j,k+1))
    heapq.heappush(heap,(-(arr1[i]+arr2[j]+arr3[k+1]),i,j,k+1))
  print(-v)
Buggy code:
import heapq
X, Y, Z, K = 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)

h = []
heapq.heappush(h, (A[0] + B[0] + C[0], 0, 0, 0))

ans = []
for _ in range(K):
    p, i, j, k = heapq.heappop(h)
    ans.append(p)
    if i + 1 < X and j < Y and k < Z and not (A[i+1] + B[j] + C[k], i + 1, j, k) in h:
        heapq.heappush(h, (A[i + 1] + B[j] + C[k], i + 1, j, k))
    if i < X and j + 1 < Y and k < Z and not (A[i] + B[j+1] + C[k], i, j+1, k) in h:
        heapq.heappush(h, (A[i] + B[j+1] + C[k], i, j+1, k))
    if i < X and j < Y and k + 1 < Z and not (A[i] + B[j] + C[k+1], i, j, k+1) in h:
        heapq.heappush(h, (A[i] + B[j] + C[k+1], i, j, k+1))

for a in ans:
    print(a)

Fixed code:
import heapq
X, Y, Z, K = 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)

h = []
heapq.heappush(h, (-(A[0] + B[0] + C[0]), (0, 0, 0)))

ans = []
for _ in range(K):
    p, v = heapq.heappop(h)
    i, j, k = v
    ans.append(p)
    if i + 1 < X and j < Y and k < Z and not (-(A[i+1] + B[j] + C[k]), (i+1, j, k)) in h:
        heapq.heappush(h, (-(A[i + 1] + B[j] + C[k]), (i+1, j, k)))
    if i < X and j + 1 < Y and k < Z and not (-(A[i] + B[j+1] + C[k]), (i, j+1, k)) in h:
        heapq.heappush(h, (-(A[i] + B[j+1] + C[k]), (i, j+1, k)))
    if i < X and j < Y and k + 1 < Z and not (-(A[i] + B[j] + C[k+1]), (i, j, k+1)) in h:
        heapq.heappush(h, (-(A[i] + B[j] + C[k+1]), (i, j, k+1)))

for a in ans:
    print(-a)
Buggy code:
from bisect import bisect_left as bl
from collections import deque as dq
X, Y, Z, K = map(int, input().split())
ABC = [sorted(list(map(int, input().split()))) for _ in range(3)]
AB = []
for i in range(X):
  for j in range(Y):
    AB.append(ABC[0][i] + ABC[1][j])
AB.sort(reverse = True)
res = []
for i in range(K):
  for j in range(Z):
    res.append(AB[i] + ABC[2][j])
res.sort(reverse = True)
for i in range(K):
  print(res[i])

Fixed code:
from bisect import bisect_left as bl
from collections import deque as dq
X, Y, Z, K = map(int, input().split())
ABC = [sorted(list(map(int, input().split()))) for _ in range(3)]
AB = []
for i in range(X):
  for j in range(Y):
    AB.append(ABC[0][i] + ABC[1][j])
AB.sort(reverse = True)
res = []
for i in range(min(K, X * Y)):
  for j in range(Z):
    res.append(AB[i] + ABC[2][j])
res.sort(reverse = True)
for i in range(K):
  print(res[i])
Buggy code:
from heapq import heappush, heappop
X, Y, Z, K = map(int, input().split())
I = lambda: sorted(list(map(int, input().split())), reverse=True)
A = I()
B = I()
C = I()
hq = []

for a in A:
    for b in B:
        for c in C:
            if len(hq) < K:
                heappush(hq, a+b+c)
            else:
                tmp = heappop(hq)
                if tmp >= a+b+c:
                    heappush(hq, tmp)
                    break
                else:
                    heappush(hq, a*b*c)

ans = []
for _ in range(K):
    ans.append(heappop(hq))

ans.sort(reverse=True)
for x in ans:
    print(x)


Fixed code:
from heapq import heappush, heappop
X, Y, Z, K = map(int, input().split())
I = lambda: sorted(list(map(int, input().split())), reverse=True)
A = I()
B = I()
C = I()
hq = []

for a in A:
    for b in B:
        for c in C:
            if len(hq) < K:
                heappush(hq, a+b+c)
            else:
                tmp = heappop(hq)
                if tmp >= a+b+c:
                    heappush(hq, tmp)
                    break
                else:
                    heappush(hq, a+b+c)

ans = []
for _ in range(K):
    ans.append(heappop(hq))

ans.sort(reverse=True)
for x in ans:
    print(x)
Buggy code:
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)
print(w for w in l[:q])

Fixed code:
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)
Buggy code:
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)
 
def bisect(l,r):
  cnt=(l+r)//2
  if cnt==l:
    return l-1+judge(l)
  if judge(cnt):
    return bisect(cnt+1,r)
  else:
    return bisect(l,cnt)
def judge(thr):
  m=0
  for i in a:
    for j in b:
      if i*j>q:
        break
      for k in c:
        if i+j+k<thr:
          break
        m+=1
        if m>=q:
          return True
  return False
def make(thr):
  m=0
  l=[]
  for i in a:
    for j in b:
      for k in c:
        n=i+j+k
        if n<thr+1:
          break
        m+=1
        l+=[n]
  l.sort(reverse=True)
  return l+[thr]*(q-len(l))
thr=bisect(0,a[0]+b[0]+c[0]+1)
ans=make(thr)
for w in ans:
  print(w)

Fixed code:
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)
 
def bisect(l,r):
  cnt=(l+r)//2
  if cnt==l:
    return l-1+judge(l)
  if judge(cnt):
    return bisect(cnt+1,r)
  else:
    return bisect(l,cnt)
def judge(thr):
  m=0
  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 or a[i]+b[j]+c[k]<thr:
          break
        m+=1
        if m>=q:
          return True
  return False
def make(thr):
  m=0
  l=[]
  for i in a:
    for j in b:
      for k in c:
        n=i+j+k
        if n<thr+1:
          break
        m+=1
        l+=[n]
  l.sort(reverse=True)
  return l+[thr]*(q-len(l))
thr=bisect(0,a[0]+b[0]+c[0]+1)
ans=make(thr)
for w in ans:
  print(w)
Buggy code:
import heapq
X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=1)
B = sorted(list(map(int,input().split())),reverse=1)
C = sorted(list(map(int,input().split())),reverse=1)
Q = [(-A[0]-B[0]-C[0],0,0,0)]
heapq.heapify(Q)
for i in range(K):
    n,a,b,c = heapq.heappop(Q)
    if a < X-1:
        heapq.heappush(Q,(n+A[a]-A[a+1],a+1,b,c))
    if b < Y-1:
        heapq.heappush(Q,(n+B[b]-B[b+1],a,b+1,c))
    if c < Z-1:
        heapq.heappush(Q,(n+C[c]-C[c+1],a,b,c+1))
    print(-n)

Fixed code:
import heapq
X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=1)
B = sorted(list(map(int,input().split())),reverse=1)
C = sorted(list(map(int,input().split())),reverse=1)
Q = [(-A[0]-B[0]-C[0],0,0,0)]
heapq.heapify(Q)
for i in range(K):
    n,a,b,c = heapq.heappop(Q)
    if a < X-1 and (n+A[a]-A[a+1],a+1,b,c) not in Q:
        heapq.heappush(Q,(n+A[a]-A[a+1],a+1,b,c))
    if b < Y-1 and (n+B[b]-B[b+1],a,b+1,c) not in Q:
        heapq.heappush(Q,(n+B[b]-B[b+1],a,b+1,c))
    if c < Z-1 and (n+C[c]-C[c+1],a,b,c+1) not in Q:
        heapq.heappush(Q,(n+C[c]-C[c+1],a,b,c+1))
    print(-n)
Buggy code:
import itertools

X, Y, Z, K = [int(x) for x in 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)

list_ = [a+b for (a,b) in itertools.product(A, B)]
list_.sort(reverse=True)

list__ = [ab+c for (ab,c) in itertools.product(list_[:10000], C)]
for N in list__[:K]:
  print(N)

Fixed code:
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)
Buggy code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

res = []
x, y, z, k = na()
a_li = na()
b_li = na()
c_li = na()
list.sort(a_li,reverse=True)
list.sort(b_li,reverse=True)
list.sort(c_li,reverse=True)
for i in range(x):
    for j in range(y):
        for k in range(z):
            if (i + 1) * (j + 1) * (k + 1) <= k:
                res.append(a_li[i] * b_li[j] + c_li[k])
            else:
                break
                
list.sort(res, reverse=True)
for i in range(k):
    print(res[i])

Fixed code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

res = []
x, y, z, K = na()
a_li = na()
b_li = na()
c_li = na()
list.sort(a_li, reverse=True)
list.sort(b_li, reverse=True)
list.sort(c_li, reverse=True)
for i in range(x):
    for j in range(y):
        for k in range(z):
            if (i + 1) * (j + 1) * (k + 1) <= K:
                res.append(a_li[i] + b_li[j] + c_li[k])
            else:
                break
list.sort(res, reverse=True)
for i in range(K):
    print(res[i])
Buggy code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
x,y,z,k = map(int,readline().split())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
c = [int(i) for i in readline().split()]
from heapq import heappush,heappop,heapify
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

chk = [(-(a[0]+b[0]+c[0]),0,0,0)]
heapify(chk)
C = set((0,0,0))
ans = []
for i in range(k):
  p,q,r,s = heappop(chk)
  ans.append(-p)
  C.add((q,r,s))
  if not (q+1,r,s) in C and q < x-1:
    heappush(chk,(-(a[q+1]+b[r]+c[s]),q+1,r,s))
  if not (q,r+1,s) in C and r < y-1:
    heappush(chk,(-(a[q]+b[r+1]+c[s]),q,r+1,s))
  if not (q,r,s+1) in C and s < z-1:
    heappush(chk,(-(a[q]+b[r]+c[s+1]),q,r,s+1))
    
for i in ans:
  print(i)

Fixed code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
x,y,z,k = map(int,readline().split())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
c = [int(i) for i in readline().split()]
from heapq import heappush,heappop,heapify
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

chk = [(-(a[0]+b[0]+c[0]),0,0,0)]
heapify(chk)
C = set((0,0,0))
ans = []
for i in range(k):
  p,q,r,s = heappop(chk)
  ans.append(-p)
  if not (q+1,r,s) in C and q < x-1:
    C.add((q+1,r,s))
    heappush(chk,(-(a[q+1]+b[r]+c[s]),q+1,r,s))
  if not (q,r+1,s) in C and r < y-1:
    C.add((q,r+1,s))
    heappush(chk,(-(a[q]+b[r+1]+c[s]),q,r+1,s))
  if not (q,r,s+1) in C and s < z-1:
    C.add((q,r,s+1))
    heappush(chk,(-(a[q]+b[r]+c[s+1]),q,r,s+1))
    
for i in ans:
  print(i)
Buggy code:
def binsearch(l, r, fn):
    while r - l > 1:
        m = (l + r) // 2
        if fn(m):
            l = m
        else:
            r = m
    return l

def main():
    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 = sorted((a + b for a in A for b in B), reverse=True)
    def helper(x):
        r = 0
        t = len(C) - 1
        for ab in AB:
            while t >= 0 and C[t] + ab < x:
                t -= 1
            r += t + 1
        return r >= K
    l = binsearch(AB[-1] + C[-1], AB[0] + C[0] + 1, helper)
    r = []
    for ab in AB:
        for c in C:
            if ab + c < K:
                break
            r.append(ab + c)
        if len(r) >= K:
            break
    r.sort(reverse=True)
    print('\n'.join(str(i) for i in r))

main()

Fixed code:
def binsearch(l, r, fn):
    while r - l > 1:
        m = (l + r) // 2
        if fn(m):
            l = m
        else:
            r = m
    return l

def main():
    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 = sorted((a + b for a in A for b in B), reverse=True)
    def helper(x):
        r = 0
        t = len(C) - 1
        for ab in AB:
            while t >= 0 and C[t] + ab < x:
                t -= 1
            r += t + 1
            if r >= K:
                return True
            if t < 0:
                return False
        return r >= K
    l = binsearch(AB[-1] + C[-1], AB[0] + C[0] + 1, helper)
    r = []
    t = len(C) - 1
    for ab in AB:
        while t >= 0 and C[t] + ab < l + 1:
            t -= 1
        if t < 0:
            break
        r.extend(ab + c for c in C[:t + 1])
    r.sort(reverse=True)
    r += [l] * (K - len(r))
    print('\n'.join(str(i) for i in r))

main()
Buggy code:

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 = []

for x in range(X):
  for y in range(Y):
    if x * y > K:
      break
    for z in range(Z):
      if x * y * z > K:
        break
      result.append(A[x] + B[y] + C[z])

for k in list(sorted(result, reverse=True)):
  print(k)

Fixed code:

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)

result = []

for x in range(X):
  for y in range(Y):
    if x * y > K:
      break
    for z in range(Z):
      if x * y * z > K:
        break
      result.append(A[x] + B[y] + C[z])

for k in list(sorted(result, reverse=True))[:K]:
  print(k)
Buggy code:
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()
aa=[]
for i in range(k):
    if x*y-i>=0:
        aa.append(ab[x*y-i])
ans=[]
for i in range(len(aa)):
    for j in range(z):
        ans.append(aa[i]+c[j])
ans.sort()
for i in range(k):
    print(ans[len(ans)-i]
        

Fixed code:
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()
aa=[]
for i in range(k):
    if x*y-i-1>=0:
        aa.append(ab[x*y-i-1])
ans=[]
for i in range(len(aa)):
    for j in range(z):
        ans.append(aa[i]+c[j])
ans.sort()
for i in range(k):
    print(ans[len(ans)-i-1])
Buggy code:
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(len(A)):
    for j in range(len(B)):
        if (i+1) * (j+1) > K:
            continue
        for k in range(len(C)):
            if (i + 1) *(j + 1)*(k + 1) > K:
                continue
            ans.append(A[i]+B[j]+C[k])

for a in sorted(ans,reverse=True):
    print(a)


Fixed code:
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(len(A)):
    for j in range(len(B)):
        if (i+1) * (j+1) > K:
            continue
        for k in range(len(C)):
            if (i + 1) *(j + 1)*(k + 1) > K:
                continue
            ans.append(A[i]+B[j]+C[k])

for a in sorted(ans,reverse=True)[:K]:
    print(a)
Buggy code:
k = [int(i) for i in 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=True)
y.sort(reverse=True)
z.sort(reverse=True)

for i in len(x)
  for j in len(y)
    for l in len(z)
      if x*y*z =< k[3]:
        SUM.append(x[i]+y[j]+z[l])
      else:
        break

SUM.sort(reverse=True)

for i in range(k[3])
  print(SUM[i])


Fixed code:
k = [int(i) for i in 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=True)
y.sort(reverse=True)
z.sort(reverse=True)

SUM = []

for i in range(len(x)):
  for j in range(len(y)):
    for l in range(len(z)):
      if (i+1)*(j+1)*(l+1) <= k[3]:
        SUM.append(x[i]+y[j]+z[l])
      else:
        break

SUM.sort(reverse=True)

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


Fixed code:
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)
abc = []

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


Fixed code:
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)
ab = []
for i in range(x):
  for j in range(y):
    ab.append(a[i]+b[j])
ab.sort(reverse=True)
ab = ab[0:k]
abc = []
for i in ab:
  for j in c:
    abc.append(i+j)
abc.sort(reverse=True)
abc = abc[0:k]
for i in abc:
  print(i)
Buggy code:
X, Y, Z, K = 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)

F_list = []
for i in range(1, X+1):
  if i > K:
    break
  for j in range(1, Y+1):
    if i*j > K:
      break
    for k in range(1, Z+1):
      if i*j*k > K:
        break
      F_list.append(A_list[i]+B_list[j]+C_list[k])

F_list.sort(reverse=True)

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

Fixed code:
X, Y, Z, K = 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)

F_list = []
for i in range(1, X+1):
  if i > K:
    break
  for j in range(1, Y+1):
    if i*j > K:
      break
    for k in range(1, Z+1):
      if i*j*k > K:
        break
      F_list.append(A_list[i-1]+B_list[j-1]+C_list[k-1])

F_list.sort(reverse=True)

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