require 'set'

n = gets.chomp.to_i

arr = []
n.times do
  arr.push(gets.chomp.to_i)
end

s = Set.new(arr)
m = s.max
sm = if arr.select { |i| i == arr.max }.count == 1
       (s - Set.new([s.max])).max
     else
       m
     end

n.times do |i|
  if arr[i] == m
    puts sm
  else
    puts m
  end
end
