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

#CC0000080. Diện tích hợp các hình chữ nhật II (Rectangle Area II)

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 các hình chữ nhật II (Rectangle Area II)

Rectangle Area II

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given axis-aligned rectangles with bottom-left corner (x1i,y1i)(x_{1i},y_{1i}) and top-right corner (x2i,y2i)(x_{2i},y_{2i}), compute their union area, counting overlapping regions only once. Return the answer modulo 109+710^9+7.

Input

The first line contains nn, followed by nn lines x1i,y1i,x2i,y2ix_{1i},y_{1i},x_{2i},y_{2i}. This is the stdin/stdout adaptation.

Output

Print the union area modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le 8; 0≤x1i<x2i≤1090\le x_{1i}<x_{2i}\le10^9; 0≤y1i<y2i≤1090\le y_{1i}<y_{2i}\le10^9.
  • Subtask 2 (30 points): 1≤n≤401\le n\le 40; 0≤x1i<x2i≤1090\le x_{1i}<x_{2i}\le10^9; 0≤y1i<y2i≤1090\le y_{1i}<y_{2i}\le10^9.
  • Subtask 3 (50 points): 1≤n≤2001\le n\le 200; 0≤x1i<x2i≤1090\le x_{1i}<x_{2i}\le10^9; 0≤y1i<y2i≤1090\le y_{1i}<y_{2i}\le10^9.

Examples

Input

3
0 0 2 2
1 0 2 3
1 0 3 1

Output

6

Explanation

The first rectangle covers area 44. The second adds area 11 above it, and the third adds area 11 to its right. The union area is 66.