Time limit
2s
Memory limit
128 MB
Minsik wants to put apology letters on a wall for Youngsik. Each letter is a 1 x 1 square. The lower-left corner of the wall is the origin (0, 0), the positive x-axis points right, and the positive y-axis points up.
A unit square whose lower-left corner is (x, y) is treated as one cell. At first, no cell has a letter. For each operation, Minsik chooses the rectangle from (x1, y1) to (x2, y2), meaning all cells with x1 <= x < x2 and y1 <= y < y2, and puts letters on some of those cells. If a cell already has a letter, putting another one there does not increase the count.
Each rectangle uses one of the following four methods.
y.x.(x + y) has the same parity as (x1 + y1).After all rectangles are processed, compute the total number of cells that have a letter.
The first line contains the number of rectangles N. N is a positive integer not greater than 100.
Each of the next N lines contains one rectangle in the form x1 y1 x2 y2 p. The point (x1, y1) is the lower-left corner of the rectangle, and (x2, y2) is the upper-right corner. The value p is the method number described above and is one of 1, 2, 3, or 4.
It is always true that x1 < x2 and y1 < y2. All of x1, y1, x2, and y2 are positive integers not greater than 40,000.
Print the total number of cells on the wall that have a letter.
In the first public test, the 10 x 10 rectangle affected by methods 1 and 2 fills 100 cells. The other 10 x 10 rectangle affected by methods 3 and 4 fills 75 cells. The two filled regions share 3 cells, so the answer is 100 + 75 - 3 = 172.