N = gets.to_i
A = N.times.map{gets.to_i}

max = A.max
b = A.dup.delete(max)
next_max = b.max

only_one = A.one? {|a| a == max}

N.times do |i|
  if max > A[i]
    puts max
  else
    puts only_one ? next_max : max
  end
end