n = gets.chomp.to_i
a = n.times.map{gets.to_i}
b = a.dup

max = a.max
b.delete(max)
max2 = -1
if b.length == 0
  max2 = max
else
  max2 = b.max
end

(0..(n-1)).each do |i|
	if a[i] == max
      puts max2
    else
      puts max
    end
end
