N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [A[0]]
for n in range(N-1):
    B = B+[max(B[-1], A[n + 1])]
C = [A[-1]]
for n in range(N - 1):
    C = [max(C[0], A[-n - 2])] + C
D = [C[1]]+[max(B[n-1], C[n+1]) for n in range(1, N-2+1)]+[B[N-2]]
for d in D:
    print(d)
