Problem Statement
Several rectangular sheets are placed on a plane. Write a program to find the area and perimeter of the region covered by these sheets.
However, when the plane is regarded as a coordinate plane, assume that the placement of the sheets satisfies the following conditions $(1)$ and $(2)$.
- $(1)$ The $x, y$ coordinates of the $4$ vertices of each rectangular sheet are all integers greater than or equal to $0$ and less than or equal to $10000$, and each side of the rectangle is parallel to the $x$-axis or the $y$-axis.
- $(2)$ The number of sheets is at most $10000$ or fewer.
The name of the input file is input.txt. The $1$-st line of input.txt contains the number of rectangles $n$ and an integer $r$ representing the type of problem, separated by a space. Each line from the $2$-nd line onward contains the coordinate values of the bottom-left vertex coordinates $(x_1, y_1)$ and the top-right vertex coordinates $(x_2, y_2)$ of each sheet, written in the order $x_1, y_1, x_2, y_2$ separated by spaces.
The name of the output file is output.txt. In output.txt, output the area on the $1$-st line when $r = 1$, and output the area on the $1$-st line and the perimeter on the $2$-nd line when $r = 2$. In either case, insert a newline at the end.
Also, in $40\%$ of the test data, the coordinates of the vertices of the rectangles are between $0$ and $100$ inclusive, and $1/2$ of those are problems asking only for the area. Furthermore, $1/2$ of the entire test data are problems asking only for the area.
Sample 1
Sample Input 1
5 1 0 0 3 2 1 1 2 5 0 4 6 5 3 3 5 6 5 0 7 6
Sample Output 1
29
Sample 2
Sample Input 2
5 2 0 0 3 2 1 1 2 5 0 4 6 5 3 3 5 6 5 0 7 6
Sample Output 2
29 38
Sample 3
Sample Input 3
2 2 0 0 8 9 0 0 9 8
Sample Output 3
80 36
Sample 4
Sample Input 4
3 2 2 2 8 8 3 0 4 9 5 0 7 9
Sample Output 4
45 36