n = gets.to_i
array = []

(1..n).each do
  array.push(gets.to_i)
end

max = array.max

array.each_with_index do |number,idx|
  if number != max
    puts max
  else
    array[idx] = 0
    puts array.max
    array[idx] = number
  end
end
