n = gets.to_i
as = []
n.times{ as << gets.to_i}

asl = []
as.each do |a|
  if asl.empty?
    asl << a
  else
    asl << [a, asl.last].max
  end
end

asr = []
as.reverse_each do |a|
  if asr.empty?
    asr << a
  else
    asr << [a, asr.last].max
  end
end
asr.reverse!

(0..n-1).each do |i|
  if i == 0
    p asr[i+1]
  elsif i == n-1
    p asl[i-1]
  else
    p [asl[i-1], asr[i+1]].max
  end
end
