Dimensional Debugging
InterviewTime limit2sMemory limit2048 MB
Count algorithms verifiable by BFS from those with all L_i equal to 0, where algorithm A verifies B when L_B is at most H_A in every parameter.
Problem
After struggling with this one problem for days, you have had enough! You are determined to find the bug in your algorithm once and for all! To do so, you will start all over. From scratch. At least you are sure you know the correct answer in the most trivial case: the answer in is .
You will re-solve the problem, which takes parameters, using simpler but slower algorithms. Each algorithm has two bounds for every parameter ( and ). An algorithm is only fast enough to run on inputs where for all parameters . You are confident the implementation of an algorithm is correct if you can verify its correctness at least once on an input where for all parameters . To do so, you will need another algorithm that you already proved to be correct and can handle such large inputs, or your knowledge of the answer for .
Given a list of algorithms and their bounds, find the number of algorithms you are sure are correctly implemented.
As an example, consider the first sample case shown in Figure D.1 on the left. The first algorithm (red, bottom left) can be used to verify the correctness of the second (yellow, top left) and third (blue, bottom right) algorithms. No algorithm can be used to verify the correctness of the fourth algorithm (grey, top right).

Figure D.1: The algorithms to be tested in samples 1 and 2, respectively. The boxes indicate the parameters where an algorithm must be tested, while the lighter background indicates the region where an algorithm can be used to verify other algorithms.
Input
The input consists of:
-
One line with two integers and (, ), the number of algorithms to test and the number of parameters.
-
Then follow pairs of lines:
- One line with integers ( for all ).
- One line with integers ( for all ).
-
It is guaranteed that for all .
Output
Output the number of algorithms of which you can verify the correctness.