Problem:
Closest Pair

For given n points in metric space, find the distance of the closest points.

Input

n
x0 y0
x1 y1
:
xn-1 yn-1

The first integer n is the number of points.

In the following n lines, the coordinate of the i-th point is given by two real numbers xi and yi. Each value is a real number with at most 6 digits after the decimal point.

Output

Print the distance in a line. The output values should be in a decimal fraction with an error less than 0.000001.

Constraints

2 ≤ n ≤ 100,000

-100 ≤ x, y ≤ 100

Sample Input 1

2
0.0 0.0
1.0 0.0

Sample Output 1

1.000000

Sample Input 2

3
0.0 0.0
2.0 0.0
1.0 1.0

Sample Output 2

1.41421356237

Solution in Python3 (judge verdict: Time Limit Exceeded)

import sys
from operator import itemgetter
from itertools import permutations
from math import sqrt

def solve(a: list, axis: int = 0):
    length = len(a)
    if length <= 3:
        return min(sqrt((p1[axis]-p2[axis])**2+(p1[not axis]-p2[not axis])**2) for p1, p2 in permutations(a, 2))

    med = length//2
    left, right = a[:med], a[med:]
    delta = min(solve(left, axis), solve(right, axis))
    median_x = a[med][axis]
    m_a = []
        
    for p in left[::-1]:
        if p[axis] < median_x-delta:
            break
        m_a.append(p)
    for p in right:
        if p[axis] > median_x+delta:
            break
        m_a.append(p)
    m_a.sort(key=itemgetter(not axis))

    for i, p1 in enumerate(m_a):
        ub = p1[not axis] + delta
        for j, p2 in enumerate(m_a[i+1:]):
            if p2[not axis] > ub:
                break
            delta = min(delta, sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2))

    return delta

if __name__ == "__main__":
    N = int(input())
    a = sorted([tuple(map(float, l.split())) for l in sys.stdin.readlines()])
    axis = 0 if len(set(p[0] for p in a)) > len(set(p[1] for p in a)) else 1
    print("{:.10f}".format(solve(a, axis)))