N = gets.to_i
a = []

max = 0

multi = false
N.times do
  n = gets.to_i

  if max == n
    multi = true
  elsif max < n
    max = n
  end
  a << n
end

a.each_with_index do |d, i|
  if multi
    p max
    next
  end

  if d != max
    p max
  else
    at = a.dup
    at.delete_at(i)
    p at.max
  end
end
