QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 512 MB 總分: 100

#8752. Grid

统计

Little I is learning calligraphy, but when he opened his blank paper, he remembered that he had previously doodled $n$ line segments on it, leaving the rest of the paper white.

These $n$ blackened line segments are either horizontal or vertical. Using the center of the paper as the origin, with the $x$-axis and $y$-axis parallel to the edges of the paper, each blackened line segment with endpoints $(x_1, y_1)$ and $(x_2, y_2)$ satisfies exactly one of $x_1 = x_2$ or $y_1 = y_2$. Furthermore, no two horizontal line segments intersect, and no two vertical line segments intersect.

Although the blackened segments are annoying, Little I, who understands that fortune and misfortune are intertwined, discovered that the $n$ segments form several "tian-zi" grids (grid squares), which he can use for calligraphy practice.

A "tian-zi" grid can be described by a triple $(x_0, y_0, d)$. A triple $(x_0, y_0, d)$ is a "tian-zi" grid if and only if the following conditions are met:

  • $x_0, y_0 \in \mathbb{R}$, $d \in \mathbb{R}^+$;
  • Let $R = [x_0-d, x_0+d] \times [y_0-d, y_0+d]$ be the set of all points with $x$-coordinates in $[x_0-d, x_0+d]$ and $y$-coordinates in $[y_0-d, y_0+d]$. The blackened part within $R$ consists exactly of six line segments, which are the intersections of $R$ with the lines $x=x_0-d$, $x=x_0$, $x=x_0+d$, $y=y_0-d$, $y=y_0$, and $y=y_0+d$.

Little I wants to calculate how many "tian-zi" grids are on the paper, i.e., how many triples $(x_0, y_0, d)$ satisfy the above conditions. As usual, Little I cannot calculate this, so he has entrusted the task to you.

Input

The first line contains an integer $n$ ($1 \le n \le 3 \times 10^5$), representing the number of line segments. Each of the next $n$ lines contains four integers $x_1, y_1, x_2, y_2$ ($-10^9 \le x_1 \le x_2 \le 10^9, -10^9 \le y_1 \le y_2 \le 10^9$), representing a line segment.

Each line segment in the input satisfies exactly one of $x_1 = x_2$ or $y_1 = y_2$. Additionally, no two line segments with $x_1 = x_2$ intersect, and no two line segments with $y_1 = y_2$ intersect.

Output

Output a single integer representing the number of "tian-zi" grids.

Examples

Input 1

10
-10 -10 -10 10
0 -10 0 10
10 -10 10 10
-10 -10 10 -10
-10 0 10 0
-10 10 10 10
5 -10 5 10
-10 5 10 5
-2 0 -2 10
-5 -5 10 -5

Output 1

3

Note

img
As shown in the figure above, $(5, 5, 5), (5, 0, 5), (5, -5, 5)$ are three valid "tian-zi" grids. Note that the following are not "tian-zi" grids:

  • $(0, 0, 10)$, because there are blackened parts other than the required six line segments;
  • $(-5, 5, 5)$, because the intersection of $x=-5$ with the square is not blackened.

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.