CodeEff/ECCO huggingface dataset:
# Original solution
import math

def main(): 

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

    for i in range(n):
        t = list(a)
        t.pop(i)

        print((max(t)))




if __name__ == "__main__":
    main() 

# Optimized solution

def main(): 

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

    max_v = 0
    max_sv = 0

    for i in range(n):
        if a[i] > max_v:
            max_sv = max_v
            max_v = a[i]
        elif a[i] > max_sv:
            max_sv = a[i]

    for i in range(n):
        if a[i] != max_v:
            print(max_v)
        else:
            print(max_sv)




if __name__ == "__main__":
    main()
# Original solution
n = int(eval(input()))
li = [0]*n
for i in range(n):
    li[i] = int(eval(input()))
a = 0
b = 0

for i in li:
    if i > a:
        b = a
        a = i
    elif i > b:
        b = i

for i in li:
    if i == a:
        print(b)
    else:
        print(a)


# Optimized solution
import sys
input = sys.stdin.readline

n = int(eval(input()))
li = [0]*n
for i in range(n):
    li[i] = int(eval(input()))
a = 0
b = 0

for i in li:
    if i > a:
        b = a
        a = i
    elif i > b:
        b = i

for i in li:
    if i == a:
        print(b)
    else:
        print(a)
# Original solution
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(eval(input()))
    A_ = [int(eval(input())) for _ in range(N)]

    max_A = max(A_)
    
    for i in range(N):
        if A_[i] == max_A:
            L = A_[0:i]
            L.extend(A_[i+1:])
            print((max(L)))
        else:
            print(max_A)
            
if __name__ == "__main__":
    main()


# Optimized solution
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(eval(input()))
    A_ = [int(eval(input())) for _ in range(N)]

    max_A = max(A_)
    if A_.count(max_A) > 1:
        for i in range(N):
            print(max_A)
            
    else:
        for i in range(N):
            if A_[i] == max_A:
                L = A_[0:i]
                L.extend(A_[i+1:])
                print((max(L)))
            else:
                print(max_A)

                
if __name__ == "__main__":
    main()
# Original solution
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

maxA = max(A)
lenA = len(A)

for i, a in enumerate(A):
    if a == maxA:
        if i == 0:
            print((max(A[1:])))
        elif i == lenA-1:
            print((max(A[:-1])))
        else:
            print((max(max(A[:i]), max(A[i+1:]))))
    else:
        print(maxA)

# Optimized solution
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

maxA = max(A)
lenA = len(A)
cnt_maxA = A.count(maxA)

if cnt_maxA > 1:
    for _ in range(lenA):
        print(maxA)
    exit()

for i, a in enumerate(A):
    if a == maxA:
        if i == 0:
            print((max(A[1:])))
        elif i == lenA-1:
            print((max(A[:-1])))
        else:
            print((max(max(A[:i]), max(A[i+1:]))))
    else:
        print(maxA)
# Original solution
n = int(eval(input('')))

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

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


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

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

n1 = max(xs)
n2 = sorted(xs)[-2]

for x in xs:
    if x == n1:
        print(n2)
    else:
        print(n1)
# Original solution
n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
#print(a)
lm = [0]
rm = [0]

for i in range(n-1):
    lm.append(max(a[i], lm[i]))

for i in range(n-1, 0, -1):
    rm.insert(0, (max(a[i], rm[n-i-1])))

#print(lm)
#print(rm)

for i in range(n):
    print((max(lm[i], rm[i])))

# Optimized solution
n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
#print(a)
lm = [0] * n
rm = [0] * n

for i in range(1, n):
    lm[i] = max(a[i-1], lm[i-1])

for i in range(n-2, -1, -1):
    rm[i] = max(a[i+1], rm[i+1])


for i in range(n):
    print((max(lm[i], rm[i])))
# Original solution
n=int(eval(input()))
alis=[int(eval(input())) for i in range(n)]
anslis=[0]*n
if alis.count(max(alis))>=2:
	for i in range(n):
		print((max(alis)))
else:
	for i in range(n):
		if i!=alis.index(max(alis)):
			print((max(alis)))
		else:
			print((sorted(alis)[-2]))

# Optimized solution
n=int(eval(input()))
alis=[int(eval(input())) for i in range(n)]
anslis=[max(alis)]*n
if alis.count(max(alis))==1:
	anslis[alis.index(max(alis))]=sorted(alis)[-2]
for i in range(n):
	print((anslis[i]))
