There is an by chessboard with squares in total. Rows and columns are numbered starting from , and the coordinates of the square in the -th column and -th row are denoted as . Initially, all squares are white. Now, you need to perform coloring operations on this chessboard.
There are three types of coloring operations:
- Color a horizontal line black. Specifically, given two squares and with , color all squares between (including) these two squares black.
- Color a vertical line black. Specifically, given two squares and with , color all squares between (including) these two squares black.
- Color a diagonal line black. Specifically, given two squares and with and , color all squares with coordinates on the diagonal between these two squares, where . The number of times this type of coloring operation occurs is no more than .
Now you want to know how many black squares there are on the chessboard after performing coloring operations.
Input Specification
The first line of input contains an integer , which represents the test case number. If , it means that this test case is a sample test.
The second line of input contains three positive integers , , and , which respectively represent the number of columns, rows, and the number of coloring operations on the chessboard.
Then lines follow, each line containing five positive integers . Among them, represents the first type of coloring operation, represents the second type of coloring operation, and represents the third type of coloring operation. represent the four parameters of the coloring operation.
Output Specification
Output a line containing an integer, representing the number of black squares on the chessboard that have been colored.
Sample Input 1
0
5 5 3
1 1 3 5 3
2 3 1 3 5
3 1 1 5 5
Sample Output 1
13
Explanation of Sample Output 1
In this sample test, we performed a total of three coloring operations, as shown in the following figure. The state of the chessboard after each of the three operations are given in the order from left to right.
After the first operation, squares , , , , are colored black.
After the second operation, squares , , , , are colored black.
After the third operation, , , , , are colored black.
After all three coloring operations, a total of squares are colored black.
Additional Samples
Sample inputs and outputs can be found here.
- Sample 2 (
ex_color2.in
andex_color2.ans
) corresponds to test cases 1-5. - Sample 3 (
ex_color3.in
andex_color3.ans
) corresponds to test cases 6-9. - Sample 4 (
ex_color4.in
andex_color4.ans
) corresponds to test cases 10-13. - Sample 5 (
ex_color5.in
andex_color5.ans
) corresponds to test cases 14-17. - Sample 6 (
ex_color6.in
andex_color6.ans
) corresponds to test cases 18-19. - Sample 7 (
ex_color7.in
andex_color7.ans
) corresponds to test case 20.
Constraints
For all test data, it is guaranteed that: , and there are at most operations of the third type.
Test ID | Additional Constraints | ||
---|---|---|---|
None | |||
A | |||
B | |||
None | |||
Additional Constraint A: It is guaranteed that there is only the first type of coloring operation.
Additional Constraint B: It is guaranteed that there are only the first and second type of coloring operatio
Comments