n = gets.to_i
as = []

n.times do
  as.push gets.to_i
end
max = as.max
flg = true
flg = !flg if as.select{|i| max == i}.count >= 2
as.each_with_index do |v, i|
  if max == v && flg
    as_as = as.dup
    as_as.delete_at(i)
    puts as_as.max
  else
  	puts max
  end
end