CodeEff/ECCO huggingface dataset:
# Original solution
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(eval(input()))

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = []
    n_best = 0
    best = 0
    best2 = 0
    for i in range(n):
        a = ri()
        la.append(a)
        if best < a:
            best2 = best
            best = a
            n_best = 1
        elif best == a:
            n_best += 1
        else:
            best2 = max(best2, a)
    for a in la:
        if a < best:
            print(best)
        else:
            if n_best > 1:
                print(best)
            else:
                print(best2)


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(eval(input()))

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    m1 = 0
    m2 = 0
    la = []
    for i in range(n):
        a = ri()
        if m1 <= a:
            m2 = m1
            m1 = a
        elif m2 < a:
            m2 = a
        la.append(a)
    for a in la:
        if a == m1:
            print(m2)
        else:
            print(m1)


if __name__ == '__main__':
    main()
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
for i in range(n):
  p=a[::]
  p.pop(i)
  print((max(p)))

# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
p=a[::]
m=max(a)
a.remove(m)
m2=max(a)
for i in p:
  if i==m:
    print(m2)
  else:
    print(m)
# Original solution
N, *d = list(map(int, open(0).read().split()))
allmax = 0
for i in range(N):
    if d[i] > allmax:
        allmax = d[i]
for i in range(N):
    max = 0
    for j in range(N):
        if(i == j):
            continue
        if d[j] > max:
            max = d[j]
            if max == allmax:
                break
    print(max)

# Optimized solution
N, *d = list(map(int, open(0).read().split()))
allmax = max(d)
allMaxCount = d.count(allmax)
for i in range(N):
    max = 0
    if(allMaxCount > 1 or d[i] != allmax):
        max = allmax
    else:
        for j in range(N):
            if(i == j):
                continue
            if d[j] > max:
                max = d[j]
                if max == allmax:
                    break
    print(max)
# Original solution
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(stdin.readline().rstrip()) for _ in range(n)]

for i in range(n):
    if i == n - 1:
        ai = a[:i]
    else:
        ai = a[:i] + a[i+1:]
    print((max(ai)))

# Optimized solution
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(stdin.readline().rstrip()) for _ in range(n)]

a_s = sorted(a)
m1 = a_s[-1]
m2 = a_s[-2]

for i in a:
    if i == m1:
        print(m2)
    else:
        print(m1)
# Original solution
# -*- coding: utf-8 -*-
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

for i in range(N):
  L = A[:]
  L.remove(A[i])
  print((max(L)))

# Optimized solution
# -*- coding: utf-8 -*-
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
if len(R) >= 2:
  max_v2 = R[1]
else:
  max_v2 = R[0]
R2 = sorted(A, reverse=True)
if R2[0] == R2[1]:
  signal = 1
else:
  signal = 0
  
for i in range(N):
  if A[i] == max_v and signal == 0:
    print(max_v2)
  else:
    print(max_v)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
c = sorted(a,reverse=True)
if a.count(max(a))>1:
    for i in range(n):
        print((max(a)))
else:
    for i in range(n):
        if i==a.index(max(a)):
            print((c[1]))
        else:
            print((max(a)))
    

    

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
c = sorted(a,reverse=True)
b = max(a)
if a.count(b)>1:
    for i in range(n):
        print(b)
    exit()
for i in a:
    if i==b:
        print((c[1]))
    else:
        print(b)
# Original solution
n = int(eval(input()))
ll = [[] for _ in range(n+1)]
for i in range(n):
    ll[0].append(int(eval(input())))

count = 1
for i in range(n):
    ll[count] = ll[0].copy()
    ll[count][count-1] = 0
    max = 0
    for j in ll[count]:
        if j>max:
            max = j
        else:
            pass
    print(max)
    count+=1


# Optimized solution
n = int(eval(input()))
ll = [int(eval(input())) for i in range(n)]
llc = ll.copy()
llc.sort()
m1 = llc[n-1]
m2 = llc[n-2]

