PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CC0000081. Diện tích hợp hình chữ nhật (Area of Rectangles)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Diện tích hợp hình chữ nhật (Area of Rectangles)

Area of Rectangles

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn axis-aligned rectangles, compute the exact union area of the regions covered by at least one rectangle. Overlaps must be counted once. Print the exact value without any modulo.

Input

The first line contains nn, followed by nn lines x1,y1,x2,y2x_1,y_1,x_2,y_2.

Output

Print the exact union area as an integer.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; −106≤x1<x2≤106-10^6\le x_1<x_2\le10^6; −106≤y1<y2≤106-10^6\le y_1<y_2\le10^6.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; −106≤x1<x2≤106-10^6\le x_1<x_2\le10^6; −106≤y1<y2≤106-10^6\le y_1<y_2\le10^6.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; −106≤x1<x2≤106-10^6\le x_1<x_2\le10^6; −106≤y1<y2≤106-10^6\le y_1<y_2\le10^6.

Examples

Input

3
1 3 4 5
3 1 7 4
5 3 8 6

Output

24

Explanation

The rectangle areas are 66, 1212, and 99. Two overlap regions have areas 11 and 22, and there is no triple overlap. Hence 6+12+9−1−2=246+12+9-1-2=24.