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)
  min = INF
  n.times{|i|
    (i+1).upto(n-1){|j|
      d = dist(px[i], px[j])
      min = d if d < min
    }
  }
  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 ["cl:", px, py, n]
  return bruteForce(px, n) if n <= 3

  mid = n/2 - 1
  midpoint = px[mid]

#  p midpoint

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

#  p ["mid", mid]

  pxl = px[0,pyl.size].clone
  pxr = px[pyl.size, pyr.size].clone

  # p ["pxl:", pxl]
  # p ["pyl:", pyl]
  # p ["pxr:", pxr]
  # p ["pyr:", pyr]

  dl = closest_util(pxl, pyl, pyl.size)
  dr = closest_util(pxr, pyr, pyr.size)

  d = [dl, dr].min

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

  # p strip

  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)