Олимпиадный тренинг

Задача 32983. Merging Rectangles


There are N rectangles on the plane with vertices at points with integer coordinates and sides parallel to the coordinate axes. It is necessary to find the area of ​​their union.
 
Input
The first line of the input file contains the number N (0N1500). The next N lines contain 4 integers x1, y1, x2, y2 — first the coordinates of the lower left corner of the rectangle, then the upper right (0x1x2109, 0y1y2109). Note that rectangles can degenerate into lines and even into points.
 
Output
Output a single number — answer to the problem.
 
Input Output
3
1 1 3 5
5 2 7 4
2 4 6 7
23
2
0 0 2 2
1 3 2 4
5