1.

/**
* ACM Training 2009
* ACM Problem #10245 - The Closest Pair Problem
*
* @author Felix Dietrich
* @version 1.0, 10/31/2009
*
* Methode: Closest Pair Algo
* Status : Accepted
* Runtime: 2.916
* http://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&page=show_problem&category=&problem=1186&mosmsg=Submission+received+with+ID+7524024
*/

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main
{
/**
* Standart point class
*/
public static class Point implements Comparable<Point>
{
protected double x;
protected double y;

public Point(double d, double e)
{
this.x = d;
this.y = e;
}

/**
* Compares two points by x and y value
*/
@Override
public int compareTo(Point p1)
{
if(Math.abs(this.x - p1.x) < 1e-6)
{
if(Math.abs(this.y - p1.y) < 1e-6)
return 0;
if(this.y < p1.y)
return -1;
else
return 1;
}
if(this.x < p1.x)
return -1;
else
return 1;
}
}

public static void main(String... as) throws IOException
{
Scanner sc;
sc = new Scanner(System.in);

int n;
List<Point> points = new ArrayList<Point>();
List<Point> newpoints = new ArrayList<Point>();
Point q,r;
double distance;

while(sc.hasNext())
{
points.clear();
newpoints.clear();

n = sc.nextInt();
if(n == 0)
return;

// Read the points
for(int i=0; i<n; i++)
points.add(new Point(sc.nextDouble(), sc.nextDouble()));

if(points.size() == 1)
{
System.out.println("INFINITY");
continue;
}

// sort ascending by x and y value
Collections.sort( points );

q = points.get(0);
r = points.get(1);
newpoints.add(q);
newpoints.add(r);

distance = (q.x-r.x)*(q.x-r.x) + (q.y-r.y)*(q.y-r.y);

Point m;
Point pi;

for(int i=2; i<n; i++)
{
pi = points.get(i);
for(int k=0; k<newpoints.size(); k++)
{
m = newpoints.get(k);
if((pi.x - m.x)*(pi.x - m.x) > distance)
{
newpoints.remove(k);
k--;
}
else
if((pi.x-m.x)*(pi.x-m.x) + (pi.y-m.y)*(pi.y-m.y) < distance)
{
q = m;
r = pi;
distance = (pi.x-m.x)*(pi.x-m.x) + (pi.y-m.y)*(pi.y-m.y);
}
}
newpoints.add(pi);
}

distance = Math.hypot(q.x-r.x, q.y-r.y);
if(distance > 10000.0000 || Math.abs(distance - 10000.0000) < 1e-6)
System.out.println("INFINITY");
else
System.out.println(String.format("%.04f", distance));
}
}
}