luogu#P12351. 「HCOI-R2」哀之距

「HCOI-R2」哀之距

Background

A cat with horizontal and vertical patterns? Did you encounter it?

Meow... meow.

I don't know what kind of mental state the problem setter used to write about the background of such a problem, but I hope he can win the redance and return to OI.

Please note the special time limit of this problem.

Problem Description

The cat that Ai encountered can be treated as a plane with nn rectangles on it.

The coordinates of the bottom-left corner of the ii -th rectangle are (xi,0,yi,0)(x_{i, 0},y_{i, 0}) , and the coordinates of the top-right corner are (xi,1,yi,1)(x_{i, 1}, y_{i, 1}) .

Find the distance between the two rectangles with the largest distance.

The distance between two rectangles is defined as the minimum Chebyshev distance between any pair of points where one point lies in the first rectangle and the other in the second one (including the boundaries).

Chebyshev distance: The Chebyshev distance between (a,b)(a,b) and (c,d)(c,d) is max(ac,bd)\max(|a-c|,|b-d|).

Input Format

The first line contains an integer nn, representing the number of rectangles.

In the next nn lines, the ii-th line consists of four integers xi,0,yi,0,xi,1,yi,1x_{i,0},y_{i,0},x_{i,1},y_{i,1}, representing the ii-th rectangle.

Output Format

A single integer which represents the maximum distance between any two rectangles.

5
1 2 5 2
4 0 4 4
3 3 7 3
0 5 3 5
2 1 2 6
3

Hint

Constraints

This problem uses subtasks.

  • Subtask 0 (15 pts): n20n \leq 20, xi,0,yi,0,xi,1,yi,120x_{i,0}, y_{i,0}, x_{i,1}, y_{i,1} \le 20.
  • Subtask 1 (20 pts): n103n \leq 10^3.
  • Subtask 2 (25 pts): xi,0=xi,1,yi,0=yi,1x_{i,0} = x_{i,1}, y_{i,0} = y_{i,1}.
  • Subtask 3 (40 pts): No additional constraints.

For all test cases, it is guaranteed that 2n2×1052 \le n \le 2 \times 10^5 , 0xi,0xi,110180 \le x_{i,0} \le x_{i,1} \le 10^{18}, 0yi,0yi,110180 \le y_{i,0} \le y_{i,1} \le 10^{18}.