import numpy as np

N = int(input())
A_array = np.array([int(input()) for _ in range(N)])

sorted_A_array = sorted(A_array)
max_1st = sorted_A_array[-1]
max_2nd = sorted_A_array[-2]
max_count =sum(A_array == max_1st)

for i in range(N):
    if max_count == 1:
        if A_array[i] == max_1st:
            print(max_2nd)
        else:
            print(max_1st)
    else:
        print(max_1st)
