N = gets.chomp.to_i

numbers = N.times.map { gets.chomp.to_i }

max = numbers.max
max_index = numbers.index(max)

second = [ numbers[0...max_index], numbers[max_index+1..-1] ].flatten.max

0.upto(N-1) do |i|
    puts i == max_index ? second : max
end
