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

import heapq

tmp = list(map(int, input().split()))
x = tmp[0]
y = tmp[1]
z = tmp[2]
k = tmp[3]
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)

log = [[[False for _ in range(z)] for _ in range(y)] for _ in range(x)]

cnt = 0
h = []
heapq.heappush(h, (-(a[0]+b[0]+c[0]), 0, 0, 0))
while len(h) != 0 and cnt < k: 
  tmp = heapq.heappop(h)
  print(-tmp[0])
  cnt += 1
  if tmp[1]+1 < x and log[tmp[1]+1][tmp[2]][tmp[3]] == False:
    heapq.heappush(h, (-(a[tmp[1]+1]+b[tmp[2]]+c[tmp[3]]), tmp[1]+1, tmp[2], tmp[3]))
    log[tmp[1]+1][tmp[2]][tmp[3]] = True
  if tmp[2]+1 < y and log[tmp[1]][tmp[2]+1][tmp[3]] == False:
    heapq.heappush(h, (-(a[tmp[1]]+b[tmp[2]+1]+c[tmp[3]]), tmp[1], tmp[2]+1, tmp[3]))
    log[tmp[1]][tmp[2]+1][tmp[3]] = True
  if tmp[3]+1 < z and log[tmp[1]][tmp[2]][tmp[3]+1] == False:
    heapq.heappush(h, (-(a[tmp[1]]+b[tmp[2]]+c[tmp[3]+1]), tmp[1], tmp[2], tmp[3]+1))
    log[tmp[1]][tmp[2]][tmp[3]+1] = True

### FIXED CODE ###

tmp = list(map(int, input().split()))
x = tmp[0]
y = tmp[1]
z = tmp[2]
k = tmp[3]
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)

ansl = []
for p in range(x):
  if p > k:
    break
  for q in range(y):
    if p * q > k:
      break
    for r in range(z):
      if p * q * r > k:
        break
      ansl.append(a[p] + b[q] + c[r])

ansl.sort(reverse=True)

for i in range(k):
  print(ansl[i])
### BUGGY CODE ###

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

for i in range(1, n+1):
    print(a.count(i))

### FIXED CODE ###

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

ans = [0]*n
for i in a:
    ans[i-1] += 1
for i in range(n):
    print(ans[i])
### BUGGY CODE ###

from collections import defaultdict as dd
from collections import Counter
from pprint import pprint as pp

YN = {True: 'Yes', False: 'No'}
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]
rs = lambda: input()
rsa = lambda: input().split()
rsn = lambda n: [rs() for _ in range(n)]

N = ri()
A = ria()
ret = len(A)

for l in range(1, len(A)):
  c = A[l-1]
  for x in A[l:]:
    if c & x != 0:
      break
    ret += 1
    c |= x
print(ret)

### FIXED CODE ###

from collections import defaultdict as dd
from collections import Counter
from pprint import pprint as pp

YN = {True: 'Yes', False: 'No'}
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]
rs = lambda: input()
rsa = lambda: input().split()
rsn = lambda n: [rs() for _ in range(n)]

N = ri()
A = ria()

ret = 0
l = 0
lr = 0

acc = 0
while l < len(A) and lr < len(A):
  if acc & A[lr] == 0:
    ret += 1
    acc |= A[lr]
    lr += 1
    if lr == len(A):
      for i in range(len(A) - l):
        ret += i
      break
  else:
    acc ^= A[l]
    l += 1
    if l != lr:
      ret += lr - l

print(ret)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

p = []

for i in A:
    if i not in p:
        p.append(i)
    else:
        p.remove(i)

print(len(p))


### FIXED CODE ###

from collections import Counter

N = int(input())
A = [int(input()) for _ in range(N)]

res = 0

c = Counter(A)

for i in c.values():
    if i % 2 != 0:
        res += 1

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

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

s=set(a)

c=0
for i in s:
    t=a.count(i)
    if(t-i>=0):
        c+=(t-i)
    else:
        c+=t

