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
dl = as.length - bs.length

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