# Original solution
n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
for j in range(n):
    excp = a.pop(j)
    print((max(a)))
    a.insert(j, excp)

# Optimized solution
n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
a_copy = a.copy()
biggest = max(a)
a_copy.remove(biggest)
second_biggest = max(a_copy)

for j in range(n):
    if a[j] == biggest:
        print(second_biggest)
    else:
        print(biggest)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

for i in range(N):
    A_ = [A[j] for j in range(0, N) if i != j]
    print((max(A_)))

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

FIRST = max(A)
if A.count(FIRST) > 1:
    for i in range(N):
        print(FIRST)
else:
    SECOND = max([a for a in A if a != FIRST])
    for a in A:
        if a == FIRST:
            print(SECOND)
        else:
            print(FIRST)
# Original solution
n = int(eval(input()))
a = []
for i in range(n):
  a.append(int(eval(input())))
maxi  = max(a)
for i in range(n):
  if a[i] != maxi:
    print(maxi)
  else:
    a[i] = 0
    print((max(a)))
    a[i] = maxi

# Optimized solution
n = int(eval(input()))
a = []
for i in range(n):
  a.append(int(eval(input())))
b = []
b += a
b.sort()
if b[-1] == b[-2]:
  maxi = max(a)
  for i in range(n):
    print(maxi)
else:
  maxi = max(a)
  for i in range(n):
    if a[i] != maxi:
      print(maxi)
    else:
      print((b[-2]))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
for i in range(N):
    print((max(A[:i]+A[i+1:])))


# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
m = max(A)
max_num = 0
for i in range(N):
    if A[i] == m:
        max_num += 1
        if max_num >1:
            print(m)
        else:
            print((max(A[:i]+A[i+1:])))
    else:
        print(m)
# Original solution
N = int(eval(input()))
a = [int(eval(input())) for i in range(N)]

lmax = [0]
rmax = [0]

for i in range(N-1):
    lmax.append(max(lmax[i], a[i]))
    rmax.append(max(rmax[i], a[-(i+1)]))

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

# Optimized solution
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,*A = list(map(int, read().split()))

    A_ = sorted(A)
    m = max(A)

    for a in A:
        if a == m:
            print((A_[-2]))
        else:
            print(m)


if __name__ == "__main__":
    main()
# Original solution
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]
print((max(A[1:])))
for i in range(1,N-1):
  a=A[:i]
  a.extend(A[i+1:])
  print((max(a)))
if N>1:
  print((max(A[:N-1])))

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]
c=0
m=0
for i in range(N):
  if m<A[i]:
    m=A[i]
    d=i
B=A
B[d]=0
for i in range(N):
  if i==d:
    print((max(B)))
  else:
    print(m)
# Original solution
my_max=0
my_sec=0
cnt=0
n=int(eval(input()))
a=[0]*n
r_n =list(range(n))
for i in r_n:
  a[i]=int(eval(input()))
  if my_max<a[i]:
    my_max=a[i]
  elif my_sec<a[i]:
    my_sec=a[i]
    
for i in r_n:
  if my_max==a[i]:
    cnt+=1
    
for i in r_n:
  if my_sec!=0:
    if my_max!=a[i]:
      print(my_max)
    elif cnt>1:
      print(my_max)
    else:
      print(my_sec)
  else:
    print(my_max)
  
  
 

# Optimized solution
import sys
input=sys.stdin.readline
n=int(eval(input()))
max1=0
max2=0
a=[int(eval(input())) for i in range(n)]
for i in a:
    if i>=max1:
        max2=max1
        max1=i
    elif i>=max2:
        max2=i
if max2==0:
    for i in range(n):
        print(max1)
    exit()
for i in a:
    if i==max1:
        print(max2)
    else:
        print(max1)
# Original solution
cnt = int(eval(input()))
lst = [int(eval(input())) for i in range(cnt)]

for i, j in enumerate(lst):
    lst[i] = 0
    print((max(lst)))
    lst[i] = j

# Optimized solution
cnt = int(eval(input()))
lst = [int(eval(input())) for i in range(cnt)]
lst2 = sorted(lst)
for i in lst:
  if i == lst2[-1]:
    print((lst2[-2]))
  else:
    print((lst2[-1]))
# Original solution
N = int(eval(input()))
A = [(i,int(eval(input()))) for i in range(N)]
B = sorted(A,key=lambda x:x[1],reverse=True)
cnt = 0
bmax = B[0][1]
for i in range(N):
    if B[i][1]==bmax:
        cnt += 1
    else:break
