N = int(input())
A = [int(input()) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
Max = max(A)
if len(set_A) == 1:
    for i in range(len(set_A)):
        print(Max)
    exit()
for i in range(N):
    if A[i] == Max:
        print(set_A[1])
    else:
        print(Max)
