N = gets.to_i
array = readlines.map{|n| n.chomp.to_i}

m_1 = array.max
m_1_count = array.count(m_1)
arr = array.dup
arr.delete(m_1)
m_2 = arr.max

p m_1,m_1_count,m_2

N.times do |i|
  if array[i] == m_1
    if m_1_count == 1
      puts m_2
    else
      puts m_1
    end
  else
    puts m_1
  end
end