for i in range(N):
    if A[i][1] < bmax:
        print(bmax)
    elif A[i][1]==bmax and cnt==1:
        print((B[1][1]))
    elif A[i][1]==bmax and cnt>1:
        print(bmax)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A,reverse=True)
b0 = B[0]
b1 = B[1]
for i in range(N):
    a = A[i]
    if a!=b0:
        print(b0)
    else:
        print(b1)
# Original solution
N = int(eval(input()))

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

for i in range(N):
	ans = max(A[:i] + A[i+1:])
	print(ans)


# Optimized 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]))
# Original solution
import copy

N = int(eval(input()))

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


_max = max(A)

for i in range(N):
    if A[i] == _max:
        _A = copy.deepcopy(A)
        del _A[i]
        print((max(_A)))

    else:
        print(_max)
        

# Optimized solution
import copy

N = int(eval(input()))

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


max1 = max(A)

max_i = A.index(max1)
max2 = max(A[:max_i] + A[max_i+1:])


for i in range(N):
    if A[i] == max1:
        print(max2)

    else:
        print(max1)
# Original solution
# -*- coding: utf-8 -*-

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

for i in range(N):
  backup = array.pop(i)
  print((max(array)))
  array.insert(i, backup)


# Optimized solution
# -*- coding: utf-8 -*-

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

array_sorted = sorted(array, reverse=True)
max_index = array.index(array_sorted[0])
max_value = array_sorted[0]
second_value = array_sorted[1]

for i in range(N):
  if array[i] == max_value:
    print(second_value)
  else:
    print(max_value)
# Original solution
n = int(eval(input()))
L = []
for i in range(n):
  L.append(int(eval(input())))

R = []
for i in range(n):
  R.append(L[0:i]+L[i+1:])

  
for i in range(n):
  print((max(R[i])))


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

R = sorted(L)
a = R[-2]
b = R[-1]

for i in L:
  if i == b:
    print(a)
  else:
    print(b)
# Original solution
n = int(eval(input()))

a = [int(eval(input())) for i 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[:-1])))
  
  

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

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

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

if a_max_count > 1:
  for i in range(n):
    print(a_max)
    
else:
  print((max(a[1:])))
  
  for i in range(1, n-1):
    if a[i] == a_max:
      print((max(max(a[:i]), max(a[i+1:]))))
      
    else:
      print(a_max)

  print((max(a[:-1])))
# Original solution
N = int(eval(input()))
A = []
for i in range(N):
  A.append(int(eval(input())))

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

# Optimized solution
N = int(eval(input()))
A = []
for i in range(N):
  A.append(int(eval(input())))
B = sorted(A)

for i in range(N):
  if B[-1] != A[i]:
    print((B[-1]))
  else:
    print((B[-2]))
# Original solution
n = int(eval(input()))
a = [0] * n
for i in range(n):
    a[i] = int(eval(input()))
aa = [0,0]
for i in range(n):
    if a[i] > aa[-1]:
        aa[-1] = a[i]
    else:
        if a[i] >= aa[-2]:
            aa[-2] = a[i]

if aa[-1] == aa[-2]:
    for i in range(n):
        print((aa[-1]))
else:
    for i in range(n):
        if i == a.index(aa[-1]):
            print((aa[-2]))
        else:
            print((aa[-1]))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
maxi = max(a)
s = sorted(a,reverse=True)
 
for i in range(n):
    if a[i] != maxi:
        print(maxi)
    else:
        print((s[1]))
# Original solution
import copy
n=int(eval(input()))
a=[]
for i in range(n):
  a.append(int(eval(input())))
ma =max(a)
for i in range(n):
  if a[i]==ma:
    b=copy.deepcopy(a)
    del b[i]
    print((max(b)))
  else:
    print(ma)

# Optimized solution
import copy
n=int(eval(input()))
a=[]
for i in range(n):
  a.append(int(eval(input())))
ma =max(a)
cn =0
for i in range(n):
  if a[i]==ma and cn<2:
    b=copy.deepcopy(a)
    del b[i]
    print((max(b)))
    cn +=1
  else:
    print(ma)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]

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

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

reverse_A = sorted(A, reverse=True)
max1 = reverse_A[0]
max2 = reverse_A[1]

for a in A:
  if a == max1:
    print(max2)
  else:
    print(max1)
# Original solution
n=int(eval(input()))
an=[]
an=[int(eval(input())) for i in range(n)]
s_an=sorted(an,reverse=True)
for i in range(n):
    if max(an)==an[i]:
        print((s_an[1]))
    else:
        print((max(an)))

