#2396. 曼哈顿配对

曼哈顿配对

Manhattan Pairing

Background

Dawei is studying planar geometry and found that when the y-coordinates of points are highly restricted, the pairing problem becomes very interesting. He gathered some points and asked Congcong to help solve a problem about minimizing the maximum Manhattan distance in a pairing.

Problem Description

For a pair of points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) on the Cartesian plane, we define the Manhattan distance between them as x1x2+y1y2|x_1 - x_2| + |y_1 - y_2|. For example, the Manhattan distance between points (4,1)(4, 1) and (2,7)(2, 7) is 42+17=2+6=8|4 - 2| + |1 - 7| = 2 + 6 = 8.

Given 2n2 \cdot n points on the Cartesian plane with integer coordinates. The yy-coordinates of all points are either 00 or 11.

You need to divide these points into nn pairs such that each point belongs to exactly one pair, and the maximum Manhattan distance among all pairs is minimized.

Input Format

The input is provided from standard input in the following format:

nn x1x_1 y1y_1 x2x_2 y2y_2 ... x2nx_{2n} y2ny_{2n}

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

Each of the next 2n2 \cdot n lines contains two integers xix_i and yiy_i (0xi109,0yi10 \le x_i \le 10^9, 0 \le y_i \le 1), representing the coordinates of the points.

Output Format

The output should be sent to standard output in the following format:

ansans

Output a single integer representing the minimum possible value of the maximum Manhattan distance in an optimal pairing.

Sample

1
3 1
1 0
3
3
18 0
3 0
1 0
10 0
8 0
14 0
4

Sample Explanation

In the second sample, the optimal pairing is [(18,0),(14,0)][(18, 0), (14, 0)], [(3,0),(1,0)][(3, 0), (1, 0)], and [(8,0),(10,0)][(8, 0), (10, 0)]. This is the unique optimal pairing. The Manhattan distances are 44, 22, and 22 respectively.

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

Sample Explanation

In the third sample, the optimal pairing is [(0,1),(2,1)][(0, 1), (2, 1)], [(2,1),(3,0)][(2, 1), (3, 0)], [(3,0),(5,0)][(3, 0), (5, 0)], and [(5,1),(6,0)][(5, 1), (6, 0)]. The Manhattan distance for each pair is 22.

Constraints

Subtask Score Additional Constraints
11 22 n=1n = 1
22 33 xi=0x_i = 0 (for 1i2n1 \le i \le 2 \cdot n)
33 44 n4n \le 4
44 1111 n10n \le 10
55 1414 yi=0y_i = 0 (for 1i2n1 \le i \le 2 \cdot n)
66 1010 $x_i \
eq x_j$ (for 1i<j2n1 \le i < j \le 2 \cdot n)
77 2929 n1000n \le 1000
88 2727 No additional constraints

sample