cho.sh
Notes
Loading...

Letters on the Wall

Time limit

2s

Memory limit

128 MB

Problem

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.

  1. Put letters on every cell in the rectangle.
  2. Put letters on cells in odd-numbered rows of the whole wall. In coordinates, these are exactly the cells with even y.
  3. Put letters on cells in odd-numbered columns of the whole wall. In coordinates, these are exactly the cells with even x.
  4. Count rows and columns from the rectangle's lower-left corner, and put letters on cells whose row and column numbers have the same parity. In coordinates, these are exactly the cells where (x + y) has the same parity as (x1 + y1).

After all rectangles are processed, compute the total number of cells that have a letter.

Input

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.

Output

Print the total number of cells on the wall that have a letter.

Hint

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.