# Optimized solution
n=int(eval(input()))
an=[]
an=[int(eval(input())) for i in range(n)]
s_an=sorted(an,reverse=True)
m_an=max(an)
m_an2=s_an[1]
for i in an:
    if m_an==i:
        print(m_an2)
    else:
        print(m_an)
# Original solution
n = int(eval(input()))
A = []
for i in range(n):
    A.append(int(eval(input())))

A_max = max(A)
for i in range(n):
    if A[i] == A_max:
        print((max(A[0:i] + A[i+1:n])))
    else:
        print(A_max)


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

A_max = max(A)
A_max_2 = sorted(A)[-2]
for i in range(n):
    if A[i] == A_max:
        print(A_max_2)
    else:
        print(A_max)
# Original solution
N = int(eval(input()))
A = [0]*N
for i in range(N):
  A[i] = int(eval(input()))
#print(A)
M = max(A)
ind = A.index(M)
#print(ind)
A.pop(ind)
m = max(A)
for i in range(N):
  #print(i)
  if i != ind:
    print(M)
  else:
    print(m)
    

# Optimized solution
def solve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    B = sorted(A)
    m = B[-1]
    m2 = B[-2]
    ans = []
    for a in A:
        if a!=m:
            ans.append(m)
        else:
            ans.append(m2)
    return ans
print(*solve(),sep='\n')
# Original solution
#

n=int(eval(input()))
l = [int(eval(input())) for _ in [0] * n]
x = 0
for i in range(n):
    y = l[:]
    y.pop(i)
    print((max(y)))


# Optimized solution
n=int(eval(input()))
l = [int(eval(input())) for _ in [0] * n]
m = sorted(l)
a = m[-1]
b = m[-2]
#print(a,b)
for i in range(n):
    if l[i] == a:
        print(b)
    else:
        print(a)
# Original solution
N = int(eval(input()))
a=[]
for i in range(N):
  a.append(eval(input()))
  
for j in range(N):
  modori=a.pop(j)
  print((max(a)))
  a.insert(j,modori)
  


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

a1=max(a)
b=sorted(a)
a2=b[N-2]

for j in range(N):
  if a[j] != a1:
    print(a1)
  else:
    print(a2)
# Original solution
N = int(eval(input()))
a=[]
for i in range(N):
  a.append(int(eval(input())))

a1=max(a)
b=sorted(a)
a2=b[N-2]

for j in range(N):
  if a[j] != a1:
    print(a1)
  else:
    print(a2)

# Optimized solution
# coding: utf-8
# Your code here!
N=int(eval(input()))
A=[0]*N
for i in range(N):
    A[i]=int(eval(input()))
m=sorted(A)[N-1]
m_=A.index(m)
m2=sorted(A)[N-2]
m2_=A.index(m2)
for i in range(N):
    if i!=m_:
        print(m)
    else:
        print(m2)
# Original solution
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: list(map(int, sys.stdin.readline().split()))
readms = lambda: list(map(str, sys.stdin.readline().split()))

n = readi()
d = []
for i in range(n):
    k = readi()
    d.append(k)
p = []
g = -1
for i in range(n - 1):
    t = d[i]
    k = max(d[i+1:n])
    print((max(k, g)))
    g = max(t, g)
print((max(d[0],g)))

# Optimized solution
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: list(map(int, sys.stdin.readline().split()))
readms = lambda: list(map(str, sys.stdin.readline().split()))

n = readi()
d = []
h = []
for i in range(n):
    k = readi()
    d.append(k)
    heapq.heappush(h,-k)
t1 = -heapq.heappop(h)
t2 = -1
if h:
    t2 = -heapq.heappop(h)
if n == 1:
    print((d[0]))
else:
    for i in range(n):
        if d[i] == t1:
            print(t2)
        else:
            print(t1)
# Original solution
n=int(eval(input()))
alist=[int(eval(input())) for i in range(n)]
for i in range(n):
    if i == 0:
        max_a = 0
    else:
        max_a = max(alist[0:i])
    if i == n-1:
        max_b = alist[-1]
    else:
        max_b = max(alist[i+1:])
    print((max([max_a, max_b])))

# Optimized solution
n=int(eval(input()))
alist=[int(eval(input())) for i in range(n)]
b=sorted(alist, reverse=True)
for a in alist:
    if a < b[0]:
        print((b[0]))
    elif b[0] <= a:
        print((b[1]))
