N = int(input())
A = [int(input()) for _ in range(N)]

left_i = [0] * N
right_i = [0] * N

for i in range(1, N):
    left_i[i] = max(left_i[i-2], A[i-1])
    right_i[i] = max(right_i[i-1], A[N-i])

for i in range(N):
    print(max(left_i[i], right_i[N-1-i]))