n = gets.to_i
array = []
n.times { array.push(gets.to_i) }

m = array.max
cpd = array.clone
cpd.delete(m)
second_m = cpd.max

array.each do |a|
  if a < m
    puts m
  else
    puts second_m
  end
end
