N = int(input())
A = [int(input()) for i in range(N)]
 
 
left_max = [-1] * N
right_max = [0]
all = sum(A)
left_max[0] = A[0]
right_max[0] = A[-1]
for i in range(1, N):
        left_max[i] = max(left_max[i-1], A[i])
for i in reversed(range(0, N-1)):
        right_max.insert(0, max(right_max[0], A[i]))
 
 
print(right_max[1])
for i in range(1,N-1):
        print(max(left_max[i-1], right_max[i+1]))
print(left_max[-2])