# Original solution
import copy
n = int(eval(input()))
a = list(int(eval(input())) for _ in range(n))

for i in range(n):
    # copy.copyを使用することで新しいオブジェクトを生成し、元のリストが影響を受けない
    b = copy.copy(a)
    b.pop(i)
    print((max(b)))


# Optimized solution
import copy
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
 
b = copy.deepcopy(a)
b.sort()
max1 = b[-1]
max2 = b[-2]
 
for i in a:
    if i == max1:
        print(max2)
    else:
        print(max1)
# Original solution
import sys
input=sys.stdin.buffer.readline
n=int(eval(input()))
L=list(int(eval(input())) for i in range(n))
for i in range(n):
    N=sorted(L)
    print((N[-1] if L[i]!=N[-1] else N[-2]))

# Optimized solution
import sys
input=sys.stdin.buffer.readline
n=int(eval(input()))
L=list(int(eval(input())) for i in range(n))
N=sorted(L)
for i in range(n):
    print((N[-1] if L[i]!=N[-1] else N[-2]))
# Original solution
N = int(eval(input()))
L = [int(eval(input())) for _ in range(N)]

for i in range(N):
    print((max(L[:i] + L[i + 1 :])))


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

Ls = sorted(L, reverse=True)
for i in range(N):
    if L[i] == Ls[0]:
        print((Ls[1]))
    else:
        print((Ls[0]))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = sorted(a)
m1 = b[-1]
m2 = b[-2]

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


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


def solve(N: int, A: "List[int]"):
    left = [A[0]] * N
    right = [A[-1]] * N

    for i in range(1,N):
        left[i] = max(A[i], left[i-1])
    for i in reversed(list(range(0,N-1))):
        right[i] = max(A[i], right[i+1])

    for i in range(N):
        if i == 0:
            print((right[1]))
        elif i == N-1:
            print((left[N-2]))
        else:
            print((max(left[i-1], right[i+1])))


    return



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
N = int(eval(input()))
A= [eval(input()) for i in range(N)]

normal = max(A)
maxindex = [i for i, x in enumerate(A) if x == max(A)]
A.remove(normal)
exception = max(A)

for i in range(N):
    if i in maxindex:
        print(exception)
    else:
        print(normal)

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

normal = max(A)
hoge=sorted(A)
exception = hoge[-2]

for i in range(N):
    if A[i] == normal:
        print(exception)
    else:
        print(normal)
# Original solution
n = int(eval(input()))

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

for i in range(n):
    if(i != 0):
        p1 = max(li[0:i])
    else:
        p1 = 0
    if(i != n-1):
        p2 = max(li[i+1:n])
    else:
        p2 = 0
    
    #print("{}, {}, {}".format(p1,p2,max(p1,p2)))
    print((max(p1,p2)))

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

li = [int(eval(input())) for i in range(n)]
ls = sorted(li, reverse = True)

m1 = ls[0]
m2 = ls[1]
"""
for i in range(0,n):
    if(ls[i] != m1):
        m2 = ls[i]
        break
"""

for i in li:
    print((m1 if(i != m1) else m2))
# Original solution
n = int(eval(input()))
#a = list(map(int, input().split()))
#b = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(int(eval(input())))

for i in range(n):
    if i==0:
        print((max(a[1:])))
    elif i==n-1:
        print((max(a[:-1])))
    else:
        b = max(a[:i])
        c = max(a[i+1:])
        print((max(b, c)))

# Optimized solution
n = int(eval(input()))
#a = list(map(int, input().split()))
#b = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(int(eval(input())))

b = sorted(a)
m = max(b)

for i in range(n):
    if a[i]==m:
        print((b[-2]))
    else:
        print(m)
# Original solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
LM=[0,A[0]]
a=A[::-1]
RM=[a[0]]
for i in range(1,N-1):
    LM.append(max(LM[-1],A[i]))
    RM.append(max(RM[-1],a[i]))
RM=RM[::-1]+[0]
for i in range(N):
    print((max(LM[i],RM[i])))

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
M=A[::-1]
M.sort()
for i in A:
    if i==M[-1]:print((M[-2]))
    else:print((M[-1]))
# Original solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
M=A[::-1]
M.sort()
for i in A:
    if i==M[-1]:print((M[-2]))
    else:print((M[-1]))

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
M=sorted(A)
for i in A:
    if i==M[-1]:print((M[-2]))
    else:print((M[-1]))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

for i in range(N):
  except_ls = A[:i] + A[i+1:]
  print((max(except_ls)))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A,reverse=True)

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