for l in ll:
    if l == m1:
        print(m2)
    else:
        print(m1)
# Original solution
import copy

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

for i in range(N):
    tmp = copy.deepcopy(A)
    tmp[i] = 0
    print((max(tmp)))

# Optimized solution
import copy

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

A_original = copy.deepcopy(A)
A.sort()

for i in range(N):
    if A_original[i] == A[-1]:
        print((A[-2]))
    else:
        print((A[-1]))
# Original solution
N = int(eval(input()))
k = []
for i in range(N):
  k.append(int(eval(input())))
p = k
x = k.index(max(k))
for i in range(N):
  if i==x:
    p.sort()
    print((p[-2]))
  else:
    print((max(k)))

# Optimized solution
N = int(eval(input()))
k = []
for i in range(N):
    k.append(int(eval(input())))
B = k.copy()
B.sort()
B.reverse()
P = B[0]
Q = B[1]
for i in range(N):
    if k[i] == P:
        print(Q)
    else:
        print(P)
# Original solution
n=int(eval(input()))

a=[]
for i in range(n):
    a.append(int(eval(input())))

for i in range(n):
    print((max(a[:i]+a[i+1:])))

# Optimized solution
n=int(eval(input()))

a=[]
for i in range(n):
    a.append(int(eval(input())))

a_max=max(a)
a_max_cnt=a.count(a_max)

for i in range(n):
    if (a[i]!=a_max or a_max_cnt>1):
        print(a_max)
    else:
        print((max(a[:i]+a[i+1:])))
# Original solution
n = int(eval(input()))
a_list = [int(eval(input())) for _ in range(n)]

for i in range(n):
  print((max(a_list[:i]+a_list[i+1:]))) 

# Optimized solution
n = int(eval(input()))
a_list = [int(eval(input())) for _ in range(n)]
m1 = max(a_list)
k = a_list.index(m1)
m2 = max(a_list[:k]+a_list[k+1:])
for i in range(n):
  if i == k:
    print(m2)
  else:
    print(m1)
# Original solution
n = int(eval(input()))
l = []
for _ in range(n):
    a = int(eval(input()))
    l.append(a)

ans = []
tmp = 0
cnt = 0

for i in range(n):
    tmp = []
    for m in range(n):
        if i != m:
            tmp.append(l[m])
    ans.append(max(tmp))


for j in range(n):
    print((ans[j]))

# Optimized solution
n = int(eval(input()))
l = []
for _ in range(n):
    a = int(eval(input()))
    l.append(a)

l2 = l
l2 = sorted(l2)
l2.reverse()
max = max(l)


ans = []
if l2[1] == max:
    for i in range(n):
        print(max)
else:
    for j in l:
        if j != max:
            print(max)
        else:
            print((l2[1]))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

k = max(list(range(N)), key=lambda i: A[i])
for i in range(N):
    if i != k:
        print((A[k]))
    else:
        print((
            max(
                max(A[:k], default=0),
                max(A[(k + 1):], default=0)
            )
        ))


# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

# 最大値をとるインデックスを求めておく
k = max(list(range(N)), key=lambda i: A[i])
ans = '\n'.join(
    str(
        max(A[:k] + A[k + 1:]) if i == k else
        A[k]
    )
    for i in range(N)
)

print(ans)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]


for i in range(n):
  l = list(a)
  del l[i] 
  print((max(l)))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]

b = list(a)
a.sort()

for i in range(n):
  if b[i] == a[n - 1]:
    print((a[n - 2]))
  else:
    print((a[n - 1]))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]

for i in range(n):
      if max(a) == a[i]:
            print((sorted(a)[-2]))
      else:
            print((max(a)))


# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]

m1 = max(a)
m2 = sorted(a)[-2]
for i in range(n):
      if m1 == a[i]:
            print(m2)
      else:
            print(m1)
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
b=sorted(a)
m1=b[-1]
m2=b[-2]

