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

maxleft = [0] * (N+2)
maxright = [0] * (N+2)

for i in range(N):
    maxleft[i+1] = max(A[0:i+1])
    maxright[i+1] = max(A[i:])

for i in range(N):
    print(max(maxleft[i], maxright[2+i]))
