n = gets.to_i
ary = []

n.times do
  ary << gets.to_i
end

maxaL = []
maxaR = []

maxL = 0
maxR = 0

n.times do |i|
  maxL = [maxL, ary[i]].max
  maxR = [maxR, ary[n - i - 1]].max
  maxaL << maxL
  maxaR << maxR
end
maxaR.reverse!
maxaL.unshift(0)
maxaL.push(0)

maxaR.unshift(0)
maxaR.push(0)

ans = 0
tmp = 0

for i in 1 .. n
  puts [maxaL[i - 1], maxaR[i + 1]].max
end
