import sys
input=sys.stdin.readline
n=int(input())
max1=0
max2=0
a=[int(input()) for i in range(n)]
for i in a:
    if i>=max1:
        max1=i
    elif i>=max2:
        max2=i
if max2==0:
    for i in range(n):
        print(max1)
    exit()
for i in a:
    if i==max1:
        print(max2)
    else:
        print(max1)
    