import copy
from sys import stdin
n=int(input())
A=[int(stdin.readline().rstrip()) for _ in range(n)]
z=max(A)
B=sorted(A)
o=B[1]
for j in range(0,n):
    if A[j]<z:
       print(z)
    else:
        if B[0]==B[1]:
           print(z)
        else:
           print(o)