CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
arr = [int(eval(input())) for _ in range(N)]

for i in range(N):
    a = arr[:i] + arr[i+1:]
    print((max(a)))

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

for i in range(N):
    a = arr[i]
    if a == sarr[0]:
        print((sarr[1]))
    else:
        print((sarr[0]))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i 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 i in range(N)]

# 入力された数列を降順でソート
sortA = sorted(A, reverse=True)

if sortA[0] == sortA[1]:
    # 最大値が2個発生するならば、そのときはすべての行で最大値が表示される
    for i in range(N):
        print((sortA[0]))
else:
    # 最大値が1個しかない場合、最大値の存在する位置では最大から2番めの値が表示されるが、それ以外では最大値が表示される
    maxP = A.index(sortA[0])
    for i in range(maxP):
        print((sortA[0]))
    print((sortA[1]))
    for i in range(maxP+1, N):
        print((sortA[0]))
# Original solution
#<134>
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = []
for n in range(N):
    A.append(int(eval(input())))
#print(A)
for n in range(N):
    x = A[n]
    A[n] = 0
    print((max(A)))
    A[n] = x
    #print(A)

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

B = sorted(A, reverse = True)
max1 = B[0]
max2 = B[1]
for a in A:
    print((max2 if a == max1 else max1))
# Original solution
n = int(eval(input()))
a = []
for i in range(n):
  a.append(int(eval(input())))
tmp = max(a)
for i in range(n):
  if tmp == a[i]:
    a[i] = -1
    print((max(a)))
    a[i] = tmp
  else:
    print(tmp)



"""
for i in range(n):
  if i == 0:
    print(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)
  """

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

for x in a:
  if x == tmpa[n-1]:
    print((tmpa[n-2]))
  else:
    print((tmpa[n-1]))
"""
if a[0] > a[1]:
  m,m2 = a[0],a[1]
else:
  m,m2 = a[1],a[0]

for x in a[2:]:
  if x > m2:
    if x>m:
      m2,m = 

"""
"""
for i in range(n):
  if i == 0:
    p
    rint(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)
  """
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

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

# Optimized solution

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

m = [0, 0]
for i in range(N):
  if A[i] > m[0]:
    m[0] = A[i]
    m[1] = i  

m2 = 0
for i in range(N):
  if i == m[1]:
    continue
  m2 = max(A[i], m2)

res = []
for i in range(N):
  if i != m[1]:
    print((m[0]))
  else:
    print(m2)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]

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


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

for A in a:
    if A == b[n - 1]:
        print((b[n - 2]))
    else:
        print((b[n - 1]))
# Original solution
count = int(eval(input()))
nlist = []
for i in range(count):
    a = int(eval(input()))
    nlist.append(a)
mlist = tuple(nlist)
biggest = max(mlist)
nlist.remove(biggest)

for i in range(count):
    if mlist[i] == biggest:
        print((max(nlist)))
    else:
        print(biggest)


# Optimized solution
count = int(eval(input()))
nlist = []
for i in range(count):
    a = int(eval(input()))
    nlist.append(a)
mlist = tuple(nlist)
biggest = max(mlist)
nlist.remove(biggest)
c = max(nlist)

for i in range(count):
    if mlist[i] == biggest:
        print(c)
    else:
        print(biggest)
# Original solution
def q3():
    N = int(eval(input()))
    A = []
    for n in range(N):
        A.append(int(eval(input())))

    for n in range(N):
        tmp = A.copy()
        tmp.pop(n)
        print((max(tmp)))

        
if __name__ == '__main__':
    q3()

# Optimized solution
def q3():
    """ C - Exception Handling """
    N = int(eval(input()))
    A = []
    for n in range(N):
        A.append(int(eval(input())))

    max_A = max(A)
    second_A = sorted(A, reverse=True)[1]
    for n in range(N):
        if A[n] == max_A:
            print(second_A)
        else:
            print(max_A)

            
if __name__ == '__main__':
    q3()
# 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):
    aa = max(a[0:i])
    ab = max(a[i+1:])
    print((max(aa,ab)))
