Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2*100000)
n, m = map(int,input().split())
mark = [-2] * (n-1)
dist = [0] * (n-1)
path = [[] for _ in range(n-1)]
path0 = []

def search(i):
    d = dist[i]
    p = []
    for p in path[i]:
        if dist[p] > d + 1 or dist[p] == 0:
            dist[p] = d + 1
            mark[p] = i
            search(p)

for _ in range(m):
    a, b = map(lambda x: int(x)-2, input().split())
    if a == -1:
        path0.append(b)
        dist[b] = 1
        mark[b] = -1
    elif b == -1:
        path0.append(a)
        dist[a] = 1
        mark[a] = -1
    else:
        path[a].append(b)
        path[b].append(a)

for p in path0:
    search(p)

print("Yes")
for i in mark: print(i+2)


### FIXED CODE ###

import sys
sys.setrecursionlimit(2*100000)
n, m = map(int,input().split())
mark = [-2] * (n-1)
dist = [0] * (n-1)
path = [[] for _ in range(n-1)]
path0 = []

for _ in range(m):
    a, b = map(lambda x: int(x)-2, input().split())
    if a == -1:
        path0.append(b)
        dist[b] = 1
        mark[b] = -1
    elif b == -1:
        path0.append(a)
        dist[a] = 1
        mark[a] = -1
    else:
        path[a].append(b)
        path[b].append(a)

while len(path0) > 0:
    i = path0.pop(0)
    d = dist[i]
    for p in path[i]:
        if dist[p] > d + 1 or dist[p] == 0:
            dist[p] = d + 1
            mark[p] = i
            path0.append(p)

print("Yes")
for i in mark: print(i+2)
### BUGGY CODE ###

a,b,m=map(int, input().split())
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m
ans = []
cou=[list(map(int, input().split())) for i in range(m)]
[ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2]) for i in range(m)]
[[ans.append(rei[j]+den[i]) for i in range(b)] for j in range(a)]
print(min(ans))

### FIXED CODE ###

m=list(map(int, input().split()))
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m[2]
ans = []
for i in range(m[2]):
	cou[i]=list(map(int, input().split()))
	ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])

ans.append(min(rei)+min(den))
print(min(ans))
### BUGGY CODE ###

n = int(input())
L = list(map(int,input().split()))
A = []
B = []
Q = [0,0]
R = [0,0]
S = [0,0]
T = [0,0]
J = 0
K = 0
for i in range(n):
  if (i%2 == 0):
    A.append(L[i])
  else:
    B.append(L[i])
A.sort()
B.sort()
for j in range(len(A)):
  J = A.count(A[j])
  if (J >= Q[0]):
    del Q[0]
    Q.insert(0,J)
    J = 0
    del R[0]
    R.insert(0,A[j])
    j += J
  elif (Q[0] >= J >= Q[1]):
    del Q[1]
    Q.append(J)
    del R[1]
    R.append(A[j])
    j += J
  else:
    j += J
for k in range(len(B)):
  K = B.count(B[k])
  if (K >= S[0]):
    del S[0]
    S.insert(0,K)
    K = 0
    del T[0]
    T.insert(0,B[j])
    k += K
  elif (S[0] >= J >= S[1]):
    del S[1]
    S.append(K)
    del T[1]
    T.append(B[k])
    k += K
  else:
    k += K
if (R[0] != T[0]):
  print(n-Q[0]-S[0])
else:
  if (Q[0] >= S[0]):
    print(n-Q[0]-S[1])
  else:
    print(n-S[0]-Q[1])

### FIXED CODE ###

n = int(input())
L = list(map(int,input().split()))
A = []
B = []
Q = [0,0]
R = [0,0]
S = [0,0]
T = [0,0]
J = 1
K = 1
for i in range(n):
  if (i%2 == 0):
    A.append(L[i])
  else:
    B.append(L[i])
