# frozen_string_literal: true # # Array extension # class Array def accepts FOODS.map.with_index do |food, index| index if food[0] <= self[0] && food[1] >= self[1] end end end # ----------------------------------------------------------------- input MEMBERS = gets.to_i.times.map { gets.chomp.split.map(&:to_i) } FOODS = gets.to_i.times.map { gets.chomp.split.map(&:to_i) } # ----------------------------------------------------------------- calc FOODS_WITH_NUM = MEMBERS.map(&:accepts) .flatten .compact .group_by(&:itself) .map { |i, j| [i, j.size] } MAXS = FOODS_WITH_NUM.filter do |_, j| j == ((FOODS_WITH_NUM.max_by { |_, k| k } || [nil, 0])[1]) end RESULT = MAXS.empty? ? 0 : MAXS.map { |k, _v| k + 1 }.uniq # ----------------------------------------------------------------- output puts RESULT