n = gets.to_i
a = []

n.times do |i|
  a[i] = gets.to_i
end

a_max = a.max

if(a.count(a_max) > 1)
  n.times do
    puts a_max
  end
else
  a_dup = a.dup
  a_dup.delete(a.max)
  a_max_sub = a_dup.max
  n.times do |i|
    if(a[i] == a_max)
      puts a_max_sub
    else
      puts a_max
    end
  end
end