for i in range(n):
    if a[i]==m1:
        print(m2)
    else:
        print(m1)


# Optimized solution
n=int(eval(input()))
   
A=[int(eval(input())) for i in range(n)]
B=sorted(A)

ma=B[-1]
ma2=B[-2]
for i in A:
    if i==ma:
        print(ma2)
    else:
        print(ma)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
for i in range(N):
    A[i] *= -1
    print((max(A)))
    A[i] *= -1

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
a, b = sorted(A, reverse = True)[0: 2]
for i in range(N):
    if A[i] == a:
        print(b)
    else:
        print(a)
# Original solution
def main():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]

    print((max(A[1:])))

    for i in range(1, N - 1):
        print((max(max(A[:i]), max(A[i + 1 :]))))

    print((max(A[:N])))

    return


if __name__ == "__main__":
    main()


# Optimized solution
def main():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]

    max_value = max(A)
    max_index = A.index(max_value)

    for i in range(N):
        if i != max_index:
            print(max_value)
        else:
            if i == 0:
                print((max(A[1:])))
            elif i == N - 1:
                print((max(A[: N - 1])))
            else:
                print((max(max(A[:i]), max(A[i + 1 :]))))

    return


if __name__ == "__main__":
    main()
# Original solution
import copy

N = int(eval(input()))
A = []
for n in range(N):
    A.append(int(eval(input())))
for i in range(N):
    Ai = copy.copy(A)
    Ai.remove(Ai[i])
    Ai.sort(reverse=True)
    print((Ai[0]))

# Optimized solution
import copy

N = int(eval(input()))
A = []
for n in range(N):
    A.append(int(eval(input())))

V = copy.copy(A)
V.sort(reverse=True)
for i in range(N):
    if V[0] == A[i]:
        print((V[1]))
    else:
        print((V[0]))
# Original solution
# coding: utf-8
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
for i in range(N):
    B = A[:]
    B.pop(i)
    print((max(B)))


# Optimized solution
# coding: utf-8
N = int(eval(input()))
A = []#value
for i in range(N):
    A.append(int(eval(input())))
B = A[:]
B.sort()
one = B[-1]
two = B[-2]
for i in range(N):
    if A[i] == one:
        print(two)
    else:
        print(one)
# Original solution
n=int(eval(input()))
A=[]
for i in range(n):
    a=int(eval(input()))
    A.append(a)
M=max(A)
for i in range(n):
    if A[i]!=M:
        print(M)
    else:
        b=A.pop(i)
        print((max(A)))
        A.insert(i,b)

# Optimized solution
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]

M = max(A)
ind = A.index(M)
A[ind] = 0
M2 = max(A)


if M in A:
    for i in range(n):
        print(M)
else:
    for i in range(n):
        if A[i] == 0:
            print(M2)
        else:
            print(M)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A)

for i in range(N):
  if A[i] == B[-1]:
    print((B[-2]))
  else:
    print((B[-1]))

# Optimized solution
N = int(input())
A = [int(input()) for _ in range(N)]
second, first = sorted(A)[-2:]

ans = [second if a==first else first for a in A]
[print(a) for a in ans]
# Original solution
n=int(eval(input()))
l=[int(eval(input())) for i in range(n)]
s=sorted(l)
m=max(l)
nums=[i for i in range(n)]
for num in nums:
  if(l[num]!=m or l.count(m)!=1):
    print(m)
  else:
    print((s[-2]))

# Optimized solution
n=int(eval(input()))
l=[int(eval(input())) for i in range(n)]
s=sorted(l)
p=s[-1]
q=s[-2]
for i in range(n):
  if l[i]==p:
    print(q)
  else:
    print(p)
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
c=sorted(a)
b=max(a)
for i in range(n):
  if a[i]==b:
    print((c[n-2]))
  else:
    print(b)

# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
b=sorted(a)
if b[n-1]==b[n-2]:
  for i in a:
    print((b[n-1]))
else:
  for i in a:
    if i==b[n-1]:
      print((b[n-2]))
    else:
      print((b[n-1]))
# Original solution
def maximum(l,ind):
	max=-90000000
	for i in range(0,len(l)):
		if(i!=ind):
			if(l[i]>max):
				max=l[i]
	return max
n=int(eval(input()))
l=[]
for i in range(0,n):
	l.append(int(eval(input())))
for i in range(0,n):
	print((maximum(l,i)))

# Optimized solution
n=int(eval(input()))
l=[]
for i in range(n):
	l.append(int(eval(input())))
copy=sorted(l,reverse=True)
for i in range(n):
	if(copy[0]==l[i]):
		print((copy[1]))
	else:
		print((copy[0]))
# Original solution
from sys import stdin
N = int(stdin.readline().rstrip())
num_line = [stdin.readline().rstrip() for _ in range(N)]
for i in range(N):
    save_num = num_line[i]
    num_line.pop(i)
    print((max(num_line)))
    num_line.insert(i, save_num)

# Optimized solution
N = int(eval(input()))
num_line = [int(eval(input())) for _ in range(N)]
sort_line = sorted(num_line)
for i in num_line:
    if i == sort_line[N-1]:
        print((sort_line[N-2]))
    else:
        print((sort_line[N-1]))
# Original solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
sort=sorted(A)
x,y=sort[-1],sort[-2]
for a in A:
    print((x if a!=x else y))

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
y,x=sorted(A)[-2:]
for a in A:
    print((x if a!=x else y))
# Original solution
n = int(eval(input()))
a = [0]*n
for i in range(n):
  a[i] = int(eval(input()))
for i in range(n):
  b = a[:]
  b[i] = 0
  print((max(set(b))))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = a[:]
b.sort(reverse=True)
for i in range(n):
  if a[i] == b[0]:
    print((b[1]))
  else:
    print((b[0]))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = a[:]
b.sort(reverse=True)
for i in range(n):
  if a[i] == b[0]:
    print((b[1]))
  else:
    print((b[0]))

# Optimized solution
def main():
    n = int(eval(input()))
    a = [int(eval(input())) for _ in range(n)]
    b = sorted(a)
    for i in range(n):
      if a[i] == b[-1]:
        print((b[-2]))
      else:
        print((b[-1]))
 
main()
# Original solution
n = int(eval(input()))
a = []
for _ in range(n):a.append(int(eval(input())))

for i in range(n):
    tmp = a[i]
    a[i] = 0
    print((max(a)))
    a[i] = tmp

# Optimized solution
n = int(eval(input()))
a = []
for _ in range(n):a.append(int(eval(input())))

max_ = max(a)
max2 = sorted(a)[-2]
for i in range(n):
    if a[i] != max_:
        print(max_)
    else:
        print(max2)
# Original solution
N = int(eval(input()))
As = [int(eval(input())) for _ in range(N)]
result = []
for x in range(N):
  as_tmp = list(As)
  del as_tmp[x]
  result.append(max(as_tmp))
print(('\n'.join(map(str, result))))

# Optimized solution
N = int(eval(input()))
As = [int(eval(input())) for _ in range(N)]
Bs = sorted(As,reverse=True)
for x in As:
  if x == Bs[0] and x != Bs[1]:
    print((Bs[1]))
  else:
    print((Bs[0]))
# Original solution
n = int(eval(input()))
a = [0] * n
#dp = []

for i in range(n):
    a[i] = int(eval(input()))

maxV = max(a)

for i in range(n):
    if a[i] == maxV:
        new = list(a)
        del new[i]
        print((max(new)))
    else:
        print(maxV)


# Optimized solution
n = int(eval(input()))
a = [0] * n

for i in range(n):
    a[i] = int(eval(input()))

