QOJ.ac

QOJ

Time Limit: 9 s Memory Limit: 256 MB Total points: 10

#210. Territories [B]

Statistics

Bajtazar is a biologist studying the fauna of a newly discovered planet. He has observed that $n$ different types of unique animal species live on the planet. Unfortunately, geologists have simultaneously discovered large mineral deposits on the planet, and there are plans to build massive mines that could threaten the planet's ecological balance.

All species on the planet are territorial animals—each species has a fixed rectangle in which it can move. To appease the biologists, the Interplanetary Parliament has issued a decree stating that the area lying within the territories of all species is to become a nature reserve (so no mines will be built there).

During his study of the planet, for each species, Bajtazar recorded a pair of coordinates $(x_1, y_1)$ and $(x_2, y_2)$ for opposite vertices of the rectangle describing that species' territory. Now he has returned to Earth and is analyzing the collected data, wanting to determine the area of the reserve.

It is worth mentioning here that the planet is shaped like a torus, and its map can be represented as a grid of dimensions $X \times Y$ with a coordinate system applied. Points on the map are defined by their coordinates $(x, y)$, where $0 \le x < X$ and $0 \le y < Y$. All territories are rectangles with sides parallel to the coordinate axes.

Unfortunately, Bajtazar did not take into account that since the planet is a torus, two points do not uniquely define a rectangle. In fact, for each species, there are as many as four possible territories consistent with the collected data. However, the Parliament wants to know as soon as possible how many mines can definitely be built in order to include the projected profits from mineral extraction in next year's budget. To this end, based on the existing data, Bajtazar needs to determine the maximum possible surface area of the nature reserve.

Input

The first line of the input contains three integers $n$, $X$, and $Y$ ($1 \le n \le 500\,000$, $2 \le X, Y \le 10^9$) representing the number of animal species and the dimensions of the map.

Each of the next $n$ lines contains four integers $x_1, y_1, x_2, y_2$ ($0 \le x_1, x_2 < X$, $0 \le y_1, y_2 < Y$, $x_1 \neq x_2$, $y_1 \neq y_2$) defining the opposite vertices of the next species' territory—these vertices have coordinates $(x_1, y_1)$ and $(x_2, y_2)$.

Output

The output should contain a single integer—the maximum possible area of the intersection of all territories.

Examples

Input 1

2 10 7
2 1 8 6
5 2 4 4

Output 1

15

Note

The example explanation: The drawings below show three possibilities (out of 16) for the placement of two territories for vertices with coordinates $(2, 1), (8, 6)$ and $(5, 2), (4, 4)$ on a $10 \times 7$ map. The common parts have sizes of 0, 8, and 15, respectively, with the last drawing representing the largest possible reserve. Note that the reserve area does not have to be connected.

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.