n = gets.to_i
a = []
max = [0]
n.times do
  a << gets.to_i
end
b = a.sort
if b[-1] == b[-2]
  n.times{p b[-1]}
else
  for i in 0...n
    if a[i] == b[-1]
      p b[-2]
    else
      p b[-1]
    end
  end
end