n = gets.to_i
a = []
n.times do |i|
  a[i] = gets.to_i
end
b = a.dup.sort
m = b.last
nm = 0
n.downto(1) do |i|
  if i == m
    nm = m
    break
  elsif i < m
    nm = i
    break
  end
end

a.each_with_index do |e, i|
  if a[i] == m
    puts nm
  else
    puts m
  end
end