Venue Rental (Large)

Given up to 3000 axis-aligned rectangles, find the total area of their union, counting overlaps once.

Medium7GeometrySortingSegment treePrefix sumInterviewNo attempts yetTime limit5sMemory limit256 MB

Problem

Sanghyun is planning a farewell party before he leaves for his military service, so he wants to rent a venue for it.

Everyone who works at the rental company is a former programmer, which makes the rental procedure unusual. Once Sanghyun picks the place he wants, the company builds NN rectangles that cover that place exactly. It then tells him the number of rectangles NN and, for each rectangle, the coordinates of its lower left corner and its upper right corner. The NN rectangles may overlap in part or in full. Every side of every rectangle is parallel to a coordinate axis.

Write a program that computes the area of the venue Sanghyun rented, which is the area of the region covered by the NN rectangles.

Input

The first line contains the number of rectangles NN. (2N30002 \le N \le 3000)

Each of the next NN lines contains four integers x1x_1, y1y_1, x2x_2, y2y_2 in this order. (50000x1<x250000-50000 \le x_1 < x_2 \le 50000, 50000y1<y250000-50000 \le y_1 < y_2 \le 50000) The lower left corner of that rectangle is (x1,y1)(x_1, y_1) and its upper right corner is (x2,y2)(x_2, y_2).

Output

Print the area of the venue Sanghyun rented on the first line. Count an overlapping part only once. The area reaches 101010^{10}, so it does not fit in a 32-bit integer.