Olya is a model problem solver who tackles challenges every day. However, working from home is nearly impossible because her mischievous cat, Konstantin, is always ready to cause trouble. When Olya received a huge white piece of Cartesian plane for her birthday, Konstantin immediately decided to ruin this wonderful gift.
The plane is a white square with its bottom-left corner at and its top-right corner at (N, N). For convenience, Olya places an ink bottle in each corner, i.e., at the points , , , and (N, N), and sits down to write a complex contest.
While Olya is working on problems, Konstantin may "accidentally" tip over any ink bottle. As a result, the rectangular area between the bottle and the point on the plane will be completely covered in ink. Olya will, of course, be upset, but she has to refill the ink bottle and return to her contest. Then, Konstantin can spill ink again, covering a new area of the plane.
Sometimes, when Olya encounters a particularly difficult problem, she decides to jot down her thoughts on some part of her plane. For notes, she always chooses a rectangle parallel to the coordinate axes. Of course, Olya needs to know how much of the chosen area is already covered with ink. Since she is busy solving problems during the contest, she needs your help to find this out.
Write a program that helps Olya calculate the area of the painted part of the plane, based on the events that occurred during the contest.
The first line contains two integers and (1 \le N, Q \le 10^5), the size of the plane and the number of events during the contest, respectively.
Each of the following lines describes an event. Every line starts with the integer , which describes the type of the event.
If 1 \le t \le 4, this means Konstantin spills the corresponding ink bottle. In this case, two integers and (0 \le x, y \le N) follow, specifying the opposite corner of the area that will be painted black.
The first ink bottle is at the bottom-left, the second at the bottom-right, the third at the top-left, and the fourth at the top-right corners.
If t = 0, four integers x_1, y_1, x_2, y_2 (0 \le x_1 < x_2 \le N, 0 \le y_1 < y_2 \le N) follow — Olya selects a rectangle parallel to the axes with opposite corners at (x_1, y_1) and (x_2, y_2).
It is guaranteed that there is at least one event of type in the input, and the cat only spills ink over rectangles of positive area.
For every query of type , output a single integer on a separate line — the area of the corresponding part of the plane that is already covered with ink. Print the answers in the order the queries appear in the input.
Example 1
Subtask | Points | Additional Constraints | Required Subtasks |
|---|---|---|---|
0 | 0 | Tests from the statement | - |
1 | 5 | 1 \le N, Q \le 100 | 0 |
2 | 6 | 1 \le N, Q \le 1000, t \in \{ 0, 1, 2 \} | - |
3 | 8 | 1 \le N, Q \le 1000 | 0, 1, 2 |
4 | 14 | 1 \le N, Q \le 50000, number of type queries not more than | 0 |
5 | 12 | 1 \le N, Q \le 50000, t \in \{ 0, 1 \}, for all type queries: if query comes after query , then x_a \le x_b, y_a \ge y_b | - |
6 | 8 | 1 \le N, Q \le 50000, t \in \{ 0, 1 \} | - |
7 | 10 | 1 \le N, Q \le 50000, t \in \{ 0, 1, 2 \} | 2, 5, 6 |
8 | 13 | 1 \le N, Q \le 50000 | 0, 1, 2, 3, 4, 5, 6, 7 |
9 | 9 | t \in \{ 0, 1 \} | 5, 6 |
10 | 8 | t \in \{ 0, 1, 2 \} | 2, 5, 6, 7, 9 |
11 | 7 | No additional constraints | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 |
