Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [i for i in input().split()]
outStr = []
if n % 2 == 0:
    for i in range(n):
        # print("i:{} outStr:{}".format(i, outStr))
        if i % 2 == 1:
            outStr = [a[i]] + outStr
        else:
            outStr.append(a[i])
        # print("i:{} outStr:{}\n".format(i, outStr))
    print(" ".join(outStr))
else:
    for i in range(n):
        if i % 2 == 0:
            outStr = [a[i]] + outStr
        else:
            outStr.append(a[i])
    print(" ".join(outStr))

Fixed submission:
n = int(input())
a = [i for i in input().split()]
outStr = []
if n % 2 == 0:
    for i in reversed(range(int(n/2))):
        outStr += [a[int(i * 2)+1]]
    for i in range(int(n/2)):
        outStr += [a[int(i*2)]]
    print(" ".join(outStr))
else:
    for i in reversed(range(int(n/2)+1)):
        outStr += [a[int(i*2)]]
    for i in range(int(n/2)):
        outStr += [a[int(i*2)+1]]
    print(" ".join(outStr))
Buggy python submission (verdict: Time Limit Exceeded):
def func(n, W, w):
    # ナップザック問題
    # 残り荷物 iつで,残り容量jの場合の最大価値
    dp = [[0 for _ in range(W+1)] for _ in range(n+1)]
    for i in range(1, len(dp)):
        for j in range(len(dp[0])):
            if j-w[-i][0] >= 0:
                dp[i][j] = max(dp[i-1][j-w[-i][0]] + w[-i][1], dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]
    # for i in range(len(dp)):
        # print(dp[i])
    return dp[n][W]
n, W = [int(i) for i in input().split()]
w = [[0, 0] for _ in range(n)]
for i in range(n):
    w[i] = [int(i) for i in input().split()]
print(func(n, W, w))
"""
# print("print(\" vs \" + str(func({}, {}, {})))".format(n, W, w))
print("11 vs " + str(func(4, 6, [[2, 1], [3, 4], [4, 10], [3, 4]])))
print("13 vs " + str(func(4, 6, [[2, 1], [3, 7], [4, 10], [3, 6]])))
print("400 vs " + str(func(4, 10, [[1, 100], [1, 100], [1, 100], [1, 100]])))
print("0 vs " + str(func(4, 1, [[10, 100], [10, 100], [10, 100], [10, 100]])))
"""


Fixed submission:
def func(n, W, w):  # ナップザック問題の亜種
    _max = 0
    weights = [[] for _ in range(4)]
    for i in range(n):
        weights[w[i][0]-w[0][0]].append(w[i][1])
    for i in range(len(weights)):
        weights[i].sort()
        weights[i].append(0)
        weights[i].reverse()
        for j in range(1, len(weights[i])):
            weights[i][j] += weights[i][j-1]
    # print(weights)
    for i in range(len(weights[0])):
        # print("i:{}".format(i))
        for j in range(len(weights[1])):
            # print("j:{}".format(j))
            for k in range(len(weights[2])):
                for l in range(len(weights[3])):
                    # 「i+j+k+l < n」つ選ぶ
                    if w[0][0]*i\
                            + (w[0][0]+1)*j\
                            + (w[0][0]+2)*k\
                            + (w[0][0]+3)*l <= W:
                        # print("i:{} j:{} k:{} l:{} score:{}".format(i, j, k, l, weights[0][i]+weights[1][
                        # j]+weights[2][k]+weights[3][l]))
                        _max = max(_max, weights[0][i]+weights[1][j]+weights[2][k]+weights[3][l])
    return _max


n, W = [int(i) for i in input().split()]
w = [[0, 0] for _ in range(n)]
for i in range(n):
    w[i] = [int(i) for i in input().split()]
