n = gets.to_i
a = Array.new(n,0)
n.times { |i| a[i] = gets.to_i }
tmp = a.sort
first = tmp[-1]
second = tmp[-2]
n.times do |i|
  if a[i] == first
    a[i] = second
  else
    a[i] = first
  end
end
puts a