N = int(input())
a = [int(input()) for i in range(N)]
A = max(a)
if a.count(A) > 1:
    for i in range(len(a)):
        print(A)
else:
    for i in range(len(a)):
        if i == a.index(A):
            print(sorted(a)[-2])
        else:
            print(A)