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 dist(p1, p2)
  return Math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
end

def bruteForce(px)
  n = px.size
  min = INF
  n.times{|i|
    (i+1).upto(n-1){|j|
      d = dist(px[i], px[j])
      if d < min
        min = d
      end
    }
  }
  return min
end

def strip_closest(strip, size, d)
  min = d

  size.times{|i|
    (i+1).upto(size-1){|j|
      break if strip[j][1] - strip[i][1] >= min
      dd = dist(strip[i], strip[j])
      min = dd if dd < min
    }
  }
  return min
end

def closest_util(px, py, n)
  # p [px, py]
  return bruteForce(px) if n <= 3

  mid = n/2
  midpoint = px[mid]

  pyl = []
  pyr = []
  n.times{|i|
    if py[i][0] <= midpoint[0]
      pyl << py[i]
    else
      pyr << py[i]
    end
  }

  pxl = px[0,mid]
  pxr = px[mid, n-mid]

  dl = closest_util(pxr, pxl, mid)
  dr = closest_util(pxr, pyl, n-mid)

  d = [dl, dr].min

  strip = []
  n.times{|i|
    if (py[i][0] - midpoint[0]).abs < d
      strip << py[i]
    end
  }

  return [d, strip_closest(strip, strip.size, d)].min

end

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

px.sort!
py = px.map(&:clone)
py.sort! {|a, b| a[1] <=> b[1]}

puts closest_util(px, py, px.size)