n = gets.to_i
arr = []
n.times do |i|
  arr.push(gets.to_i)
end

sorted_arr = arr.sort
max_value = sorted_arr[n-1]
second_value = sorted_arr[n-2]
max_i = arr.index(max_value)

n.times do |i|
  if max_i != i
    puts(max_value)
  else
    puts(second_value)
  end
end