# coding: utf-8
# Your code here!
import sys
N=int(input())
a=[0]*(N)
maxim=[0]*(N)
for i in range(N):
    a[i]=int(input())
maxim=sorted(list(set(a)), reverse=True)
if len(maxim)==1:
    for j in range(N):
        print(maxim[0])
        sys.exit()

for k in range(N):
    if a[k]!=maxim[0]:
        print(maxim[0])
    else:
        print(maxim[1])