A.sort()
B.sort()
A.append(-1)
B.append(-1)
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J > Q[0]):
      Q[1] = Q[0]
      del Q[0]
      Q.insert(0,J)
      R[1] = R[0]
      del R[0]
      R.insert(0,A[j-1])
      j += J
      J = 1
    elif (Q[0] >= J > Q[1]):
      del Q[1]
      Q.append(J)
      del R[1]
      R.append(A[j-1])
      j += J
      J = 1
    else:
      j += J
      J = 1
for k in range(1,len(B)):
  if (B[k-1] == B[k]):
    K += 1
  else:
    if (K > S[0]):
      S[1] = S[0]
      del S[0]
      S.insert(0,K)
      T[1] = T[0]
      del T[0]
      T.insert(0,B[k-1])
      k += K
      K = 1
    elif (S[0] >= K > S[1]):
      del S[1]
      S.append(K)
      del T[1]
      T.append(B[k-1])
      k += K
      K = 1
    else:
      k += K
      K = 1
if (R[0] != T[0]):
  print(n-Q[0]-S[0])
else:
  print(n-max(S[0]+Q[1],S[1]+Q[0]))
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))

v = L[:]
v.sort()

res = 0

import bisect

for mid in range(N-1,-1,-1):
    a = v[mid]
    for low in range(mid-1,-1,-1):
        b = v[low]
        sup = a + b
        inf = max(a-b,b-a)
        iterS = bisect.bisect_left(v,sup)
        iterI = bisect.bisect_left(v,inf+1)
        #print(a,b,sup,inf,iterS,iterI)
        res += max(low-iterI,0)

print(res)


### FIXED CODE ###

N = int(input())
L = list(map(int,input().split()))

v = L[:]
v.sort()

res = 0

import bisect

for i in range(N-2):
    a = v[i]
    for j in range(i+1,N-1):
        b = v[j]
        sup = a + b
        #inf = max(a-b,b-a)
        iterS = bisect.bisect_left(v,sup)
        #iterI = bisect.bisect_left(v,inf+1)
        #print(a,b,sup,inf,iterS,iterI)
        res += iterS - (j+1)

print(res)
### BUGGY CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))


def dfs(l):
    ret = 0
    if len(l) == 1:
        return l[0]
    elif len(l) == 0:
        return 0
    else:
        le = len(l)
        mi = min(l)
        min_ind = l.index(mi)
        ret += mi*(min_ind+1)*(le-min_ind)
        return ret + dfs(l[:min_ind])+dfs(l[min_ind+1:])


def solve():
    ans = dfs(A)
    print(ans)


def solve2():
    ans = 0
    min_cand = 1
    for i in range(N):
        prev = float('inf')
        for j in range(i, N):
            if A[j] < prev:
                if A[j] == min_cand:
                    ans += min_cand*(N-j)
                    break
                else:
                    prev = A[j]
                    ans += prev
            else:
                ans += prev
        if A[i] == min_cand and i+1 < N:
            min_cand = min(A[i+1:])

    print(ans)


# solve()
solve2()


### FIXED CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class UnionFind:
    """
    sizeによる実装
    """

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

    def same(self, x, y):
        return self.find(x) == self.find(y)


N = int(input())
A = list(map(int, input().split()))

Un = UnionFind(N+1)
pos = [-1]*(N+1)
for i, a in enumerate(A):
    pos[a] = i

ans = 0
for i in reversed(range(1, N+1)):
    ind = pos[i]
    left = 0
    right = 0
    if ind > 0 and A[ind] < A[ind-1]:
        left = Un.size[Un.find(ind-1)]
        Un.union(ind, ind-1)
    if ind+1 < N and A[ind+1] > A[ind]:
        right = Un.size[Un.find(ind+1)]
        Un.union(ind, ind+1)
    ans += (left+1)*(right+1)*A[ind]

print(ans)
### BUGGY CODE ###

import numpy as np


n = int(input())
s = []

# for i in range(n):
#     s.append(input())

buf = []
cnt = []

for i in range(n):
    buf2 = input()
    if buf2 not in buf:
        buf.append(buf2)
        cnt.append(0)
    cnt[buf.index(buf2)] += 1

# for i in s:
#     if i not in buf:
#         buf.append(i)
#         cnt.append(0)
#     cnt[buf.index(i)] += 1

