n = gets.to_i

as = []
largest = second_largest = 0

n.times do
  a = gets.to_i

  if a > largest
    largest = a
  elsif a > second_largest
    second_largest = a
  end

  as.push(a)
end

as.each do |a|
  puts a < largest ? largest : second_largest
end
