Lukas has a very large grid. Initially every cell is white. He has three patterns, numbered 1 to 3 (from left to right):
XXXX X.X. X.X.
.... X.X. .X.X
XXXX X.X. X.X.
.... X.X. .X.X
Each pattern is periodic and can be extended to fill a rectangle of any size. Lukas paints the grid N times. Each time he chooses an axis-aligned rectangle and one pattern, then paints the cells inside the rectangle black according to that pattern (an X in the pattern paints the cell black, a . leaves it unchanged). The pattern is anchored so that its top-left corner coincides with the top-left corner of the rectangle: the grid point with the smallest x coordinate and the largest y coordinate.
When painted areas overlap, the OR rule applies: a cell is black if it was painted black by at least one operation. For example, applying pattern 1 and then pattern 3 to the same 4×4 rectangle yields:
XXXX
.X.X
XXXX
.X.X
After all N operations, compute the number of black cells.
The first line contains an integer N (0≤N≤100000). Each of the next N lines contains five integers x1, y1, x2, y2, p, where (x1,y1) and (x2,y2) are two opposite corners of the rectangle (given as grid points), and p (1≤p≤3) is the pattern number. All coordinates have absolute value at most 109, and every rectangle is at least one unit wide and one unit tall.
Print a single integer: the number of black cells after all operations.