n = io.read("*n")
t = {}
for i = 1, n do
  t[i] = io.read("*n")
end
local mma = math.max
left = {t[1]}
for i = 2, n do
  left[i] = mma(left[i - 1], t[i])
end
local right = {}
for i = 1, n do right[i] = 0 end
right[n] = t[n]
for i = n - 1, 1, -1 do
  right[i] = mma(right[i + 1], t[i])
end
print(right[2])
for i = 2, n - 1 do
  print(math.max(left[i - 1], right[i + 1]))
end
print(left[n - 1])
