N = gets.to_i AB = N.times.map{gets.split.map &:to_i} M = gets.to_i XY = M.times.map{gets.split.map &:to_i} a = XY.map{|x,y| AB.count{|a,b| x<=a&&y>=b } } max = a.max if max == 0 p 0 else p *a.map.with_index(1){|n, i|n==max ? i : p}-[p] end