n = int(input())
a = [int(input()) for i in range(n)]
a_r = a[::-1]
max_list = [max(a[:i + 1]) for i in range(n)]
max_list_r = [max(a_r[:i + 1]) for i in range(n)]

for i in range(n):
    print(max(max_list[i - 1], max_list_r[i - 1]))
