Closest Pair of Points
You are given n points on the plane with integer coordinates. Point i is (x_i, y_i). Several points may coincide.
Find the smallest squared Euclidean distance between two points with different indices, that is, the minimum of (x_i − x_j)^2 + (y_i − y_j)^2 over all pairs 1 ≤ i < j ≤ n.
Input
The first line contains an integer n (2 ≤ n ≤ 2·10^5), the number of points.
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 point i.
Output
Print one integer: the minimum squared distance between two points with different indices.
Notes
The answer can be as large as 8·10^18, so it fits in a signed 64-bit integer but not in a 32-bit one. Squaring a coordinate difference also needs 64-bit arithmetic.
In the first example the closest pair is (2, 3) and (3, 4), at squared distance 1 + 1 = 2.
In the second example two points coincide, so the answer is 0.