n = gets.chomp!.to_i
as = Array.new
n.times do |e|
  e = gets.chomp!.to_i
  as.push(e)
end

am = as.max
bs = as.clone
bs.delete(am)
bm = bs.max
#bs.delete(m)
#p as
#p bs


as.each do |i|
  if i == am
    if bm == nil
      p am
    else
      p bm
    end
  else
    p am
  end
end