QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#14555. Rectangle

统计

Little z has an infinite grid.

He wants to cover some rectangles on the grid. The top-left corner of the $i$-th rectangle is at grid coordinates $(x1_i, y1_i)$, and the bottom-right corner is at $(x2_i, y2_i)$.

Now, little z wants to know how many connected components the uncovered grid cells form. If two uncovered cells share an edge, they belong to the same connected component.

Specifically, the infinite region extending to the outermost boundary is also considered a connected component. For example, if there are no covered rectangles, the answer is 1.

Input

The first line contains an integer $n$ ($1 \le n \le 10^5$).

Each of the next $n$ lines contains 4 space-separated integers $x1_i, x2_i, y1_i, y2_i$, where $1 \le x1_i \le x2_i \le 10^9$ and $1 \le y1_i \le y2_i \le 10^9$.

Output

Output a single integer representing the answer.

Examples

Input 1

1
1 1 1 1

Output 1

1

Input 2

4
1 1 1 10
1 10 1 1
1 10 10 10
10 10 1 10

Output 2

2

Input 3

6
1 1 1 10
1 10 1 1
1 10 10 10
10 10 1 10
5 5 1 10
1 10 5 5

Output 3

5

Note

For the last example, the figure formed by the covered rectangles is shown below. It can be seen that the uncovered area is divided into 5 connected components.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.