print(c)

### FIXED CODE ###

from collections import defaultdict

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

d=defaultdict(int)
for b in a:
    d[b] +=1

c=0
for k,v in d.items():
    if(k>v):
        c+=v
    else:
        c+=v-k

print(c)
### BUGGY CODE ###

x,y = map(int, input().split())
list = [x, y]

while True:

    if x == 0 and y == 0 : break

    print(sorted(list, reverse=True))
       


### FIXED CODE ###

while True:
    x,y = map(int, input().split())

    if x == 0 and y == 0:
        break

    elif x <= y:
        print(str(x) + " " + str(y))
    else:
        print(str(y) + " " + str(x))
### BUGGY CODE ###

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


MOD=[0] * (2019*2019)

def myidx(i,j):
    return i * 2019 + j

for i in range(2019):
    for j in range(2019):
        idx = myidx(i,j)
        MOD[idx] = (i*j) % 2019

for i in range(2019):
    idx = myidx(i,i)
    MOD[idx] = 2019

MMM = []

if L+2019 <= R:
    MMM = MOD

Lmod = L % 2019
Rmod = R % 2019
if Lmod <= Rmod:
    for i in range(Lmod, Rmod+1):
        for j in range(i+1, Rmod+1):
            idx = myidx(i,j)
            MMM.append(MOD[idx])

if Lmod > Rmod:
    for i in list(range(0,Rmod+1)) + list(range(Lmod, 2019)):
        for j in list(range(i+1,Rmod+1)) + list(range(Lmod, 2019)):
            idx = myidx(i,j)
            MMM.append(MOD[idx])

MMM.sort()
print(MMM.pop(0))


### FIXED CODE ###

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

MOD=[0] * (2019*2019)

def myidx(i,j):
    return i * 2019 + j

for i in range(2019):
    for j in range(i+1,2019):
        idx = myidx(i,j)
        MOD[idx] = (i*j) % 2019

#for i in range(2019):
#    idx = myidx(i,i)
#    MOD[idx] = 2019

MMM = []
MIN = 2019
Lmod = L % 2019
Rmod = R % 2019

if L+2019 <= R:
    for i in range(2019):
        for j in range(i+1,2019):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])
elif Lmod <= Rmod:
    for i in range(Lmod, Rmod+1):
        for j in range(i+1, Rmod+1):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])

elif Lmod > Rmod:
    for i in list(range(0,Rmod+1)) + list(range(Lmod, 2019)):
        for j in list(range(i+1,Rmod+1)) + list(range(max(Lmod,i+1), 2019)):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])

#MMM=list(set(MMM))
#MMM.sort()
#print(MMM.pop(0))
print(MIN)
### BUGGY CODE ###

#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left
#from copy import deepcopy
#import heapq
#import math
#import string

setrecursionlimit(10**6)
input=stdin.readline

def nibu(A,lo,hi,a,b):
    #print(lo,hi)
    while lo<hi:
        m=(lo+hi)//2
        if abs(A[a]-A[b])<A[m]<A[a]+A[b]: lo=m+1
        else: hi=m
        #print(lo,hi)
    return m

n=int(input().rstrip())
l=sorted([int(i) for i in input().split()],reverse=True)
#print(*l)
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for c in range(j+1,n):
            if abs(l[i]-l[j])<l[c]<l[i]+l[j]:
                t=nibu(l,c,n,i,j)
                #print(t,j)
                ans+=t-j
                break
print(ans)

### FIXED CODE ###

#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
from bisect import bisect_left
#from copy import deepcopy
#import heapq
#import math
#import string

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
l=sorted([int(i) for i in input().split()])
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        m=bisect_left(l,l[i]+l[j])
        ans+=m-j-1
        #print(m)
print(ans)
### BUGGY CODE ###

s = input()[::-1]
num = len(s)

l = []
for i in range(1, num+1):
    tmp = s[:i][::-1]
    l.append(int(''.join(tmp)))

