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-2).downto(1) do |i|
  if b[i] == m
    nm = m
    break
  elsif b[i] < m
    nm = b[i]
    break
  end
end

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