n=int(input())
A=[int(input()) for i in range(n)]
b=list(set(A))
if len(b)==1:
    for i in range(n):
        print(max(b))
    exit()
mi,maxi=b[-2:]
for a in A:
    if a==maxi:
        print(mi)
    else:
        print(maxi)