#P5987. [PA 2019] Terytoria

[PA 2019] Terytoria

Description

On a 2D Cartesian coordinate plane, there is a map of length XX and width YY. Note that the left and right boundaries of this map are connected, and the bottom and top boundaries are also connected.

On this map, there are X×YX \times Y grid cells and nn axis-aligned rectangles. You only know the coordinates of two opposite vertices of each rectangle. In the best case, what is the maximum possible number of grid cells that are covered by all nn rectangles?

Input Format

The first line contains three positive integers n,X,Yn, X, Y.

The next nn lines each contain 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 \ne x_2, y_1 \ne y_2)$, meaning that for the ii-th rectangle, the coordinates of its two opposite vertices are (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2).

Output Format

Output one line with one integer: the maximum possible number of grid cells covered by all nn rectangles.

2 10 7
2 1 8 6
5 2 4 4
15

Hint

For 100%100\% of the testdata, 1n5×1051 \le n \le 5 \times 10^5, 2X,Y1092 \le X, Y \le 10^9.

Sample Explanation

The figure below lists some cases, where the third case is optimal.

Translated by ChatGPT 5