n = gets.to_i
nums = []
n.times { nums << gets.to_i }
copy = Marshal.load(Marshal.dump(nums))
nums.sort!.reverse!
biggest = nums[0]
second_biggest = nums[1]
copy.each do |n|
  if n == biggest
    puts second_biggest
  else
    puts biggest
  end
end
