Where to Put the Mail Room
A company campus is laid out on a grid of streets, and its n offices sit at integer coordinates. Each morning a courier walks from the mail room to every office, always along the streets. The walk from point (a, b) to an office at (x, y) is |a − x| + |b − y| meters.
Facilities wants to build the mail room at the integer point (a, b) that minimizes the total walking distance
D(a, b) = Σ (|a − x_i| + |b − y_i|), summed over all offices i.
The mail room may go anywhere, including on the same point as an office. If several points give the minimum, facilities picks the one with the smallest a, and among those, the one with the smallest b.
Find that point and the minimum total distance.
Input
The first line contains an integer n (1 ≤ n ≤ 2·10^5), the number of offices.
Each of the next n lines contains two integers x_i and y_i (−10^9 ≤ x_i, y_i ≤ 10^9), the coordinates of one office. Several offices may share the same point.
Output
Print three integers separated by spaces: a, b and D(a, b).
Notes
In the first example the best point is (3, 2), which is not an office. The distances from it to the three offices are 3, 3 and 1, for a total of 7.
In the second example, every point with 0 ≤ a ≤ 10 and 0 ≤ b ≤ 10 gives the same total, 40. The tie-break picks (0, 0).
The total can exceed 2^31, so use 64-bit integers.