N = gets.to_i
A = []
N.times { A << gets.to_i }

max = A.max
max_index = A.find_index(max)
A.delete_at(max_index)
max2 = A.max

N.times do |i|
  if i == max_index
    puts max2
  else
    puts max
  end
end