n = gets.chomp.to_i
array = []
n.times do
  array << gets.chomp.to_i
end
array_sorted = array.sort
max = array_sorted[-1]
second = array_sorted[-2]

array.each do |num|
  if (num == max)
    puts second
  else
    puts max
  end
end