print((max(a[:n])))

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
sortA=sorted(A)
for i in range(N):
    if A[i]!=sortA[-1]:
        print((sortA[-1]))
    else:
        print((sortA[-2]))
# Original solution
N = int(eval(input()))
a = []
for i 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 i in range(N):
    a.append(int(eval(input())))

sorted_list = sorted(a,reverse=True)
first = sorted_list[0]
secend = sorted_list[1]

for num in a:
    if num != first:
        print(first)
    else:
        print(secend)
# Original solution
n = int(eval(input()))
_list = []

for _ in range(n):
    _list.append(int(eval(input())))

for i in range(n):
    if i==0:
        tmp_list = _list[1:]
        tmp_max = max(tmp_list)
        print(tmp_max)
        
        if _list[0] < tmp_max:
            maxi = tmp_max
        else:
            maxi = _list[0]

    elif 0<i<n-1:
        if _list[i] < maxi:
            print(maxi)
        else:
            tmp_list = _list[:i] + _list[i+1:]
            print((max(tmp_list)))

    else:
        if _list[i] < maxi:
            print(maxi)
        else:
            tmp_list = _list[:n-1]
            print((max(tmp_list)))

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

for _ in range(n):
    a.append(int(eval(input())))

b = sorted(a, 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 = [0]*n
for i in range(n):
    a[i] = int(eval(input()))
amax = sorted(a)[-1]
amax2 = sorted(a)[-2]
for i in range(n):
    if a[i] == amax:
        print(amax2)
    else:
        print(amax)


# Optimized solution
n = int(eval(input()))
a = [0]*n
for i in range(n):
    a[i] = int(eval(input()))
amax = sorted(a)[-2:]
for i in range(n):
    if a[i] == amax[1]:
        print((amax[0]))
    else:
        print((amax[1]))
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
for i in range(n):
  x=a[i]
  a.pop(i)
  print((max(a)))
  a.insert(i,x)

# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
max1=1
m=0
for i in range(n):
  if max1<a[i]:
    max1=a[i]
    m=i
a.pop(m)
max2=max(a)
a.insert(m,max1)
for i in range(n):
  if i!=m:
    print(max1)
  else:
    print(max2)
# Original solution
N=int(eval(input()))
A=[]
for i in range(N):
    A.append(int(eval(input())))
R=[]
max_ = 0
for i in range(N):
    max_ = max(max_, A[i])
    R.append(max_)
L=[]
max_ = 0
for i in reversed(list(range(N))):
    max_ = max(max_, A[i])
    L.append(max_)
L = list(reversed(L))
print((L[1]))
for i in range(1, N-1):
    print((max(R[i-1], L[i+1])))
print((R[N-2]))

# Optimized solution
n=int(eval(input()))
max1 = 0
max2 = 0
A=[]
for _ in range(n):
    num = int(eval(input()))
    if num == max(num, max1):
        max2 = max1
        max1 = num
    elif num == max(num, max2):
        max2 = num
    A.append(num)
for a in A:
    if a == max1:
        print(max2)
    else:
        print(max1)
# Original solution
import heapq
N = int(eval(input()))
A = []

for _ in range(N):
    A.append((-1)*(int(eval(input()))))

B = A.copy()

heapq.heapify(B)
max_1 = 0 - heapq.heappop(B)
max_2 = 0 - heapq.heappop(B)

if max_1 == max_2:
    for _ in range(N):
        print(max_1)
        
else:
    for i in range(N):
        if i == A.index(-max_1):
            print(max_2)
        else:
            print(max_1)

    


# Optimized solution
import heapq
N = int(eval(input()))
A = []

for _ in range(N):
    A.append((-1)*(int(eval(input()))))

B = A.copy()

heapq.heapify(B)
max_1 = 0 - heapq.heappop(B)
max_2 = 0 - heapq.heappop(B)

if max_1 == max_2:
    for _ in range(N):
        print(max_1)
        
else:
    index = A.index(-max_1)
    
    for i in range(index):
        print(max_1)

    print(max_2)

    for i in range(N - index - 1):
        print(max_1)
# Original solution
n=int(eval(input()))
l=[int(eval(input())) for i in range(n)]
for j in range(n):
    kari=l[j]
    l[j]=0
    print((max(l)))
    l[j]=kari

# Optimized solution
n=int(eval(input()))
l=[int(eval(input())) for i in range(n)]
ma=sorted(l)[-2:]
for j in l:
    if j==ma[1]:
        print((ma[0]))
    else:
        print((ma[1]))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]

