Problem C
Checking Break
As you already know from the previous problem, ‘Breaking Cake’, the first round of the Hunter Exam has begun.
The following paragraphs are copied from the problem statement of ‘Breaking Cake’:
The first round of the Hunter Exam is a real-life problem solving test: Each candidate is given a rectangular parallelepiped cake of size
, which can be divided into unit cubes of size . Inside the cake, there are
unit cubes containing chocolate chips. The -th cube is located at position . The candidates must divide their given cake into exactly
rectangular parallelepiped parts, satisfying all the following conditions:
For every two parts, their common space’s volume must be zero.
Each part must contain exactly one chocolate chip.
The coordinates of the corners of all
parts must be integers. To prevent wasted food, candidates cannot throw away any part of the cake.
Can you divide the cake satisfying all the constraints and pass the first round of the Hunter Exam?
This year,
Input
The input contains multiple test cases. Each test case is described as below:
-
The first line contains exactly
positive integers , , and . . -
In the next
lines, the -th line contains exactly positive integers , and — the coordinates of the -th chocolate chip . No two chips are in the same position. -
The next
lines describe a solution given by a candidate:-
The
-th line contains exactly integers, , , , , and representing the -th part . and are the coordinates of two opposite unit cubes of the -th part.
-
Sum of
The last line of the input contains a single number
Output
For each test case, print exactly one line, containing ‘YES’ if the candidate’s solution satisfies all the given constraints:
-
The
-th part must contains the -th chocolate chip. -
Candidate did not throw away any part of the cake.
-
The volume of the intersection of any two parts must be equal to zero.
-
.
Otherwise, print ‘NO’.
Note that it is not guaranteed that
the cake can be divided into
Sample Input 1 | Sample Output 1 |
---|---|
5 5 5 2 1 1 1 5 5 5 1 1 1 5 5 1 1 1 2 5 5 5 5 5 5 1 3 3 3 1 1 1 5 5 6 -1 |
YES NO |