ans = np.where(cnt == np.max(cnt))[0].tolist()


# ans = [i for i, x in enumerate(cnt) if x == max(cnt)]

ans2 = [buf[i] for i in range(len(buf)) if i in ans]

ans3 = sorted(ans2)

for i in ans3:
    print(i)

### FIXED CODE ###

n = int(input())
s = []

for i in range(n):
    s.append(input())

word_buf = {}

for i in s:
    if i in word_buf.keys():
        word_buf[i] += 1
    else:
        word_buf[i] = 1

max_cnt = max(word_buf.values())
max_word = [i[0] for i in word_buf.items() if i[1] == max_cnt]
max_word.sort()

for i in max_word:
    print(i)
### BUGGY CODE ###

n = int(input())
ps = list(map(int, input().split()))

result = 1
for i in range(1,n):
  if ps[i] < min(ps[:i]):
    result += 1
print(result)

### FIXED CODE ###

n = int(input())
ps = list(map(int, input().split()))

result = 0
min_p = ps[0]
for i in range(0,n):
  if ps[i] <= min_p:
    result += 1
    min_p = ps[i]
print(result)
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    a = [INT() for _ in range(n)]

    for i in range(n):
        a_ = a.copy()
        a_.pop(i)
        print(max(a_))

if  __name__=='__main__':
    main()

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    a = [INT() for _ in range(n)]
    a_ = a.copy()
    a_.sort()
    m1, m2=a_[-1], a_[-2]

    for x in a:
        if x == m1:
            print(m2)
        else:
            print(m1)

if  __name__=='__main__':
    main()
### BUGGY CODE ###

from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
import heapq
from heapq import heappush
from heapq import heappop
import random


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n,m = map(int, input().split())
p=np.zeros(m+1,dtype=int)
y=np.zeros(m+1,dtype=int)
for i in range(1,m+1):
    p[i],y[i] = map(int, input().split())


l_pref=[[] for _ in range(n+1)]    # 県の数(==n)だけ空リストを用意
for i in range(1,m+1):
    l_pref[p[i]].append((y[i],i))
for i in range(1,n+1):
    l_pref[i].sort()

eprint(l_pref)


for i in range(1,m+1):
    temp =  l_pref[p[i]].index((y[i],i))  + 1
    print("0"*(6-len(str(p[i])))  +  str(p[i])  +  "0"*(6-len(str(temp))) + str(temp) )


### FIXED CODE ###

from __future__ import print_function
# import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
import heapq
from heapq import heappush
from heapq import heappop
import random


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n,m = map(int, input().split())
p=[i for i in range(m+1)]
y=[i for i in range(m+1)]
for i in range(1,m+1):
    p[i],y[i] = map(int, input().split())


l_pref=[[] for _ in range(n+1)]    # 県の数(==n)だけ空リストを用意
for i in range(1,m+1):
    l_pref[p[i]].append((y[i],i))
for i in range(1,n+1):
    l_pref[i].sort()

# eprint(l_pref)


lll = [(1,1) for i in range(m+1)]
for i in range(1,n+1):
    for j in range(len(l_pref[i])):
        lll[l_pref[i][j][1]] = j+1
# eprint(lll)

for i in range(1,m+1):
    # temp =  l_pref[p[i]].index((y[i],i))  + 1
    print("0"*(6-len(str(p[i])))  +  str(p[i])  +  "0"*(6-len(str(lll[i]))) + str(lll[i]) )
### BUGGY CODE ###

