N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
list = A
list = sorted(list)
max = list[-1]
second_max = list[-2]
for i in range(N):
    if A[i] == max and A.count(max) == 1:
        print(second_max)
    else:
        print(max)