This page is still under construction.

Parts of this page are still being built. What you see may change.

Police Stations

Time limit1sMemory limit512 MB

Summary
Choose integer coordinates for a control center and axis-aligned cable limits L and W so every station is reachable, minimizing L+W then L.
Level

Medium6 of 10

Topics
Binary search, Math, Geometry, Greedy
Solved
No attempts yet

Problem

There are NN police stations in Flatland, and the ii-th police station is at coordinate (xi,yi)(x_i, y_i). The authority wants to increase cooperation among these police stations by reducing the miscommunication that often arises between them. To do this, the authority decides to build a new tower that will serve as the Communication Control Center (CCC). The CCC can only be built at (x,y)(x, y) where both xx and yy are integers. It does not matter whether a police station already occupies (x,y)(x, y); the CCC can be built alongside that police station.

The CCC then draws a communication cable to each police station, with some restrictions.

  • Each cable serves only one police station, so serving NN police stations requires NN cables.
  • A cable can only be laid parallel to the xx-axis or the yy-axis. Diagonal crossing is not allowed.

Because of a strange physics law in Flatland, each cable can have length at most LL in the xx-axis direction and at most WW in the yy-axis direction. This is why such a cable is called an ⟨L,W⟩\langle L, W \rangle cable in Flatland. For stable communication, all police stations must be connected by the same type of cable.

Recent advances in science and technology in Flatland let physicists build an ⟨L,W⟩\langle L, W \rangle cable for any LL and WW they like, at a cost. The cost becomes very expensive for larger LL and WW, so the authority must find LL and WW that satisfy their need, connecting all police stations to the CCC, while minimizing the value of L+WL + W.

In this problem, you must find LL and WW such that L+WL + W is minimized, the authority can build the CCC at (x,y)(x, y) where both xx and yy are integers, and all police stations can be connected to the CCC with ⟨L,W⟩\langle L, W \rangle cables. If there are multiple solutions, minimize LL first, and then minimize WW.

Input

The first line contains an integer NN (1≤N≤100 0001 \le N \le 100\,000), the number of police stations in Flatland. Each of the next NN lines contains two integers xix_i yiy_i (−106≤xi,yi≤106-10^6 \le x_i, y_i \le 10^6), the location of a police station.

Output

Output two integers LL and WW separated by a single space, such that L+WL + W is minimized, the authority can build the CCC at (x,y)(x, y) where both xx and yy are integers, and all police stations can be connected to the CCC with ⟨L,W⟩\langle L, W \rangle cables. If there are multiple solutions, minimize LL first, and then minimize WW.

Examples3

  1. Example 1

    Input
    5
    20 90
    -10 40
    90 20
    50 -30
    50 70
    
    Expected output
    50 60
    
  2. Example 2

    Input
    2
    120 740
    122 749
    
    Expected output
    1 5
    
  3. Example 3

    Input
    5
    -30 -7
    2 80
    23 15
    31 30
    92 -20
    
    Expected output
    61 50