cnts = [1] + [0] * (2019 - 1)

for j in range(num):
    cnts[l[j] % 2019] += 1

ans = 0
for cnt in cnts:
    ans += (cnt-1)*cnt//2

print(ans)


### FIXED CODE ###

s = input()[::-1]

cnts = [1] + [0] * (2019 - 1)
tmp = 0
d = 1

for i in s:
    tmp += int(i) * d
    cnts[tmp % 2019] += 1
    d = d * 10 % 2019 # 桁数が大きくなりすぎる → 10と2019が素だから可能

ans = 0
for cnt in cnts:
    ans += (cnt - 1) * cnt // 2

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

n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  print(a.count(i+1)) 


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
x=[0]*n
for i in a:
  x[i-1]+=1
for i in x:
  print(i)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import defaultdict,deque

N=input()
AL=defaultdict(lambda: set())
IN=defaultdict(lambda: 0)
BEGIN=set()

for i in range(N):
	A=map(int, sys.stdin.readline().split())
	for j in range(N-2):
		x=i+1
		x_next=i+1
		y=A[j]
		y_next=A[j+1]
		#print x,y,x_next,y_next
		if x>y: x,y=y,x
		if x_next>y_next: x_next,y_next=y_next,x_next
		IN[(x_next,y_next)]+=1
		AL[(x,y)].add((x_next,y_next))

		if j==0:
			BEGIN.add((x,y))


q=deque()

for x,y in BEGIN:
	if IN[(x,y)]==0:
		q.append((x,y))


DAY=defaultdict(lambda: 1)	#距離

ans=-1
cnt=0
#while q and cnt<100000:
while q:
	fro=q.pop()
	for to in AL[fro]:
		alt=DAY[fro]+1
		if DAY[to]<alt:
			ans=max(ans,alt)
			DAY[to]=alt
			q.append((to[0],to[1]))
	cnt+=1

print ans

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
from collections import defaultdict,deque

