N = int(input())
A = [int(input()) for i in range(N)]
first = sorted(A)[-1]
second = sorted(A)[-2]
if first == second:
    for i in range(N):
        print(first)
else:
    for i in range(N):
        if i == A.index(first):
            print(second)
        else:
            print(first)
