from collections import deque

n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))

leftA = [0]
tmp = A[0]
for a in A:
    tmp = max(tmp, a)
    leftA.append(tmp)
print(leftA)

rightA = deque([0])
tmp = A[-1]
for a in reversed(A):
    tmp = max(tmp, a)
    rightA.appendleft(tmp)
rightA.appendleft(0)
print(rightA)

for i in range(1, n+1):
    print(max(leftA[i-1], rightA[i+1]))
