import copy

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

A_max=max(A)
M=[i for i,x in enumerate(A) if x==A_max]

if len(M)>=2:
    for i in range(N):
        print(A_max)
else:
    for i in range(N):
        if i!=M[0]:
            print(A_max)
        else:
            B=copy.copy(A)
            B.remove(A_max)
            print(max(B))