r, g, b, n = [int(i) for i in input().split(" ")]
c = 0
for i in range(0, n // r + 1):
    for j in range(0, n // g + 1):
        t = n - i * r - j * g
        if t >= 0 and t % b == 0:
            c += 1
print(c)

### FIXED CODE ###

r, g, b, n = [int(i) for i in input().split(" ")]
c = 0
for i in range(0, n // r + 1):
    for j in range(0, n // g + 1):
        t = n - i * r - j * g
        if t >= 0 and t % b == 0:
            c += 1
print(c)
### BUGGY CODE ###

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))


N = INT()
A = LIST()

init_nodes = [0]*(N+1)
stems = [0]*(N+1)
init_nodes[0] = 1
stems[0] = 1


def solve():
    if N > 0:
        if A[0] > 0: return -1
    else:
        if A[0] == 1: return 1
        else: return -1

    if A[-1] == 0: return -1


    for i in range(N+1):
        if A[i] > 2**i:
            return -1


    for i in range(1, N+1):
        init_nodes[i] = 2 * stems[i-1]
        stems[i] = init_nodes[i] - A[i]
        if stems[i] < 0: return -1

    ans = sum(init_nodes)

    dif = init_nodes[-1] - A[-1]
    ans -= dif
    for i in reversed(range(N+1)):
        if init_nodes[i] - dif < 0: return -1
        dif = (dif-(init_nodes[i] - dif))//2
        if dif <= 0: break
        ans -= dif
    return ans

print(solve())







### FIXED CODE ###

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
import math

N = INT()
A = LIST()


if (N == 0 and A[0] != 1) or (N > 0 and A[0] != 0):
    print(-1)
    exit()


node_min, node_max = [0]*(N+1), [0]*(N+1)
node_min[-1] = A[-1]
node_max[-1] = A[-1]
for i in reversed(range(N)):
    node_min[i] = math.ceil(node_min[i+1]/2) + A[i]
    node_max[i] = node_max[i+1] + A[i]


if node_min[0] > 1:
    print(-1)
    exit()

ans = 1
node = 1
for i in range(1, N+1):
    node = min(node_max[i], 2*node)
    ans += node
    node = node - A[i]


print(ans)
### BUGGY CODE ###

import os
import sys
from functools import lru_cache

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

# グラフつくる
graph = [[] for _ in range(N ** 2)]
ins = [0] * (N ** 2)
for i in range(N):
    for j in range(N - 2):
        a, b = i, A[i][j] - 1
        a, b = min(a, b), max(a, b)
        c, d = i, A[i][j + 1] - 1
        c, d = min(c, d), max(c, d)

        graph[a * N + b].append(c * N + d)
        ins[c * N + d] += 1

# トポロジカルソート
S = []
for v in range(N ** 2):
    if ins[v] == 0:
        S.append(v)
L = []
while S:
    v = S.pop()
    L.append(v)
    for u in graph[v]:
        ins[u] -= 1
        if ins[u] == 0:
            S.append(u)
if len(L) != N ** 2:
    print(-1)
    exit()

seen = []


@lru_cache(maxsize=None)
def dfs(v):
    ret = 0
    for u in graph[v]:
        ret = max(ret, dfs(u))
    return ret + 1


ans = 0
for v in range(N ** 2):
    ans = max(ans, dfs(v))
print(ans)


### FIXED CODE ###

import os
import sys
from collections import defaultdict, deque
from functools import lru_cache

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

graph = [[] for _ in range(N ** 2)]
ins = [0] * (N ** 2)
for i in range(N):
    for j in range(N - 2):
        a, b = i, A[i][j] - 1
        c, d = i, A[i][j + 1] - 1

        if a > b:
            a, b = b, a
        if c > d:
            c, d = d, c

        graph[a * N + b].append(c * N + d)
        ins[c * N + d] += 1

zeros = []
seen = []
for v, cnt in enumerate(ins):
    if cnt == 0:
        zeros.append(v)
        seen.append(v)

ans = 0
while zeros:
    nz = []
    for v in zeros:
        for u in graph[v]:
            ins[u] -= 1
            if ins[u] == 0:
                nz.append(u)
                seen.append(u)
    zeros = nz
    ans += 1
if len(seen) == len(graph):
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

from queue import Queue
def  disintegration_Bridge(index):
    ConectMatrix[index[0]][index[1]] = '0'
    ConectMatrix[index[1]][index[0]] = '0'

def is_island(index):
    # indexから直接たどり着ける島リスト
    temp = [[i for i in range(n + 1) if ConectMatrix[j][i] == '1'] for j in range(n + 1)]
    mydic = ['0' for i in range(n+1)]
    q = Queue()
    q.put(index[0])
    while not q.empty():
        v = q.get()
        for j in temp[v]:
            if type(j) == int:
                if mydic[j] == '0':
                    mydic[j] = '1'
                    q.put(j)
            else:
                for node in j:
                    if mydic[node] == '0':
                        mydic[node] = '1'
                        q.put(node)

    if mydic[index[1]] == '1':
        return False
    else:
        return True

n, m = map(int, input().split())
a = [input().split() for i in range(m)]
a = [(int(i[0]), int(i[1])) for i in a]
ConectMatrix = [['0' for i in range(n + 1)] for j in range(n + 1)]

for brige in a:
    ConectMatrix[brige[1]][brige[0]] = '1'
    ConectMatrix[brige[0]][brige[1]] = '1'

for i in a:
    # print("-----{}----".format(i))
    # 橋の崩落
    disintegration_Bridge(i)
    # 直接繋がっていない島がある島を検索
    not_connect = [(i, j) for i in range(1, n + 1) for j in range(1, n + 1) if ConectMatrix[i][j] == '0' and i != j]
    [not_connect.remove((i[1], i[0])) for i in not_connect]
    counter = 0
    # print(not_connect)
    # 直接繋がっていないが迂回すればいけるか検索
    for index in not_connect:
        # AとBの島が迂回して繋がっているか判定
        # temp = [[i for i in range(n + 1) if ConectMatrix[j][i] == '1'] for j in range(n + 1)]
        # print(temp)
        if is_island(index):
            # print(index)
            counter = counter + 1
    print(counter)

### FIXED CODE ###

class UnionFind:
    Parents = None

    def __init__(self, N):
        self.Parents = [-1 for i in range(N + 1)]

    # Aがどのグループにいるのか調べる
    def root(self, A):
        if self.Parents[A] < 0:
            return A
        else:
            self.Parents[A] = self.root(self.Parents[A])
            return self.Parents[A]

    # Aが所属しているグループのサイズを返す
    def size(self, A):
        return -self.Parents[self.root(A)]

    # AとBをくっつける
    def Connect(self, A, B):
        if self.root(A) == self.root(B):
            return False
        if self.size(A) < self.size(B):
            self.Parents[self.root(B)] += self.Parents[self.root(A)]
            self.Parents[self.root(A)] = B
        else:
            self.Parents[self.root(A)] += self.Parents[self.root(B)]
            self.Parents[self.root(B)] = A
        return True


n, m = map(int, input().split())
a = [input().split() for i in range(m)]
a = [(int(i[0]), int(i[1])) for i in a]
ans = [int(n * (n - 1) / 2) for i in range(m)]
uni = UnionFind(n)

for i in range(m):
    if i == 0:
        continue
    A = a[-i][0]
    B = a[-i][1]

    if uni.root(A) != uni.root(B):
        ans[i] = ans[i-1] - uni.size(A) * uni.size(B)
        uni.Connect(A, B)
    else:
        ans[i] = ans[i-1]


for i in range(1, m+1):
    print(ans[-i])
### BUGGY CODE ###

N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SUM_A=[0 for _ in range(N+1)]
for i in range(N):
    SUM_A[i+1] = A[i] + SUM_A[i]
    if SUM_A[i+1] > K:
        N=i
        break

SUM_B=[0 for _ in range(M+1)]
for i in range(M):
    SUM_B[i+1] = B[i] + SUM_B[i]
    if SUM_B[i+1] > K:
        M=i
        break

cnt = N
for i in range(N+1)[::-1]:
    V=K-SUM_A[i]
    j = 0
    while j < M+1 and SUM_B[j] <= V:
        j += 1
    j-=1
    if i+j > cnt:
        cnt = i+j
print(cnt)

### FIXED CODE ###

N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SUM_A=[0 for _ in range(N+1)]
for i in range(N):
    SUM_A[i+1] = A[i] + SUM_A[i]
    if SUM_A[i+1] > K:
        N=i
        break

SUM_B=[0 for _ in range(M+1)]
for i in range(M):
    SUM_B[i+1] = B[i] + SUM_B[i]
    if SUM_B[i+1] > K:
        M=i
        break

cnt = N
for i in range(N+1)[::-1]:
    V=K-SUM_A[i]
    j = cnt-i
    while j < M+1 and SUM_B[j] <= V:
        j += 1
    j-=1
    if i+j > cnt:
        cnt = i+j
print(cnt)
### 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()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)            

ab=[]

for i in a[:k]:
    for j in b[:k]:
        ab.append(i+j)
ab.sort(reverse=True)

abc=[]
for i in ab[:k]:
    for j in c[:k]:
        abc.append(i+j)
abc.sort(reverse=True)

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

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ab = sorted(x+y for x in a for y in b)[:-k-1:-1]
abc = sorted(x+y for x in ab[:k] for y in c)[:-k-1:-1]
print(*abc, sep='\n')
### BUGGY CODE ###

n = int(input())
a = sorted(list(map(int,input().split())))

if n == 1:
    print(1)
    exit()

ans = 0
div = []
for i in range(n):
    if 0 < i and a[i] == a[i-1]:
        div += [a[i]]
        continue
    if i < n-1 and a[i] == a[i+1]:
        continue

    b = True
    for x in div:
        if a[i] < x * 2:
            break
        if a[i] % x == 0:
            b = False
    if b:
        ans += 1
        div += [a[i]]

print(ans)

### FIXED CODE ###

n = int(input())
a = sorted(list(map(int,input().split())))
m = a[-1]
b = [True]*(m+1)
for i in range(n):
    if i > 0 and a[i] == a[i-1]:
        continue
    for j in range(2, m//a[i]+1):
        b[j*a[i]] = False
ans = 0
for i in range(n):
    if 0 < i and a[i] == a[i-1]:
        continue
    if i < n-1 and a[i] == a[i+1]:
        continue
    if b[a[i]]:
        ans += 1
print(ans)
### BUGGY CODE ###

CONST = 100000

class EndLoop(Exception):
    pass

def solve():
    N = int(input())
    try:
        for h in range(1, CONST):
            for n in range(1, CONST):
                for w in range(1, CONST):
                    if ((4 * h * n * w) / (n * w + h * w + h * n)) == N:
                        print(h, n, w)
                        raise EndLoop
    except EndLoop:
        pass


solve()

### FIXED CODE ###

class EndLoop(Exception):
    pass


def solve():
    N = int(input())
    try:
        for h in range(1, 3501):
            for n in range(1, 3501):
                if 4 * h * n - n * N - h * N > 0:
                    if (h * n * N) % (4 * h * n - n * N - h * N) == 0:
                        w = int((h * n * N) / (4 * h * n - n * N - h * N))
                        print(h, n, int(w))
                        raise EndLoop
    except:
        pass


solve()
### BUGGY CODE ###

import sys
N = int(input())
a_list = list(map(int, input().split())) #[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 1]

ans = 0
value = 1


try:
    idx = a_list.index(value)
    ans += a_list.index(1)
    a_list = a_list[idx:]
    value += 1
except:
    print(-1)
    sys.exit(0)

while True:
    try:
        idx = a_list.index(value)
        ans += idx - 1
        a_list = a_list[idx:]
        value += 1
    except:
        ans += len(a_list) - 1
        break

print(ans)

### FIXED CODE ###

import sys
N = int(input())
a_list = list(map(int, input().split())) #[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 1]

try:
    idx = a_list.index(1)
except:
    print(-1)
    sys.exit(0)

#idx = 0
value = 1

for k, v in enumerate(a_list):
    if idx <= k and value+1 == v:
        value += 1

print(len(a_list) - value)
### BUGGY CODE ###

A, B, C, K = list(map(int, input().split()))

ans = 0
while K:
  if A:
    ans += 1
    A -= 1
  elif B:
    B -= 1
  else:
    ans -= 1

print(str(ans))

### FIXED CODE ###

A, B, C, K = list(map(int, input().split()))

ans = 0
if A > K:
  print(K)
elif A == K:
  print(A)
elif A + B >= K:
  print(A)
else:
  print(A - (K - A - B))