import sys

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
M = sorted(A)
if M[-1] == M[-2]:
    for i in range(N):
        print(M[-1])
    sys.exit()
high_num = M[-1]
print(high_num)
print(A)
for i in range(N):
    if A[i] == high_num:
        print(M[-2])
    else:
        print(M[-1])
