from collections import deque
import numpy as np
N = int(input())
A = [int(input()) for _ in range(N)]

# d = deque()
R = deque(A)
R.append(0)
L = deque([0])

maxA = np.max(R)
for i in A:
  R.popleft()
  if i >= maxA: 
    maxA = max(np.max(L), np.max(R))
  print(maxA)
  L.append(i)
  