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 Kotlin (judge verdict: Time Limit Exceeded)

import java.math.BigDecimal
import java.util.*


fun solve(a: Array<Array<Double>>, sortedAxis: Int = -1): Double {
    if (a.size <= 3) {
        var dist = 1000000000000.0
        for ((i, p1) in a.withIndex()) {
            for (p2 in a.takeLast(a.size-i-1)) {
                dist = Math.min(dist, Math.sqrt(Math.pow(p1[0]-p2[0], 2.0)+Math.pow(p1[1]-p2[1], 2.0)))
            }
        }
        return dist
    }

    val mid = a.size/2
    val xSetLen = a.map { it -> it[0] }.toHashSet().size
    val (axis1, axis2) = if (xSetLen >= mid) Pair(0, 1) else Pair(1, 0)
    if (axis1 != sortedAxis) a.sortBy { it[axis1] }

    val leftArray = a.sliceArray(0 until mid)
    val rightArray = a.sliceArray(mid until a.size)
    var delta = Math.min(solve(leftArray, axis1), solve(rightArray, axis1))
    val median = a[mid][axis1]
    val mid_a = a.filter { it[axis1] in median-delta..median+delta }.sortedBy { it[axis2] }

    for (i in 0 until mid_a.size-1) {
        val ub = mid_a[i][axis2] + delta
        for (j in i+1 until mid_a.size) {
            if (mid_a[i][axis2] >= ub) break
            delta = Math.min(delta,
                    Math.sqrt(Math.pow(mid_a[i][0]-mid_a[j][0], 2.0)+Math.pow(mid_a[i][1]-mid_a[j][1], 2.0)))
        }
    }

    return delta
}
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val a = Array(N, { arrayOf(sc.nextDouble(), sc.nextDouble()) })
    val ans = solve(a)
    println(BigDecimal.valueOf(ans).toPlainString())
}