#maxV = max(a)
sortedA = sorted(a)
maxV = sortedA[n-1]
maxV2 = sortedA[n-2]

for i in range(n):
    if a[i] == maxV:
        # new = list(a)
        # del new[i]
        # print(max(new))
        print(maxV2)
    else:
        print(maxV)
# Original solution
n = int(input())
a = [int(input()) for i in range(n)]
max_a = max(a)
second_a = sorted(a)[-2]
[print(max_a) if a[i] != max_a or a.count(a[i]) > 1 else print(second_a) for i in range(len(a))]


# Optimized solution
n = int(input())
a = [int(input()) for i in range(n)]
max_a = max(a)
second_a = sorted(a)[-2]
max_count = a.count(max_a) - 1
if max_count:
    [print(max_a) for _ in range(len(a))]
else:
    [print(max_a) if a[i] != max_a else print(second_a) for i in range(len(a))]
# Original solution
import copy
n = int(eval(input()))
ls = []
for i in range(n):
    a = int(eval(input()))
    ls.append(a) 

ans = max(ls)
for i in range(len(ls)):
    ls2 = copy.copy(ls)
    del ls2[i]
    if ans in ls2:
        print(ans)
    else:
        ls2.sort()
        print((ls2[-1]))
    

# Optimized solution
import copy
n = int(eval(input()))
ls = []
for i in range(n):
    a = int(eval(input()))
    ls.append(a) 
ls2 = copy.copy(ls)
ls.sort()
max1 = ls[-1]
max2 = ls[-2]


for i in ls2:
    if i != max1:
        print(max1)
    else:
        print(max2)
# Original solution
n = int(eval(input()))

a = [int(eval(input())) for i in range(n)]

for i in range(n):
    print((max(max(a[:i],a[i+1:]))))

# Optimized solution

n = int(eval(input()))
a = []
y = 0
for i in range(n):
    x = int(eval(input()))
    a.append(x)
    if y <= x:
        y = x
        m = i

a.sort(reverse = True)
a_1 = a[0]
a_2 = a[1]

if a_1 == a_2:
    for i in range(n):
        print(a_1)

else:
    for i in range(m):
        print(a_1)

    print(a_2)

    for j in range(m+1,n):
        print(a_1)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

# http://tjkendev.github.io/procon-library/python/range_query/rmq_segment_tree.html
# N: 処理する区間の長さ
N0 = 2**(N-1).bit_length()
INF = 2**31-1
data = [0]*(2*N0)

# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = max(data[2*k+1], data[2*k+2])

# 区間[l, r)の最小値
def query(l, r):
    L = l + N0
    R = r + N0
    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])

        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1
        R >>= 1
    return s


for i, a in enumerate(A):
    update(i, a)

l, r = 0, 1
for _ in range(N):
    a, b = query(0, l), query(r, N)
    print((max(a, b)))
    l += 1
    r += 1


# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

B = sorted(A)
f, s = B[-1], B[-2]

for a in A:
    if a == f:
        print(s)
    else:
        print(f)
# Original solution
n = int(eval(input()))
a = []
num = []
prem = 0
m = 0
j = 0
for i in range(n):
    a.append(int(eval(input())))
for i in range(n):
    if a[i] > m:
        prem = m
        m = a[i]
        num = []
        num.append(i)
    elif a[i] == m:
        num.append(i)
    elif a[i] > prem:
        prem = a[i]
for i in range(n):
    if len(num) > 1:
        print(m)
    elif j < len(num) and i == num[j]:
        print(prem)
        j += 1
    else:
        print(m)


# Optimized solution
n = int(eval(input()))
a = []
prem = 0
m = 0
j = 0
for i in range(n):
    a.append(int(eval(input())))
for i in range(n):
    if a[i] > m:
        prem = m
        m = a[i]
    elif a[i] > prem:
        prem = a[i]
for i in range(n):
    if a[i] == m:
        print(prem)
    else:
        print(m)