N=input()
A=[[]]+[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
C=defaultdict(lambda: 0)

Now=[ 0 for _ in range(N+1)]
game=set()
next_game=set()

for i in range(1,N+1):
	a=i
	b=A[i][0]
	if a>b: a,b=b,a
	game.add((a,b))

day=0

while game:
	next_game=set()
	Visit=defaultdict(lambda: None) 

	for x,y in game:
		now_x=Now[x]
		now_y=Now[y]

		xopp=A[x][now_x]
		yopp=A[y][now_y]

		if (x,y)==(yopp,xopp) and Visit[x] is None and Visit[y] is None:
			Visit[x]=1
			Visit[y]=1
			if now_x<N-2:
				now_x+=1
				Now[x]=now_x
				x_nextopp=A[x][now_x]
				if x_nextopp<x: x,x_nextopp=x_nextopp,x
				next_game.add((x,x_nextopp))

			if now_y<N-2:
				now_y+=1
				Now[y]=now_y
				y_nextopp=A[y][now_y]
				if y_nextopp<y: y,y_nextopp=y_nextopp,y
				next_game.add((y,y_nextopp))

	game=next_game
	day+=1


for i in range(1,N+1):
	if Now[i] != N-2:
		print -1
		quit()
else:
	print day
### BUGGY CODE ###

import sys
from bisect import bisect_right
input = sys.stdin.readline

n, m = map(int, input().split())
ba = []
for _ in range(n):
    a, b = map(int, input().split())
    ba.append([b, a])
ba.sort(reverse=True)
days = [x for x in range(m)]
ans = 0
for x in ba:
    a = x[1]
    b = x[0]
    lim = m - a
    d = bisect_right(days, lim)
    if d > 0:
        ans += b
        days = days[:d-1] + days[d:]
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
from heapq import *


n, m = map(int, input().split())
tmp = [ [] for _ in range(10 ** 5 + 1) ]
for _ in range(n):
    a, b = map(int, input().split())
    tmp[a].append(b)

h = []
ans = 0
for i in range(1, m+1):
    for bb in tmp[i]:
        heappush(h, -bb)
    if h:
        ans += -heappop(h)
print(ans)
### BUGGY CODE ###

import sys
from functools import lru_cache

sys.setrecursionlimit(1000000)

H, N = map(int, input().split())

AB = []
for i in range(N):
  A, B = map(int, input().split())
  AB.append((A, B))

'''
H = 10000
N = 1000
import random
AB = []
for i in range(N):
    A = random.randint(1, 10000)
    B = random.randint(1, 10000)
    AB.append((A, B))
'''




@lru_cache(maxsize=None)
def f(h):
    if h <= 0:
        return 0
    return min(b + f(h - a) for a, b in AB)

#AB.sort(key=lambda ab: (ab[0] / ab[1], -ab[0]))
#bestA, bestB = AB[-1]

bestA, bestB = max(AB, key=lambda ab: (ab[0] / ab[1], -ab[0]))
threshold = sum(a for a, b in AB)

ans = None
times = (H - threshold) // bestA
if times > 0:
    ans = bestB * times + f(H - bestA * times)
else:
    ans = f(H)

print(ans)

### FIXED CODE ###

import sys
from functools import lru_cache

sys.setrecursionlimit(1000000)

H, N = map(int, input().split())

AB = []
for i in range(N):
  A, B = map(int, input().split())
  AB.append((A, B))

'''
H = 10000
N = 1000
import random
AB = []
for i in range(N):
    A = random.randint(1, 10000)
    B = random.randint(1, 10000)
    AB.append((A, B))
'''




@lru_cache(maxsize=None)
def f(h):
    if h <= 0:
        return 0
    best = float('inf')
    for a, b in AB:
        val = b + f(h - a)
        if val < best:
            best = val
        else:
            break
    return best

AB.sort(key=lambda ab: (ab[0] / ab[1], -ab[0]), reverse=True)
bestA, bestB = AB[0]
threshold = sum(a for a, b in AB)

ans = None
times = (H - threshold) // bestA
if times > 0:
    ans = bestB * times + f(H - bestA * times)
else:
    ans = f(H)

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

N,M = map(int, input().split())
L = []
for i in range(M):
    p,S = map(str, input().split())
    L.append([p,S])
C = 0
P = 0

A = []
for k in range(M):
    if L[k][1] == 'AC' and L[k] not in A:
        A.append(L[k])
    elif L[k][1] == 'WA' and [L[k][0],'AC'] not in A:
        A.append(L[k])
for i in range(len(A)):
    if A[i][1] == 'AC':
        C += 1
    else:
        P += 1
print(C,P)

### FIXED CODE ###

N,M = map(int, input().split())
A = {}
C = 0
P = 0
for i in range(M):
    p,S = map(str, input().split())
    if S == 'AC' and A.get(p+S) is None:
        A[p+S] = 0
        C += 1
    elif S == 'WA' and A.get(p+'AC') is None and A.get(p+S) is None:
        A[p+S] = 1
    elif S == 'WA' and A.get(p+'AC') is None:
        A[p+S] += 1
for i in range(1,N+1):
    if A.get(str(i)+'AC') is not None and A.get(str(i)+'WA') is not None:
        P += A[str(i)+'WA']
print(C,P)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
count_dict = {i:{} for i in range(2)}
#print(count_dict[0])
for i in range(2):
  for j in A[i::2]:
    if j not in count_dict[i]:
      count_dict[i][j] = 1
    else:
      count_dict[i][j] += 1

candidates = []
for i in range(2):
  candidates.append(sorted(count_dict[i].items(), key=lambda kv: kv[1]))

candidates = [i[1]+j[1] for i in candidates[0] for j in candidates[1] if i[0] != j[0]]
no_move = max(candidates) if candidates != [] else len(A) // 2
print(N-no_move)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
count_dict = {i:{} for i in range(2)}
#print(count_dict[0])
for i in range(2):
  for j in A[i::2]:
    if j not in count_dict[i]:
      count_dict[i][j] = 1
    else:
      count_dict[i][j] += 1

candidates = [sorted(count_dict[i].items(), key=lambda kv: kv[1], reverse=True)[:2] for i in range(2)]
candidates = [i[1]+j[1] for i in candidates[0] for j in candidates[1] if i[0] != j[0]]
no_move = max(candidates) if candidates != [] else len(A) // 2
print(N-no_move)
### BUGGY CODE ###

N = int(input())
E = [[int(l) for l in input().split()] for _ in range(N-1)]
M = int(input())
L = [[int(l) for l in input().split()] for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
        
    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
                
    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)

C = [set([]) for _ in range(M)]
for i in range(N-1):
    uf = UnionFind(N)
    for e in E:
        if e == E[i]:
            continue
        uf.unite(e[0], e[1])
    for l in range(M):
        if uf.isSameGroup(L[l][0], L[l][1]):
            continue
        C[l].add(i)

ans = 0
for i in range(2**M):
    cnt = 0
    white = set([])
    for j in range(M):
        if i & 1 << j:
            cnt += 1
            white = white | C[j]
    if cnt%2:
        ans -= pow(2, N-1-len(white))
    else:
        ans += pow(2, N-1-len(white))
print(ans)

### FIXED CODE ###

N = int(input())
E = [[int(l) for l in input().split()] for _ in range(N-1)]
M = int(input())
L = [[int(l) for l in input().split()] for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
        
    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
                
    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)

C = [0]*M
for i in range(N-1):
    uf = UnionFind(N)
    for e in E:
        if e == E[i]:
            continue
        uf.unite(e[0], e[1])
    for l in range(M):
        if uf.isSameGroup(L[l][0], L[l][1]):
            continue
        C[l] |= 1 << i

import itertools

ans = 0
L = [int(i) for i in range(M)]
for m in range(M+1):
    for P in itertools.combinations(L, m):
        white = 0
        for j in P:
            white |= C[j]
        if m%2:
            ans -= 1 << N-1-bin(white).count("1")
        else:
            ans += 1 << N-1-bin(white).count("1")
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import fractions
from functools import reduce
n = int(input())

A = tuple(map(int, input().split()))
mod = 10**9 + 7
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
Z = lcm(*A)
ans = sum(Z//a%mod for a in A)%mod
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
import fractions
N=int(input())
A=list(map(int,input().split()))
c=1
a=0
w=10**9+7
for A_ in A:
    c=c*A_//fractions.gcd(c,A_)
for A_ in A:
    a+=c//A_
print(int(a%w))
### BUGGY CODE ###

from itertools import accumulate

N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(min(K, 100)):
    tmp = [0]*N
    for i, ai in enumerate(A):
        tmp[max(0, i-ai)] += 1
        if i+ai+1 < N:
            tmp[i+ai+1] -= 1
    A = accumulate(tmp)
print(*A)


### FIXED CODE ###

from itertools import accumulate

N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(min(K, 100)):
    tmp = [0]*N
    for i, ai in enumerate(A):
        tmp[max(0, i-ai)] += 1
        if i+ai+1 < N:
            tmp[i+ai+1] -= 1
    A = accumulate(tmp)
print(*A)
### BUGGY CODE ###

import numpy as np
h, w = map(int, input().split())
grid = np.zeros((h + 2, w + 2), dtype=int)

black = []
for i in range(h):
    for j, k in enumerate(input()):
        if k == "#":
            black.append((i + 1, j + 1))
            grid[i+1][j+1] = True

ans = 0
d = ((0, 1),
     (1, 0),
     (0, -1),
     (-1, 0),)
while not grid[1: h + 1, 1: w + 1].all():
    paint = []
    while black:
        x, y = black.pop()
        if x == 0 or x == h + 1 or y == 0 or y == w + 1:
            continue
        else:
            for nx, ny in d:
                if not grid[nx + x][ny + y]:
                    grid[nx + x][ny + y] = 1
                    paint.append((nx + x, ny + y))

    black = paint[:]
    ans += 1

print(ans)


### FIXED CODE ###

h, w = map(int, input().split())
grid = [[0]*(w+2) for _ in range(h+2)]

black = []
for i in range(h):
    for j, k in enumerate(input()):
        if k == "#":
            black.append((i + 1, j + 1))
            grid[i+1][j+1] = 1

ans = 0
d = ((0, 1),
     (1, 0),
     (0, -1),
     (-1, 0),)
while True:
    paint = []
    while black:
        x, y = black.pop()
        if x == 0 or x == h + 1 or y == 0 or y == w + 1:
            continue
        else:
            for nx, ny in d:
                if not grid[nx + x][ny + y]:
                    if x+nx == 0 or x+nx == h + 1 or y+ny == 0 or y+ny == w + 1:
                        continue
                    grid[nx + x][ny + y] = 1
                    paint.append((nx + x, ny + y))

    if len(paint) == 0:
        break
    black = paint[:]
    ans += 1

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

n = int(input())
l = [0]*n
for i in range(n):
  l[i] = int(input())

for i in range(n):
  l_b = l[:i]
  l_a = l[i+1:]
  if i == 0:
    print(max(l_a))
  elif i == n-1:
    print(max(l_b))
  else:
    print(max(max(l_b), max(l_a)))


### FIXED CODE ###

n = int(input())
#l = [0]*n
l = [int(input()) for i in range(n)]

m_l = [0]
m_r = [0]

for i in range(n):
  m_l.append(max(m_l[i], l[i]))
  m_r.append(max(m_r[i], l[-(i+1)]))
m_r = m_r[::-1]
#print(m_l) 
#print(m_r)

for i in range(n):
  print(max(m_l[i], m_r[i+1]))
### BUGGY CODE ###

import bisect

N=int(input())
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()
# print(A)
# print(B)
# print(C)

ans=0
for i in range(N):
    part1=A[i]
    part2_pos=bisect.bisect_right(B,part1)
    for j in range(part2_pos,N):
        part2=B[j]
        part3_pos=bisect.bisect_right(C,part2)
        # print(i,j,part3_spos,": ",A[i],B[j],C[part3_pos])
        ans+=(N-part3_pos)
print(ans)


### FIXED CODE ###

import bisect

N=int(input())
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()
# print(A)
# print(B)
# print(C)

ans=0
for j in range(N):
    a_num=bisect.bisect_left(A,B[j])
    c_num=bisect.bisect_right(C,B[j])
    # print(B[j],A[:a_num],C[c_num:])
    # print(a_num,c_num)
    ans+=a_num*(N-c_num)
print(ans)
### BUGGY CODE ###

import math

def search(A, S):

    for i, a in enumerate(A):
        if a < S:
            A[i] = S
            return A
    A.append(S)
    return A



def main():
    N = int(input())
    A = [int(input())]
    le = 1
    for _ in range(N-1):
        S = int(input())
        A = search(A, S)
    print(len(A))

    

if __name__ == "__main__":
    main()


### FIXED CODE ###

from bisect import bisect


def main():
    N = int(input())
    A = [-int(input()) for _ in range(N)]
    L = [A[0]]
    for a in A[1:]:
        if a >= L[-1]:
            L.append(a)
        else:
            L[bisect(L, a)] = a
    print(len(L))


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

N = int(input())
A = [int(input()) for i in range(N)]
for j in range(N):
    B = A[:j] + A[j+1:]
    print(max(B))

### FIXED CODE ###

N=int(input())
A=[int(input()) for _ in range(N)]
B=sorted(A)[:N-1]
m=max(A)
n=A.index(max(A))
for i in range(N):
    if  i!=n:
        print(m)
    else:
        print(max(B))
### BUGGY CODE ###

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 CODE ###

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