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