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

#PS0000251. Diện tích hợp hình chữ nhật (Rectangle Union Area)

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 (Rectangle Union Area)

Rectangle Union Area

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given NN axis-aligned rectangles [xi,Xi)×[yi,Yi)[x_i,X_i)\times[y_i,Y_i), find the area covered by at least one rectangle. Count overlap only once; boundaries have zero area.

Input

First line: NN. Each of the next NN lines contains xi,yi,Xi,Yix_i,y_i,X_i,Y_i.

Output

Print one integer: the union area.

Subtasks

  • Subtask 1 (20 points): 1≤N≤301\le N\le 30; 0≤xi<Xi≤300\le x_i<X_i\le 30; 0≤yi<Yi≤300\le y_i<Y_i\le 30.
  • Subtask 2 (30 points): 1≤N≤2001\le N\le 200; 0≤xi<Xi≤10000000000\le x_i<X_i\le 1000000000; 0≤yi<Yi≤10000000000\le y_i<Y_i\le 1000000000; yi=y1,Yi=Y1y_i=y_1, Y_i=Y_1.
  • Subtask 3 (50 points): 1≤N≤2001\le N\le 200; 0≤xi<Xi≤10000000000\le x_i<X_i\le 1000000000; 0≤yi<Yi≤10000000000\le y_i<Y_i\le 1000000000.

Example 1

Input

2
0 0 3 2
2 1 5 4

Output

14

Explanation

Areas are 6 and 9, intersection is 1; union is 14.

Example 2

Input

3
0 0 2 2
2 0 4 2
0 0 2 2

Output

8

Explanation

First two rectangles touch along an edge; third repeats first. Total is 8.