Under construction

Still being built. Things may change

Interesting Couple

Time limit2sMemory limit2048 MB

Summary
Given N points in the plane with Manhattan distance, find the smallest p(i, j) among pairs whose distance d(i, j) is no more than p(i, j).
Level

Medium7 of 10

Topics
Geometry, Sorting, Segment tree
Solved
No attempts yet

Problem

You are hosting a party with NN guests (numbered from 11 to NN) in a large room. The party room is a 2-dimensional Cartesian space where guest ii stands at (Xi,Yi)(X_i, Y_i). Each guest may only move horizontally or vertically within the room.

The distance between two guests ii and jj, written d(i,j)d(i, j), is the total horizontal and vertical distance they need to travel to reach each other: d(i,j)=∣Xi−Xj∣+∣Yi−Yj∣d(i, j) = |X_i - X_j| + |Y_i - Y_j|.

The privacy value of two guests ii and jj, written p(i,j)p(i, j), is the smallest min⁡(d(i,k),d(j,k))\min(d(i, k), d(j, k)) over all kk with k≠ik \ne i and k≠jk \ne j. In other words, it is decided by how close each of them is to their nearest other guest.

A pair of guests ii and jj is an interesting couple if p(i,j)≥d(i,j)p(i, j) \ge d(i, j).

Find the minimum value of p(i,j)p(i, j) among all interesting couples.

Input

The first line contains an integer NN (3≤N≤1000003 \le N \le 100000). Each of the next NN lines contains two integers XiX_i and YiY_i (0≤Xi,Yi≤1090 \le X_i, Y_i \le 10^9). No two guests stand at the same location, that is, (Xi,Yi)≠(Xj,Yj)(X_i, Y_i) \ne (X_j, Y_j) for 1≤i<j≤N1 \le i < j \le N.

Under the given constraints, an interesting couple always exists.

Output

Output one integer: the minimum value of p(i,j)p(i, j) among all interesting couples.

Examples4

  1. Example 1

    Input
    4
    3 2
    6 4
    3 4
    4 7
    
    Expected output
    3
    
  2. Example 2

    Input
    3
    4 6
    8 6
    6 4
    
    Expected output
    4
    
  3. Example 3

    Input
    5
    1 5
    2 5
    11 5
    12 5
    20 5
    
    Expected output
    8
    
  4. Example 4

    Input
    5
    4 4
    4 3
    4 5
    3 4
    5 4
    
    Expected output
    1