N = int(input())
A = [int(input()) for i in range(N)]
Max_f = []
Max_r = []
tmp_f = 0
tmp_r = 0

for i in range(N-1):
    Max_f.append(max(tmp_f, A[i]))
    Max_r.append(max(tmp_r, A[-i-1]))
    tmp_f = A[i]
    tmp_r = A[-i-1]

for i in range(N):
    if i == 0:
        print(Max_r[-1])
    elif i == N-1:
        print(Max_f[-1])
    else:
        print(max(Max_f[i-1], Max_r[N-i-2]))