n = gets.to_i
arr = []
n.times do
  arr.push(gets.to_i)
end
if arr.count(arr.max) != 1
  n.times do
    puts arr.max
  end
else
  arr.freeze
  new_arr = arr.dup
  new_arr.delete(arr.max)
  second = new_arr.max
  arr.each do |num|
    if num == arr.max
      puts second
    else
      puts arr.max
    end
  end
end
