N = gets.to_i
as = N.times.map{gets.to_i}
max, max_2, max_index = 0, 0, []
as.each_with_index do |a, i|
  if a > max
    max, max_2 = a, max
    max_index = [i]
  elsif a == max
    max_index.push(i)
  elsif a > max_2
    max_2 = a
  end
end
if max_index.length >= 2
  N.times{print "#{max}\n"}
else
  N.times{|i|
    if max_index.include?(i)
      puts max_2
    else
      puts max
    end
  }
end