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: Time Limit Exceeded)

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)
  n = pt.size
  return INF if n == 1
  return length(pt[0], pt[1]) if n == 2
  m = n / 2
  x = pt[m][0]
  d = [closest_pair(pt[0..m]), closest_pair(pt[m..-1])].min

  sorted = []
  n.times{|i|
    sorted << i if (pt[i][0] - x).abs < d
  }
  m = sorted.size
  m.times{|i|
    (i+1).upto(m-1){|j|
      if (pt[sorted[i]][0] - x) * (pt[sorted[j]][0] - x) < 0
        it = length(pt[sorted[i]], pt[sorted[j]])
        break if it > d
        d = it
      end
    }
  }
  return d
end

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

pt.sort!

puts "%.8f" % closest_pair(pt)