def method_name(n, ai)
  max = ai.max
  cnt = ai.count(max)
  size = ai.size

  if cnt == 1
    max_index = ai.index(max)
    for i in 0..size-1
      if i == max_index
        bi = ai.clone
        bi[max_index] = 0
        puts bi.max
      else
        puts max
      end
    end
  else
    size.times{puts max}
  end
end

n = gets.chomp.to_i
ai = []
n.times{ai << gets.chomp.to_i}
method_name(n, ai)