print(func(n, W, w))
"""
# print("print(\" vs \" + str(func({}, {}, {})))".format(n, W, w))
print("11 vs " + str(func(4, 6, [[2, 1], [3, 4], [4, 10], [3, 4]])))
print("13 vs " + str(func(4, 6, [[2, 1], [3, 7], [4, 10], [3, 6]])))
print("400 vs " + str(func(4, 10, [[1, 100], [1, 100], [1, 100], [1, 100]])))
print("0 vs " + str(func(4, 1, [[10, 100], [10, 100], [10, 100], [10, 100]])))
"""
Buggy python submission (verdict: Time Limit Exceeded):
# 入力 : 自然数     ex) 12
# 出力 : 約数リスト ex) [2, 2, 3]
def factorization(n):
    R = int(n)
    s = 0
    L = []
    div = 2
    while s == 0:
        for i in range(div, R + 1):
            if n % i == 0:
                n = n / i
                div = i
                if n == 1:
                    s = 1
                L.append(i)
                break
    return L


n = int(input())
if n == 1:
    print(1)
    exit()
divs = factorization(n)
N = [i for i in divs]  # N = bit探索する桁数
maxDigit = n
# Nの要素の全組み合わせが出力
for i in range(1, 1 << len(N)):
    output = []
    nonout = []
    outNum = 1
    nonOutNum = 1
    for j in range(len(N)):
        if ((i >> j) & 1) == 1:
            output.append(N[j])  # このjが今回探索するindexの1つ
            outNum *= N[j]
        else:
            nonout.append(N[j])
            nonOutNum *= N[j]
    # print("{} vs {}".format(outNum, nonOutNum))
    digitOut = 0
    digitNonOut = 0
    while outNum > 0:
        digitOut += 1
        outNum = int(outNum / 10)
    while nonOutNum > 0:
        digitNonOut += 1
        nonOutNum = int(nonOutNum / 10)
    if max(digitOut, digitNonOut) < maxDigit:
        maxDigit = max(digitOut, digitNonOut)
print(maxDigit)


Fixed submission:
# 入力 : 自然数     ex) 12
# 出力 : 約数リスト ex) [(2,2),(3,1)]
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base ** exponent
    return a

n = int(input())
if n == 1:
    print(1)
    exit()
fct = factorize(n)
maxDigit = n
for div in divisorize(fct):
    outNum = num(div)
    nonOutNum = int(n/outNum)
    digitOut = 0
    digitNonOut = 0
    while outNum > 0:
        digitOut += 1
        outNum = int(outNum / 10)
    while nonOutNum > 0:
        digitNonOut += 1
        nonOutNum = int(nonOutNum / 10)
    if max(digitOut, digitNonOut) < maxDigit:
        maxDigit = max(digitOut, digitNonOut)
print(maxDigit)
Buggy python submission (verdict: Time Limit Exceeded):
k, s = [int(i) for i in input().split()]

count = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z == s:
                count += 1
print(count)

Fixed submission:
k, s = [int(i) for i in input().split()]

count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            # print("{} {} {}".format(x, y, z))
            count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
a, op, b = [int(i) for i in input().split()]
if op == "+":
    print(int(a) + int(b))
else:
    print(int(a) - int(b))


Fixed submission:
a, op, b = [i for i in input().split()]
if op == "+":
    print(int(a) + int(b))
else:
    print(int(a) - int(b))
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
vote = [0, 0]
# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<=t*k, vote[1]<=a*kとなる
# 最小のt*k,a*kでvoteを更新
vote = [1, 1]
for i in range(n):
    t, a = [int(i) for i in input().split()]
    k = max(math.ceil(vote[0] / t), math.ceil(vote[1] / a))
    vote = [t * k, a * k]
    if sum(vote) > 10**10:
        t[1000000000] = 1
    # print("i:{} vote:{}".format(i, vote))
print(vote[0] + vote[1])


Fixed submission:
import math

