arr = []
gets.chomp.to_i.times do |i|
  arr << gets.chomp.to_i
end

sorted_arr = arr.sort
arr.length.times do |idx|
  _arr = sorted_arr.dup
  _arr.each_with_index do |i, _idx|
    if arr[idx] == i
      _arr.delete_at(_idx)
      break
    end
  end
  p _arr[-1]
end