m = max(a)

for i in range(n):
    if m > a[i]:
        print(m)
    else:
        b = a[i]
        a.remove(b)
        print((max(a)))
        a.insert(i,b)


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

b = sorted(a)

for i in a:
    if i == b[-1]:
        print((b[-2]))
    else:
        print((b[-1]))
# 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
import sys
input = sys.stdin.buffer.readline
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
max_A = max(A)
sorted_A = sorted(A, reverse=True)
if sorted_A[1] == max_A:
    for _ in range(N):
        print(max_A)
    exit()

for a in A:
    if a == max_A:
        print((sorted_A[1]))
    else:
        print(max_A)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

maxleft = [0] * (N+2)
maxright = [0] * (N+2)

for i in range(N):
    maxleft[i+1] = max(A[0:i+1])
    maxright[i+1] = max(A[i:])

for i in range(N):
    print((max(maxleft[i], maxright[2+i])))


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

maxleft = [0] * (N+2)
maxright = [0] * (N+2)

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

for i in range(N):
    print((max(maxleft[i], maxright[2+i])))
# Original solution
n = int(eval(input()))
l = []
for i in range(n):
    l.append(int(eval(input())))
           
for j in range(n):
    print((max(l[:j]+l[j+1:])))  

# Optimized solution
n = int(eval(input()))
l = []
for i in range(n):
	l.append(int(eval(input())))
           
s = sorted(l, reverse=True)
      
for value in l:
    if value == s[0]:
        print((s[1]))
    else:
        print((s[0]))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

for i in range(N):
  a = A[i]
  del A[i]
  print((max(A)))
  A.insert(i, a)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
M = max(A)
c = A.count(M)
a = list(set(A))
a.sort(reverse=True)
 
for i in range(N):
  if A[i] != M:
    print(M)
  else:
    if c >= 2:
      print(M)
    else:
      print((a[1]))
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for  _ in range(n)]
for i in range(n):
    print((max(a[i+1:]+a[:i])))

# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for  _ in range(n)]
b=sorted(a,reverse=True)
max0=b[0]
max1=b[1]
for i in range(n):
    if a[i]!=max0:
        print(max0)
    else:
        print(max1)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
i=0
j=0
for i in range(n):
  b=-10000
  for j in range(n):
    if j==i:
      continue
    else:
      if b<=a[j]:
        b=a[j]
  print(b)

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
list=[]
i=0
j=0
l=0
m=0
o=0
c=max(a)
for i in range(n):
  if c!=a[i]:
    continue
  else:
    list.append(i)
if len(list)>1:
  for l in range(n):
    print(c)
else:
  del a[list[0]]
  d=max(a)
  for o in range(n):
    if o==list[0]:
      print(d)
    else:
      print(c)
# Original solution
N=int(eval(input()))
maxi=0
smaxi=0
flag=0
ls=[]
x=0
for i in range(N):
  x=int(eval(input()))
  ls.append(x)
  if (maxi<x):
    smaxi=maxi
    maxi=x
  elif (maxi==x):
    smaxi=maxi
  elif (smaxi<x):
    smaxi=x
for i in range(N):
  if (ls[i]==maxi):
    print(smaxi)
  else:
    print(maxi)


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

fromL=[0 for _ in range(N)]
for i in range(1,N):
  fromL[i]=max([fromL[i-1],ls[i-1]])

fromR=[0 for _ in range(N)]
for i in range(1,N):
  fromR[N-1-i]=max([fromR[N-i],ls[N-i]])

for i in range(N):
  print((max([fromL[i],fromR[i]])))
# Original solution

