Rectangles
Time limit1sMemory limit128 MB
Compute the total area covered by up to 1000 axis-aligned rectangles, counting overlaps once.
Problem
A rectangle whose sides are parallel to the axes is always determined by the two endpoints of one of its diagonals. For example, a rectangle can be drawn once the top left corner and the bottom right corner are given.

Given a set of rectangles, we want the total area they cover. In the picture below, the total area is the region inside the solid lines. An overlapping region is counted once, not twice.

Write a program that reads a set of rectangles and computes the total area covered by all of them.
Input
The input describes a set of rectangles, where is between 0 and 1000. The first line contains the integer . Each of the remaining lines holds the coordinates of one rectangle as four integers , , , , which give the two points and . One or more blanks separate the numbers. These two points are not necessarily the top left and bottom right corners. Every and is between 0 and .
Output
On the first line print the total area covered by the rectangles. You may assume that the area is at most .