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 Ruby (judge verdict: Wrong Answer)

INF = 1.0 / 0.0

def length(a, b)
  return Math.sqrt((b[0] - a[0])**2 + (b[1] - a[1])**2)
end
def closest_pair(pt, s, e)
  return INF if e - s < 1
  return length(pt[s], pt[e]) if e - s == 1
  m = (e + s) / 2
  x = pt[m][0]
  d = [closest_pair(pt, s, m), closest_pair(pt, m, s)].min
  sorted = pt[s..e].sort{|a, b| a[1] <=> b[1]}
  tmp = []
  sorted.size.times{|it|
    next if ((sorted[it][0] - x).abs >= d)
    (tmp.size-1).downto(0){|i|
      dx = sorted[it][0] - tmp[i][0]
      dy = sorted[it][1] - tmp[i][1]
      break if dy >= d
      d = [d, Math.sqrt(dx*dx+dy*dy)].min
    }
    tmp << sorted[it]
  }
  return d
end

n = gets.to_i
pt = []
n.times{|i|
  pt[i] = gets.split.map(&:to_f)
}

pt.sort!

puts closest_pair(pt, 0, n-1)