def s0():return eval(input())
def s1():return input().split()
def s2(n):return [eval(input()) for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(eval(input()))
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(eval(input())) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print((yes if b else no))
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
a=n2(n)
b=sorted(a)
m1=b[-1]
m2=b[-2]

for i in a:
    p0(i==m1,m2,m1)
    

# Optimized solution

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
a=n2(n)
b=sorted(a)
m1=b[-1]
m2=b[-2]
c=[]

for i in a:
    if i==m1:
        c.append(m2)
    else:
        c.append(m1)
print(*c,sep="\n")
# Original solution
N = int(eval(input()))
A = []
for i in range(N):
    A.append(int(eval(input())))
B = sorted(A, reverse = True)

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


# Optimized solution
import sys
input = sys.stdin.readline
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]))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
l = a
for i in range(n):
    m = a.pop(i)
    print((max(a)))
    a.insert(i, m)

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
MAX = max(a)
se = list(reversed(sorted(a)))[1]
for i in range(n):
    if a[i] == MAX:
        print(se)
    else:
        print(MAX)
# Original solution
import copy

n = int(eval(input()))

a = [0] * n

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

# a_s = set(a)

for i in range(n):
    tmp = copy.deepcopy(a)
    # tmp.discard(a[i])
    del tmp[i]
    print((max(tmp)))


# Optimized solution
import copy

n = int(eval(input()))

a = [0] * n

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

a_sort = sorted(a, reverse=True)

for i in range(n):
    if a[i] == a_sort[0]:
        print((a_sort[1]))
    else:
        print((a_sort[0]))
# Original solution
n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))

for i in range(n):
    memory = a[0]
    a.remove(a[0])
    print((max(a)))
    a.append(memory)

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

m = max(a)
count = a.count(m)

if count != 1:
    for i in range(n):
        print(m)

else:
    switch = 0
    for i in range(n-1):
        if a[i] == m:
            a.remove(m)
            m2max = max(a)
            print(m2max)
            a.append(m)
            switch = 1
        else:
            print(m)
    
    if switch == 1:
        print(m)
    else:
        a.remove(m)
        m2max = max(a)
        print(m2max)
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
for i in range(n):
    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)]
maxa=max(a)
if a.count(maxa)>=2:
    for i in range(n):
        print(maxa)
else:
    maxi=a.index(maxa)
    a.remove(maxa)
    maxa2=max(a)
    for i in range(n):
        if i==maxi:
            print(maxa2)
        else:
            print(maxa)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
maxa = max(a)
if a.count(maxa) > 1:
    for i in range(n):
        print((max(a)))
else:
    for j in range(n):
        if a[j] == maxa:
            sorta = sorted(a)
            print((sorta[-2]))
        else:
            print(maxa)

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
aa = sorted(a)[:n-1]
maxa = max(a)
b = a.index(maxa)
for i in range(n):
	if i == b:
		print((max(aa)))
	else:
		print(maxa)
# Original solution
N=int(eval(input()))
A=[int(eval(input())) for n in range(N)]
m=max(A)
n=sorted(A,reverse=True)[1]
for i in range(N):
    if A[i]<m:
        print(m)
    else:
        print(n)


# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for n in range(N)]
m=max(A)
n=sorted(A,reverse=True)[1]
print(("\n".join([str(m) if a<m else str(n) for a in A])))
# Original solution
N = int(eval(input()))
list_A = []
for _ in range(N):
    A = int(eval(input()))
    list_A.append(A)
    
A = max(list_A)
index_A = list_A.index(A)
for i in range(N):
    if list_A[i] == A:
      list_B = sorted(list_A, reverse=True)
      B = list_B[1]
      print(B)
    else:
      print(A)


# Optimized solution
N = int(eval(input()))
list_A = []
for _ in range(N):
    A = int(eval(input()))
    list_A.append(A)
    
sorted_list = sorted(list_A, reverse=True)
A = sorted_list[0]
B = sorted_list[1]

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

for n in range(N):
  tmp = A.copy()
  tmp.pop(n)
  print((max(tmp)))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for n in range(N)]
tmp = A.copy()
A.sort()
fir, sec = A[N-1], A[N-2]
for n in range(N):
  if tmp[n] == fir:
    print(sec)
  else:
    print(fir)
