n = gets.to_i
array = []
max = []

(1..n).each do
  array.push(gets.to_i)
end

array.each do |number|
  local_array = Array.new(array)
  local_array.each_with_index do |number_1, idx|
    if number == number_1
      local_array[idx] = nil
      local_array.compact
      break
    end
  end
  puts local_array.compact.max
end