n = int(input())
vote = [0, 0]
# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<=t*k, vote[1]<=a*kとなる
# 最小のt*k,a*kでvoteを更新
vote = [1, 1]
for i in range(n):
    t, a = [int(i) for i in input().split()]
    if vote[0] % t == 0:
        k = vote[0] // t
    else:
        k = vote[0] // t + 1
    if vote[1] % a == 0:
        k = max(k, vote[1] // a)
    else:
        k = max(k, vote[1] // a + 1)
    # k = max(math.ceil(vote[0] / t), math.ceil(vote[1] / a))
    vote = [t * k, a * k]
    # a / b + (a % b == 0 ? 0: 1)
    # print("i:{} vote:{}".format(i, vote))
print(vote[0] + vote[1])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
vote = [int(i) for i in input().split()]

# 各入力に対し、vote[0]<tk, vote[1]<akとなる
# 最小のtk,akでvoteを更新
for i in range(n-1):
    # print(i)
    t, a = [int(i) for i in input().split()]
    # vote[0]<tk, vote[1]<akとなるkを算出(k<nなのでO(n))
    for k in range(1, 10000000):
        # print("k:{}".format(k))
        if t*k >= vote[0] and a*k >= vote[1]:
            vote = [t*k, a*k]
            break
    # print("vote:{}".format(vote))
print(sum(vote))

Fixed submission:
import math

n = int(input())
vote = [0, 0]
# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<=t*k, vote[1]<=a*kとなる
# 最小のt*k,a*kでvoteを更新
vote = [1, 1]
for i in range(n):
    t, a = [int(i) for i in input().split()]
    if vote[0] % t == 0:
        k = vote[0] // t
    else:
        k = vote[0] // t + 1
    if vote[1] % a == 0:
        k = max(k, vote[1] // a)
    else:
        k = max(k, vote[1] // a + 1)
    # k = max(math.ceil(vote[0] / t), math.ceil(vote[1] / a))
    vote = [t * k, a * k]
    # a / b + (a % b == 0 ? 0: 1)
    # print("i:{} vote:{}".format(i, vote))
print(vote[0] + vote[1])
Buggy python submission (verdict: Time Limit Exceeded):
_x = input()
x = []
for i in _x:
    x.append(i)
count = 0
i = 0
while i < len(x):
    # print("i:{} x:{}".format(i, x))
    if i < len(x) - 1 and x[i] == "S" and x[i + 1] == "T":
        del x[i]
        del x[i]
        if i > 0:
            i -= 1
        continue
    else:
        count += 1
        i += 1
print(len(x))


Fixed submission:
_x = input()
x = []
for i in _x:
    x.append(i)
count = 0

# 今まで確認してきたものはスタックに入れる
# スタックの頂上がSで次の入力がTならスタックをポップ
stack = []
i = 0
while i < len(x):
    if len(stack) > 0 and stack[-1] == "S" and x[i] == "T":
        del stack[-1]
    else:
        stack.append(x[i])
    i += 1
print(len(stack))
# print(stack)
Buggy python submission (verdict: Runtime Error):
def listToString(_list, split=""):
    maped_list = map(str, _list)  # mapで要素すべてを文字列に
    mojiretu = split.join(maped_list)
    return mojiretu


s = input()
out = []
for i in range(len(s)):
    if s[i] == "0":
        out.append("0")
    elif s[i] == "1":
        out.append("1")
    else:
        out.pop()
print(listToString(out))

Fixed submission:
def listToString(_list, split=""):
    maped_list = map(str, _list)  # mapで要素すべてを文字列に
    mojiretu = split.join(maped_list)
    return mojiretu


s = input()
out = []
for i in range(len(s)):
    if s[i] == "0":
        out.append("0")
    elif s[i] == "1":
        out.append("1")
    else:
        if len(out) > 0:
            out.pop()
print(listToString(out))
Buggy python submission (verdict: Runtime Error):
a , b, c = map(int, input().split())
d =  b // a 
if d > c:
  return c
else:
  return d

Fixed submission:
a , b, c = map(int, input().split())
d =  b // a 
if d > c:
  print(c)
else:
  print(d)
Buggy python submission (verdict: Runtime Error):
a , b, c = map(int, input().split())
X = []
for i in range(min([a,b])):
  if a % i == 0 and b % i == 0:
    X.append(i)
print(X[-c])

Fixed submission:
a , b, c = map(int, input().split())
X = []
for i in range(min([a,b])):
  if a % (i+1) == 0 and b % (i+1) == 0:
    X.append((i+1))
print(X[-c])

Buggy python submission (verdict: Runtime Error):
a , b, c = map(int, input().split())
X = []
for i in range(max(a,b)):
  if a % i == 0 and b % i == 0:
    X.append(i)
print(X[-c])

Fixed submission:
a , b, c = map(int, input().split())
X = []
for i in range(min([a,b])):
  if a % (i+1) == 0 and b % (i+1) == 0:
    X.append((i+1))
print(X[-c])

Buggy python submission (verdict: Runtime Error):
a , b, c = map(int, input().split())
X = []
for i in range(max(a,b)):
  if a % i == 0 and b % i == 0:
    X.append(i)
print(X[c])

Fixed submission:
a , b, c = map(int, input().split())
X = []
for i in range(min([a,b])):
  if a % (i+1) == 0 and b % (i+1) == 0:
    X.append((i+1))
print(X[-c])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s = list(s)
count = 0
#for j in range(100):
while(1):
    length = len(s)
    for i in range(len(s)):
        try:
            if s[i] != s[i+1]:
                s.pop(i)
                s.pop(i)
                count = count+1
        except IndexError:
            pass
    if length == len(s):
        break
    
print(count*2)


Fixed submission:
s = input()
print(2*min(s.count('0'),s.count('1')))
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
S=S+'#'
sc=0
tc=0
ans=0
for i in range(N+1):
    if(tc!=0 and S[i]=='#'):
        if(sc>tc):
            ans+=tc
            sc+=tc
        else:
            ans+=sc
            sc=0
        tc=0

    if(sc!=0 and S[i]=='.'):
        tc+=1
    elif(tc==0 and S[i]=='#'):
        sc+=1
print(str(ans))







Fixed submission:
a,b,c=map(int,input().split(" "))
if(a>b):
    n=a
    a=b
    b=n
if(c>a and c<b):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=list(map(int,input().split()))
ans=0
aa=list(set(a))

for i in aa:
    cnt=a.count(i)
    if cnt>i:
        ans+=cnt-i
    elif cnt<i:
        ans+=cnt

print(str(ans))




Fixed submission:
N=int(input())
a=list(map(int,input().split()))
ans=0
aa=list(set(a))
dict={}
for s in aa:
    dict[s]=0
for l in a:
    dict[l]+=1
for i in dict.items():
    num=i[0]
    amount=i[1]
    """                                                           
    cnt=a.count(i)                                                
    if cnt>i:                                                     
        ans+=cnt-i                                                
    elif cnt<i:                                                   
        ans+=cnt                                                  
    """
    if amount>num:
        ans+=amount-num
    elif amount<num:
        ans+=amount
print(str(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=list(map(int,input().split()))
ans=0
aa=list(set(a))

for i in range(len(aa)):
    cnt=a.count(aa[i])
    if cnt>aa[i]:
        ans+=cnt-aa[i]
    elif cnt<aa[i]:
        ans+=cnt

print(str(ans))

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
ans=0
aa=list(set(a))
dict={}
for s in aa:
    dict[s]=0
for l in a:
    dict[l]+=1
for i in dict.items():
    num=i[0]
    amount=i[1]
    """                                                           
    cnt=a.count(i)                                                
    if cnt>i:                                                     
        ans+=cnt-i                                                
    elif cnt<i:                                                   
        ans+=cnt                                                  
    """
    if amount>num:
        ans+=amount-num
    elif amount<num:
        ans+=amount
print(str(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=list(map(int,input().split()))
ans=0
while(N!=0):
    cnt=a.count(a[0])
    if cnt>a[0]:
        ans+=cnt-a[0]
    elif cnt<a[0]:
        ans+=cnt
    x=a[0]
    for i in range(cnt):
        a.remove(x)
    N=len(a)
print(str(ans))

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
ans=0
aa=list(set(a))
dict={}
for s in aa:
    dict[s]=0
for l in a:
    dict[l]+=1
for i in dict.items():
    num=i[0]
    amount=i[1]
    """                                                           
    cnt=a.count(i)                                                
    if cnt>i:                                                     
        ans+=cnt-i                                                
    elif cnt<i:                                                   
        ans+=cnt                                                  
    """
    if amount>num:
        ans+=amount-num
    elif amount<num:
        ans+=amount
print(str(ans))
Buggy python submission (verdict: Runtime Error):
n=[]
for i in range(5):
  n[i]=int(input())
k=int(input())
mi=min(n)
ma=max(n)
if k <= ma-mi:
  print("Yay!")
else:
  print(":(")

        

Fixed submission:
n=[0]*5
for i in range(5):
  n[i]=int(input())
k=int(input())
mi=min(n)
ma=max(n)
if k >=ma-mi:
  print("Yay!")
else:
  print(":(")
Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
S = input()
a = []
for i in range(M):
    a.append(list(map(int, input().split())))
for i in range(M):
  print(S[a[i][0]-1:a[i][1]].count('AC'))

Fixed submission:
b = input()
if b=="A":
  print("T")
elif b=="T":
  print("A")
elif b=="G":
  print("C")
else:
  print("G")
Buggy python submission (verdict: Runtime Error):
b = input()
l = len(b)
ans = []
kotae = 1
c = []
for i in range(l):
  if b[i]=="A" or b[i]=="T" or b[i]=="G" or b[i]=="C":
    ans.append(i)
l2 = len(ans)
for i in range(l2-1):
  if (ans[i+1]-ans[i])==1 and i==l2-2:
    kotae+=1
    c.append(kotae)
  elif (ans[i+1]-ans[i])==1:
    kotae+=1
  else:
    c.append(kotae)
    kotae=1
if ans==[]:
  print(0)
else:print(max(c))

Fixed submission:
b = input()
l = len(b)
ans = []
kotae = 1
c = []
for i in range(l):
  if b[i]=="A" or b[i]=="T" or b[i]=="G" or b[i]=="C":
    ans.append(i)
l2 = len(ans)
if l2==1:
  c.append(1)
for i in range(l2-1):
  if (ans[i+1]-ans[i])==1 and i==l2-2:
    kotae+=1
    c.append(kotae)
  elif (ans[i+1]-ans[i])==1:
    kotae+=1
  else:
    c.append(kotae)
    kotae=1
if ans==[]:
  print(0)
else:print(max(c))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
length=len(s)
l = int(len(s)/2)
def erase_01_10(moji):
  moji = moji.replace('01','').replace('0011','').replace('000111','').replace('00001111','').replace('0000011111','')
  moji = moji.replace('10','').replace('1100','').replace('111000','').replace('11110000','').replace('1111100000','')
  return moji
for i in range(l):
  if s == erase_01_10(s):
    break
  s = erase_01_10(s)
print(length-len(s))


Fixed submission:
s = input()
length=len(s)
#print(s.count('0'))
#print(s.count('1'))
m=min(s.count('0'),s.count('1'))
print(2*m)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
length=len(s)
l = int(len(s)/2)
def erase_01_10(moji):
  moji = moji.replace('01','').replace('0011','').replace('000111','')
  moji = moji.replace('10','').replace('1100','').replace('111000','')
  return moji
for i in range(l):
  if s == erase_01_10(s):
    break
  s = erase_01_10(s)
print(length-len(s))


Fixed submission:
s = input()
length=len(s)
#print(s.count('0'))
#print(s.count('1'))
m=min(s.count('0'),s.count('1'))
print(2*m)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
length=len(s)
l = int(len(s)/2)
def erase_01_10(moji):
  if moji.count('01')>0:
    moji = moji.replace('01','')
  elif moji.count('10')>0:
    moji = moji.replace('10','')
  return moji
for i in range(l):
  if s == erase_01_10(s):
    break
  s = erase_01_10(s)
print(length-len(s))

Fixed submission:
s = input()
length=len(s)
#print(s.count('0'))
#print(s.count('1'))
m=min(s.count('0'),s.count('1'))
print(2*m)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
l = int(len(s)/2)
def erase_01_10(moji):
  if moji.count('01')>0:
    moji = moji.replace('01','',1)
  elif moji.count('10')>0:
    moji = moji.replace('10','',1)
  return moji
count=0
for i in range(l):
  if s == erase_01_10(s):
    break
  s = erase_01_10(s)
  count+=2
print(count)


Fixed submission:
s = input()
length=len(s)
#print(s.count('0'))
#print(s.count('1'))
m=min(s.count('0'),s.count('1'))
print(2*m)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

cap = [a, b, c, d, e]
city = [n, 0, 0, 0, 0, 0]

t = 0
while city[5] != n:
    schedule = [0, 0, 0, 0, 0, 0]
    t += 1
    for i in range(len(cap)):
        if city[i] < cap[i]:
            schedule[i + 1] += city[i]
            schedule[i] -= city[i]
        else:
            schedule[i] -= cap[i]
            schedule[i + 1] += cap[i]
    for i in range(len(schedule)):
        city[i] += schedule[i]
print(t)

Fixed submission:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

cap = [a, b, c, d, e]

min_pos = 0
for p in range(len(cap)):
    if cap[p] < cap[min_pos]:
        min_pos = p

if n % cap[min_pos] == 0:
    print(4 + n // cap[min_pos])
else:
    print(5 + n // cap[min_pos])
Buggy python submission (verdict: Runtime Error):
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.reverse()
b.reverse()
c.reverse()

counter = 0
a_idx = 0
b_idx = 0
c_idx = 0
while counter < k:
    print(a[a_idx] + b[b_idx] + b[b_idx])
    counter += 1

    a_diff = -1
    b_diff = -1
    c_diff = -1
    diff = []
    if a_idx < len(a) - 1:
        a_diff = a[a_idx] - a[a_idx + 1]
        diff.append(a_diff)
    if b_idx < len(b) - 1:
        b_diff = b[b_idx] - b[b_idx + 1]
        diff.append(b_diff)
    if c_idx < len(c) - 1:
        c_diff = c[c_idx] - c[c_idx + 1]
        diff.append(c_diff)
    min_diff = min(diff)

    for i, d in enumerate([a_diff, b_diff, c_diff]):
        if d == min_diff:
            if i == 0:
                a_idx += 1
            elif i == 1:
                b_idx += 1
            else:
                c_idx += 1

Fixed submission:
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 = sorted(a, key=lambda x: x * -1)
b = sorted(b, key=lambda x: x * -1)
c = sorted(c, key=lambda x: x * -1)

counter = 0
a_idx = 0
b_idx = 0
c_idx = 0
pque = []
heapq.heappush(pque, (-1 * (a[a_idx] + b[b_idx] + c[c_idx]), (a_idx, b_idx, c_idx)))

while counter < k:
    counter += 1
    output = heapq.heappop(pque)
    print(output[0] * -1)
    a_idx, b_idx, c_idx = output[1]
    if a_idx < len(a) - 1:
        current = a[a_idx + 1] + b[b_idx] + c[c_idx]
        cand = (a_idx + 1, b_idx, c_idx)
        if (-1 * current, cand) not in pque:
            heapq.heappush(pque, (-1 * current, cand))
    if b_idx < len(b) - 1:
        current = a[a_idx] + b[b_idx + 1] + c[c_idx]
        cand = (a_idx, b_idx + 1, c_idx)
        if (-1 * current, cand) not in pque:
            heapq.heappush(pque, (-1 * current, cand))
    if c_idx < len(c) - 1:
        current = a[a_idx] + b[b_idx] + c[c_idx + 1]
        cand = (a_idx, b_idx, c_idx + 1)
        if (-1 * current, cand) not in pque:
            heapq.heappush(pque, (-1 * current, cand))