# Original solution
n=int(eval(input()))
a=[0]*n
for i in range(n):
    a[i]=int(eval(input()))
for i in range(n):
    a[i]*=-1
    print((max(a)))
    a[i]*=-1

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

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

max_a = max(a)
sec_max_a = sorted(a)[-2]
ans = [max_a]*N
max_index = []
for i in range(N):
  if a[i] == max_a:
    max_index.append(i)
#print(max_index)

for i in max_index:
  ans[i] = sec_max_a
for i in ans:
  print(i)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

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

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

first = A2[-1]
second = A2[-2]

for i in range(N):
    if A[i] == first:
        print(second)
    else:
        print(first)
# Original solution
N = int(eval(input()))
nums = []
for i in range(N):
    nums.append(int(eval(input())))

maxinum = max(nums)
for i in range(N):
    if nums[i] == maxinum:
        print((max(nums[0:i] + nums[i+1:])))
    else:
        print(maxinum)

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

maxinum = max(nums)
maxinum2 = -1
for i in range(N):
    if nums[i] == maxinum:
        if maxinum2 == -1:
            maxinum2 = max(nums[0:i] + nums[i+1:])
        print(maxinum2)
    else:
        print(maxinum)
# Original solution
#!/usr/bin/env python3
import sys
INF = float("inf")

import math


class SegmentTree(object):
    # セグメント木

    def __init__(self, N):
        """サイズNの配列を元にしたセグメント木
        """
        # 単位元
        self.idelem = -INF
        # 比較関数
        self.func = max

        self.N0 = 2**(math.ceil(math.log2(N)))
        self.tree = [self.idelem]*(2*self.N0)

    def update(self, k, x):
        """k番目の値をxに更新
        """
        k += self.N0-1
        self.tree[k] = x
        while k > 1:
            k = (k-1)//2
            self.tree[k] = self.func(self.tree[2*k+1], self.tree[2*k+2])

    def query(self, l, r):
        """区間[l, r)の最大
        """
        l += self.N0-1
        r += self.N0-1
        s = self.idelem
        while l < r:
            if r % 2 == 0:
                r -= 1
                s = self.func(s, self.tree[r])

            if l % 2 == 0:
                s = self.func(s, self.tree[l])
                l += 1
            l //= 2
            r //= 2
        return s

    def __str__(self):
        return str(self.tree[self.N0-1:-1])


def solve(N: int, A: "List[int]"):
    st = SegmentTree(N)
    for i, a in enumerate(A):
        st.update(i, a)
    print((st.query(1, N)))
    for i in range(1, N-1):
        print((max(st.query(0, i), st.query(i+1, N))))
    print((st.query(0, N-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()


# Optimized solution
#!/usr/bin/env python3
import sys
INF = float("inf")


def argmax(a):
    m, n = -(1 << 31), -1
    for i, v in enumerate(a):
        if m < v:
            m, n = v, i
    return m, n


def solve(N: int, A: "List[int]"):
    m, mi = argmax(A)
    m2, mi2 = argmax(A[:mi]+A[mi+1:])
    for i in range(N):
        if i == mi:
            print(m2)
        else:
            print(m)

    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

def solve():
  n = int(eval(input()))
  maxi = -10
  maxi2 = -10
  place = -1
  for i in range(n):
    a = int(eval(input()))
    if a>maxi:
      maxi2 = maxi
      maxi = a
      place = i
    else:
      maxi2 = max(maxi2,a)
  for j in range(n):
    if place == j:
      print(maxi2)
    else:
      print(maxi)
  
solve()

# Optimized solution
import sys
input = sys.stdin.readline
  
def solve():
  n = int(eval(input()))
  maxi = -10
  maxi2 = -10
  place = -1
  for i in range(n):
    a = int(eval(input()))
    if a>maxi:
      maxi2 = maxi
      maxi = a
      place = i
    else:
      maxi2 = max(maxi2,a)
  for j in range(n):
    if place == j:
      print(maxi2)
    else:
      print(maxi)
  
solve()