# Original solution
N = int(eval(input()))

A = []

for i in range(0, N):
    A.append(int(eval(input())))

for i in range(0, N):
    print((max(A[0:i] + A[i+1:N])))

# Optimized solution
N = int(eval(input()))

A = []

for i in range(0, N):
    A.append(int(eval(input())))

max1 = sorted(A)[-1]
max2 = sorted(A)[-2]


for i in A:
    if i == max1:
        print(max2)
    else:
        print(max1)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

for i in range(N):
    A_num = A.pop(i)
    print((max(A)))
    A.insert(i, A_num)


# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = sorted(a)[::-1]
mx = b[0]
mx2 = b[1]

for i in a:
    if i == mx:
        print(mx2)
    else:
        print(mx)
# Original solution
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    s = sorted(list(set(A)))

    for a in A:
        if len(s) == 1:
            print((s[-1]))
        elif a == s[-1] and A.count(a) == 1:
            print((s[-2]))
        else:
            print((s[-1]))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    s = sorted(list(set(A)))
    mc = A.count(s[-1])

    for a in A:
        if len(s) == 1:
            print((s[-1]))
        elif a == s[-1] and mc == 1:
            print((s[-2]))
        else:
            print((s[-1]))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()
# Original solution
import heapq
import copy
N = eval(input())
A = [-int(eval(input())) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
for idx, a in enumerate(A):
    heapq.heapify(A_heap)
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A2 = heapq.heappop(A_heap)
        print((-(pop_A2)))
        heapq.heappush(A_heap, pop_A)
        heapq.heappush(A_heap, pop_A2)
        continue

    print((-(pop_A)))
    heapq.heappush(A_heap, pop_A)

# Optimized solution
import heapq
import copy
N = eval(input())
A = [-int(eval(input())) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
heapq.heapify(A_heap)
for idx, a in enumerate(A):
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A2 = heapq.heappop(A_heap)
        print((-(pop_A2)))
        heapq.heappush(A_heap, pop_A)
        heapq.heappush(A_heap, pop_A2)
        continue

    print((-(pop_A)))
    heapq.heappush(A_heap, pop_A)
# Original solution
n = int(eval(input()))
a = []
for _ in range(n):
  a.append(int(eval(input())))
  
for i in range(n):
  b = a.copy()
  b.remove(b[i])
  print((max(b)))
  
  
  
  
  

# Optimized solution
n = int(eval(input()))
a = []
x = 0
x_max = 0
for _ in range(n):
  x = int(eval(input()))
#  if x_max 
  a.append(x)

b = a.copy()  
b.sort(reverse=True)
a_max1 = b[0]
a_max2 = b[1] 

for i in a:
  if i == a_max1:
    print(a_max2)
  else:
    print(a_max1)
# Original solution
n = int(eval(input()))
a = []
for i in range(n):
  a.append(int(eval(input())))
for i in range(n):
  x = a[:i] + a[i+1:]
  print((max(x)))

# Optimized solution
n = int(eval(input()))
a = []
for i in range(n):
  a.append(int(eval(input())))
x = a.index(max(a))
a0 = sorted(a)
for i in range(n):
  if i != x:
    print((a0[n-1]))
  else:
    y = a[:x] + a[x+1:]
    print((max(y)))
# Original solution
n = int(eval(input()))
a = []
for _ in range(n):
    a.append(int(eval(input())))
escape = min(a) - 1
for i in range(len(a)):
    compare = list(a)
    compare[i] = escape
    print((max(compare)))

# Optimized solution
n = int(eval(input()))
a = []
for _ in range(n):
    a.append(int(eval(input())))
firstMax = max(a)
minVal = min(a)
secondMax = max([x if x != firstMax else minVal for x in a]) if len(str(a).split(str(firstMax))) == 2 else firstMax
for i in range(len(a)):
    if a[i] < firstMax:
        print(firstMax)
    else:
        print(secondMax)