N = int(input())
A = []
for n in range(N):
    A.append(int(input()))

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]
max_list = [i for i, x in enumerate(A) if x == max(A)]

if len(max_list) >= 2:
    for n in range(N):
        print(max_A)

else:
    for n in range(N):
        if A[n] != max(A):
            print(max(A))
        else:
            print(second_A)