N = gets.to_i
a = []
N.times do
	a.push(gets.to_i)
end

maxval = a.max
if a.select{|n| n == maxval}.size >= 2
	N.times do
		puts maxval
	end
else
	N.times do |i|
		if a[i] < maxval
			puts maxval
		else
			puts a.select{|n| n < maxval}.max
		end
	end
end