Problem:
The Closest Circle
You are given
N
non-overlapping circles in xy-plane. The radius of each circle varies, but the radius of
the largest circle is not double longer than that of the smallest.
Figure 1: The Sample Input
The distance between two circles
C
1
and
C
2
is given by the usual formula
where (
x
i
,
y
i
) is the coordinates of the center of the circle
C
i
, and
r
i
is the radius of
C
i
, for
i
= 1, 2.
Your task is to write a program that finds the closest pair of circles and print their distance.
Input
The input consists of a series of test cases, followed by a single line only containing a single zero, which
indicates the end of input.
Each test case begins with a line containing an integer
N
(2 ≤
N
≤ 100000), which indicates the number
of circles in the test case.
N
lines describing the circles follow. Each of the
N
lines has three decimal
numbers
R
,
X
, and
Y
. R represents the radius of the circle.
X
and
Y
represent the
x
- and
y
-coordinates of
the center of the circle, respectively.
Output
For each test case, print the distance between the closest circles. You may print any number of digits
after the decimal point, but the error must not exceed 0.00001.
Sample Input
4
1.0 0.0 0.0
1.5 0.0 3.0
2.0 4.0 0.0
1.0 3.0 4.0
0
Output for the Sample Input
0.5

Submitted solutions:

code_snippet: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define ele int
using namespace std;
#define maxn 100010
#define INF 1e18
#define eps 1e-7
struct circle{
	double x,y,r;
};
ele n;
double R;
circle a[maxn];
inline bool cmp1(circle a,circle b){
	return a.x<b.x;
}
inline bool cmp2(circle a,circle b){
	return a.y<b.y;
}
inline double dis(circle a,circle b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))-a.r-b.r;
}
double solve(ele l,ele r){
	if (r-l+1<=2){
		double ans=INF;
		for (int i=l; i<=r; ++i)
			for (int j=i+1; j<=r; ++j)
				ans=min(ans,dis(a[i],a[j]));
		return ans;
	}
	ele mid=(l+r)>>1;
	double ans=min(solve(l,mid-1),solve(mid+1,r));
	for (int i=l; i<=r; ++i)
		if (i!=mid) ans=min(ans,dis(a[i],a[mid]));
	static circle p[maxn],q[maxn];
	ele u=0,v=0;
	for (int i=l; i<mid; ++i)
		if (a[mid].x-a[i].x<ans+R*2+eps) p[u++]=a[i];
	for (int i=mid+1; i<=r; ++i)
		if (a[i].x-a[mid].x<ans+R*2+eps) q[v++]=a[i];
	if (!v) return ans;
	sort(p,p+u,cmp2); sort(q,q+v,cmp2);
	ele s=0,t=0;
	for (int i=0; i<u; ++i){
		while (s<v-1 && p[i].y-q[s].y>ans+R*2+eps) ++s;
		while (t<v-1 && q[t+1].y-p[i].y<ans+R*2+eps) ++t;
		for (int j=s; j<=t; ++j) ans=min(ans,dis(p[i],q[j]));
	}
	return ans;
}
int main(){
	while (scanf("%d",&n),n){
		R=0;
		for (int i=0; i<n; ++i){
			scanf("%lf%lf%lf",&a[i].r,&a[i].x,&a[i].y);
			R=max(R,a[i].r);
		}
		sort(a,a+n,cmp1);
		printf("%.10lf\n",solve(0,n-1));
	}
	return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 9072
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
using namespace std;

int n;
const double INF = 1e9;
double pr, px, py;

struct circle {
	double r, x, y;

	bool operator < (const circle& rhs) const
	{
		return x < rhs.x || (x == rhs.x && y < rhs.y);
	}
};

circle a[100000];

bool compare_y(circle a, circle b) {
	return a.y < b.y;
}

double closest_pair(circle* a, int n) {
	if (n <= 1)
		return INF;

	int m = n / 2;
	double x = a[m].x, r = a[m].r;
	double d = min(closest_pair(a, m), closest_pair(a + m, n - m));
	inplace_merge(a, a + m, a + n, compare_y);

	vector<circle> b;

	for (int i = 0; i < n; i++) {
		if (fabs(a[i].x - x) >= d + r + a[i].r)
			continue;

		int w = b.size();

		for (int j = 0; j < w; j++) {
			double dx = a[i].x - b[w - j - 1].x;
			double dy = a[i].y - b[w - j - 1].y;

			if (dy >= d + r + a[i].r)
				break;

			d = min(d, sqrt(dx * dx + dy * dy) - a[i].r - b[w - j - 1].r);
		}

		b.push_back(a[i]);
	}

	return d;
}

int main()
{
	cin >> n;

	while (n) {
		for (int i = 0; i < n; i++) {
			cin >> pr >> px >> py;
			circle w = { pr, px, py };
			a[i] = w;
		}

		sort(a, a + n);

		cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(6)
			<< closest_pair(a, n) << endl;

		cin >> n;
	}

	return 0;
}
accuracy: 1
time_ms: 480
memory_kb: 10800
final_rank: 14

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

template<class T>
using vi = vector<T>;

template<class T>
using vii = vector<vi<T>>;

template<class T>
using viii = vector<vii<T>>;

struct point {
    double x, y, r;
};

const ll inf = 1e18;

void chmin(double& x, double y) { x = min(x, y); }

double dist(point& a, point& b) {
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) - a.r - b.r;
}

double closestpair(vi<point>& d, int l, int r, const double mxr) {
    if (r - l == 1) return inf;
    const int mid = (l + r) / 2;
    point m = d[mid];
    double vl = closestpair(d, l, mid, mxr);
    double vr = closestpair(d, mid, r, mxr);
    double ans = min(vl, vr);
    inplace_merge(d.begin() + l, d.begin() + mid, d.begin() + r, 
        [&](point a, point b) {return a.y < b.y; });

    vi<point> midreg;
    for (int i = l; i < r; i++) {
        if (abs(d[i].x - m.x) >= ans + mxr * 2) continue;
        int len = midreg.size();
        for (int j = len - 1; j >= 0; j--) {
            if (d[i].y - midreg[j].y >= ans + mxr * 2) break;
            chmin(ans, dist(d[i], midreg[j]));
        }
        midreg.push_back(d[i]);
    }
    return ans;
}

int main()
{
    int n;
    while (cin >> n, n) {
        vi<point> d(n);
        rep(i, n) cin >> d[i].r >> d[i].x >> d[i].y;
        double mxr = 0;
        rep(i, n) mxr = max(mxr, d[i].r);
        sort(d.begin(), d.end(), [&](point a, point b) {return a.x < b.x; });
        double res = closestpair(d, 0, n, mxr);
        cout << fixed << setprecision(12) << res << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 380
memory_kb: 11336
final_rank: 15

code_snippet: // #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vvl = vector<vector<ll>>;
using vvi = vector<vector<int>>;
using vvpll = vector<vector<pll>>;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define rrep(i, a, b) for (ll i=(a); i>(b); i--)
#define pb push_back
#define tostr to_string
#define ALL(A) A.begin(), A.end()
#define elif else if
// constexpr ll INF = LONG_LONG_MAX;
constexpr ll INF = 1e18;
constexpr ll MOD = 1000000007;

const string digits = "0123456789";
const string ascii_lowercase = "abcdefghijklmnopqrstuvwxyz";
const string ascii_uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string ascii_letters = ascii_lowercase + ascii_uppercase;

template<typename T> vector<vector<T>> list2d(int N, int M, T init) { return vector<vector<T>>(N, vector<T>(M, init)); }
template<typename T> vector<vector<vector<T>>> list3d(int N, int M, int L, T init) { return vector<vector<vector<T>>>(N, vector<vector<T>>(M, vector<T>(L, init))); }
template<typename T> vector<vector<vector<vector<T>>>> list4d(int N, int M, int L, int O, T init) { return vector<vector<vector<vector<T>>>>(N, vector<vector<vector<T>>>(M, vector<vector<T>>(L, vector<T>(O, init)))); }

vector<ll> LIST(ll N) { vector<ll> A(N); rep(i, 0, N) cin >> A[i]; return A; }

void print(ld out) { cout << fixed << setprecision(15) << out << '\n'; }
void print(double out) { cout << fixed << setprecision(15) << out << '\n'; }
template<typename T> void print(T out) { cout << out << '\n'; }
template<typename T1, typename T2> void print(pair<T1, T2> out) { cout << out.first << ' ' << out.second << '\n'; }
template<typename T> void print(vector<T> A) { rep(i, 0, A.size()) { cout << A[i]; cout << (i == A.size()-1 ? '\n' : ' '); } }
template<typename T> void print(set<T> S) { vector<T> A(S.begin(), S.end()); print(A); }

void Yes() { print("Yes"); }
void No() { print("No"); }
void YES() { print("YES"); }
void NO() { print("NO"); }

ll floor(ll a, ll b) { if (a < 0) { return (a-b+1) / b; } else { return a / b; } }
ll ceil(ll a, ll b) { if (a >= 0) { return (a+b-1) / b; } else { return a / b; } }
pll divmod(ll a, ll b) { ll d = a / b; ll m = a % b; return {d, m}; }
template<typename T> bool chmax(T &x, T y) { return (y > x) ? x = y, true : false; }
template<typename T> bool chmin(T &x, T y) { return (y < x) ? x = y, true : false; }

template<typename T> T sum(vector<T> A) { T res = 0; for (T a: A) res += a; return res; }
template<typename T> T max(vector<T> A) { return *max_element(ALL(A)); }
template<typename T> T min(vector<T> A) { return *min_element(ALL(A)); }

ll toint(string s) { ll res = 0; for (char c : s) { res *= 10; res += (c - '0'); } return res; }
int toint(char num) { return num - '0'; }
char tochar(int num) { return '0' + num; }
int ord(char c) { return (int)c; }
char chr(int a) { return (char)a; }

ll pow(ll x, ll n) { ll res = 1; rep(_, 0, n) res *= x; return res; }
ll pow(ll x, ll n, int mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; }

int popcount(ll S) { return __builtin_popcountll(S); }
ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll x, ll y) { return (x * y) / gcd(x, y); }

template<typename T> int bisect_left(vector<T> &A, T val) { return lower_bound(ALL(A), val) - A.begin(); }
template<typename T> int bisect_right(vector<T> &A, T val) { return upper_bound(ALL(A), val) - A.begin(); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    while (1) {
        ll N;
        cin >> N;
        if (N == 0) break;

        vector<tuple<ld, ld, ld>> XY;
        rep(i, 0, N) {
            ld x, y, r;
            cin >> r >> x >> y;
            XY.pb({x, y, r});
        }
        sort(ALL(XY));

        auto rec = [&](auto&& f, vector<tuple<ld, ld, ld>> XY) -> ld {
            ll n = XY.size();
            if (n <= 1) return INF;
            ll m = n/2;
            ld l = get<0>(XY[m]);
            ld d = min(f(f, vector<tuple<ld, ld, ld>>(XY.begin(), XY.begin()+m)), 
                    f(f, vector<tuple<ld, ld, ld>>(XY.begin()+m, XY.end())));

            sort(ALL(XY), [](tuple<ld, ld, ld> a, tuple<ld, ld, ld> b) { return get<1>(a) < get<1>(b); });
            ld mxr = 0;
            for (auto& [x, y, r] : XY) chmax(mxr, r);
            rep(i, 0, n) {
                auto [x1, y1, r1] = XY[i];
                if (abs(l-x1)-mxr*2 >= d) continue;
                rep(j, i+1, n) {
                    auto [x2, y2, r2] = XY[j];
                    if (abs(y1-y2)-mxr*2 >= d) break;
                    chmin(d, sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))-r1-r2);
                }
            }
            return d;
        };
        ld ans = rec(rec, XY);
        print(ans);
    }
    return 0;
}
accuracy: 1
time_ms: 420
memory_kb: 22224
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define EPS 1e-10
typedef pair<double,int> P;
struct Point{double x,y,r;};
int n;
Point p[100010];

double cl(int i,int j,double k=0.0){
  return sqrt(pow(p[i].x-p[j].x,2)+pow(p[i].y-p[j].y,2))-(p[i].r+p[j].r+k*2.0);
}

int solve(double k){
  
  vector<P> events;
  
  for(int i=0;i<n;i++){
    double x1=p[i].x-p[i].r-k;
    double x2=p[i].x+p[i].r+k;
    events.push_back(P(x1,i));
    events.push_back(P(x2,i+n));
  }
  sort(events.begin(),events.end());

  set<P> outers;
  for(int i=0;i<events.size();i++){
    int id=events[i].second%n;
    if(events[i].second<n){
      set<P>::iterator it = outers.lower_bound(P(p[id].y,id));
      if(it!=outers.end()&&cl(id,it->second,k)<=0)return 0;
      if(it!=outers.begin()&&cl(id,(--it)->second,k)<=0)return 0;
      outers.insert(P(p[id].y,id));
    }else{
      outers.erase(P(p[id].y,id));
    }
  }
  return 1;
}

int main(){
  
  while(cin>>n,n){

    for(int i=0;i<n;i++){
      cin>>p[i].r>>p[i].x>>p[i].y;
    }

    double ok=0,ng=cl(0,1),mid;
    while(ng-ok>EPS){
      mid=(ok+ng)/2.0;
      if(solve(mid))ok=mid;
      else ng=mid;
    }
  
    printf("%.10lf\n",ok*2.0);
  }
  return 0;
}
accuracy: 1
time_ms: 2980
memory_kb: 14704
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e18;
typedef complex<double> P;
#define X real()
#define Y imag()
struct C{
    P p;
    double r;
    C(const P& p, const double& r) : p(p), r(r) {}
    C(){}
};
bool xcomp(const C &a, const C &b){
    return (a.p.X != b.p.X)? a.p.X<b.p.X : a.p.Y<b.p.Y;
}
bool ycomp(const C &a, const C &b){
    return (a.p.Y != b.p.Y)? a.p.Y<b.p.Y : a.p.X<b.p.X;
}

double closest(vector<C> &c, int first, int last, double rmax){
    if(last -first <= 1) return INF;
    int mid = (first +last)/2;
    double midx = c[mid].p.X;
    double d = min(closest(c, first, mid, rmax), closest(c, mid, last, rmax));
    inplace_merge(c.begin()+first, c.begin()+mid, c.begin()+last, ycomp);

    vector<C> near;
    for(int i=first; i<last; i++){
        if(abs(c[i].p.X -midx) -c[i].r -rmax > d +EPS) continue;
        for(int j=near.size()-1; j>=0; j--){
            if(abs(c[i].p.Y -near[j].p.Y) -c[i].r -rmax > d +EPS){
                break;
            }
            d = min(d, abs(c[i].p -near[j].p) -c[i].r -near[j].r);
        }
        near.push_back(c[i]);
    }
    return d;
}
 
int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        vector<C> c(n);
        double rmax = 0;
        for(int i=0; i<n; i++){
            double r,x,y;
            cin >> r >> x >> y;
            c[i] = C(P(x, y), r);
            rmax = max(rmax, r);
        }
        sort(c.begin(), c.end(), xcomp);

        cout << fixed << setprecision(10);
        cout << closest(c, 0, n, rmax) << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 500
memory_kb: 10736
final_rank: 13

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	bool operator<(const struct Info &arg) const{
		if(x != arg.x){
			return x < arg.x;
		}else{
			return y < arg.y;
		}
	}
	double x,y,r;
};

int N;
Info info[100001];

bool compare_y(Info left,Info right){

	return left.y < right.y;

}

double calc_dist(int a,int b){
	return sqrt((info[a].x-info[b].x)*(info[a].x-info[b].x)+(info[a].y-info[b].y)*(info[a].y-info[b].y))-(info[a].r+info[b].r);
}

double calc_y_dist(int a,int b){
	return (info[b].y-info[b].r)-(info[a].y+info[a].r);
}

double closest_pair(Info* array,int tmp_N){
	if(tmp_N <= 1)return DBL_MAX;

	int mid = tmp_N/2;

	double x = array[mid].x;
	double dist = min(closest_pair(array,mid),closest_pair(array+mid,tmp_N-mid));
	inplace_merge(array,array+mid,array+tmp_N,compare_y);

	vector<int> V;


	int left,right,m,search_left;

	for(int i = 0; i < tmp_N; i++){

		for(int k = 0; k < min((int)V.size(),2); k++){
			dist = min(dist,calc_dist(V[V.size()-1-k],i));
		}

		V.push_back(i);
	}
	return dist;
}

void func(){

	for(int i = 0; i < N; i++){
		scanf("%lf %lf %lf",&info[i].r,&info[i].x,&info[i].y);
	}
	sort(info,info+N);

	printf("%.10lf\n",closest_pair(info,N));
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 6924
final_rank: 5

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	bool operator<(const struct Info &arg) const{
		if(x != arg.x){
			return x < arg.x;
		}else{
			return y < arg.y;
		}
	}
	double x,y,r;
};

int N;
Info info[100001];

bool compare_y(Info left,Info right){ //順序付け関数

	return left.y < right.y;

}

bool is_OK(int index,double x,double dist){
	if(info[index].x < x){ //基準線より中心が左
		if(info[index].x+info[index].r+dist < x){
			return false;
		}

	}else{ //基準線より中心が右
		if(info[index].x-info[index].r-dist > x){
			return false;
		}
	}

	return true;
}

double calc_dist(int a,int b){
	return sqrt((info[a].x-info[b].x)*(info[a].x-info[b].x)+(info[a].y-info[b].y)*(info[a].y-info[b].y))-(info[a].r+info[b].r);
}

double calc_y_dist(int a,int b){
	return (info[b].y-info[b].r)-(info[a].y+info[a].r);
}

double closest_pair(Info* array,int tmp_N){
	if(tmp_N <= 1)return DBL_MAX;

	int mid = tmp_N/2; //中央のインデックス

	double x = array[mid].x; //基準線x
	double dist = min(closest_pair(array,mid),closest_pair(array+mid,tmp_N-mid)); //集合を2分割し、再帰的に最小距離を求める
	inplace_merge(array,array+mid,array+tmp_N,compare_y); //2つのソート済の範囲をマージ

	vector<int> V; //★★再帰毎にメモリを確保(indexをpush)★★


	int left,right,m,search_left;

	for(int i = 0; i < tmp_N; i++){
		//if(!is_OK(i,x,dist))continue; //基準線より最小距離以上離れている点は無視(★異なる領域間での、新最小値を作り得ないということ★)

		//★★Vはyの昇順に並んでいる:自分よりy座標が小さいもののみ、入っている★★

		//2分探索で、検索範囲を定める
		/*left = 0,right = V.size()-1,m = (left+right)/2;
		search_left = 0;

		while(left <= right){
			if(calc_y_dist(V[m],i) < dist){ //y座標の差がdist未満
				search_left = m;
				right = m-1; //より左へ
			}else{
				left = m+1; //より右へ
			}
			m = (left+right)/2;
		}*/

		/*for(int k = search_left; k < V.size(); k++){
			dist = min(dist,calc_dist(V[k],i));
		}*/

		for(int k = 0; k < min((int)V.size(),2); k++){
			dist = min(dist,calc_dist(V[V.size()-1-k],i));
		}

		V.push_back(i); //可能性あり集合に、iを追加
	}
	return dist;
}

void func(){

	for(int i = 0; i < N; i++){
		scanf("%lf %lf %lf",&info[i].r,&info[i].x,&info[i].y);
	}
	sort(info,info+N);

	printf("%.10lf\n",closest_pair(info,N));
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 6936
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;


#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define PI 3.141592653589793238
 
// COUNTER CLOCKWISE
static const int CCW_COUNTER_CLOCKWISE = 1;
static const int CCW_CLOCKWISE = -1;
static const int CCW_ONLINE_BACK = 2;
static const int CCW_ONLINE_FRONT = -2;
static const int CCW_ON_SEGMENT = 0;

//Intercsect Circle & Circle
static const int ICC_SEPERATE = 4;
static const int ICC_CIRCUMSCRIBE = 3;
static const int ICC_INTERSECT = 2;
static const int ICC_INSCRIBE = 1;
static const int ICC_CONTAIN = 0;

struct Point{
  double x,y;
  Point(){}
  Point(double x,double y) :x(x),y(y){}
  Point operator+(Point p) {return Point(x+p.x,y+p.y);}
  Point operator-(Point p) {return Point(x-p.x,y-p.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}
  double norm(){return x*x+y*y;}
  double abs(){return sqrt(norm());}

  bool operator < (const Point &p) const{
    return x!=p.x?x<p.x:y<p.y;
    //grid-point only
    //return !equals(x,p.x)?x<p.x:!equals(y,p.y)?y<p.y:0;
  }

  bool operator == (const Point &p) const{
    return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
  }
};

istream &operator >> (istream &is,Point &p){
  is>>p.x>>p.y;
  return is;
}

ostream &operator << (ostream &os,Point p){
  os<<fixed<<setprecision(12)<<p.x<<" "<<p.y;
  return os;
}

bool sort_x(Point a,Point b){
  return a.x!=b.x?a.x<b.x:a.y<b.y;
}

bool sort_y(Point a,Point b){
  return a.y!=b.y?a.y<b.y:a.x<b.x;
}

typedef Point Vector;
typedef vector<Point> Polygon;

istream &operator >> (istream &is,Polygon &p){
  for(int i=0;i<(int)p.size();i++) cin>>p[i];
  return is;
}

struct Segment{
  Point p1,p2;
  Segment(){}
  Segment(Point p1, Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

istream &operator >> (istream &is,Segment &s){
  is>>s.p1>>s.p2;
  return is;
}

struct Circle{
  Point c;
  double r;
  Circle(){}
  Circle(Point c,double r):c(c),r(r){}
};

istream &operator >> (istream &is,Circle &c){
  is>>c.c>>c.r;
  return is;
}

double norm(Vector a){
  return a.x*a.x+a.y*a.y;
}
double abs(Vector a){
  return sqrt(norm(a));
}
double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}

bool isOrthogonal(Vector a,Vector b){
  return equals(dot(a,b),0.0);
}

bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
  return isOrthogonal(a1-a2,b1-b2);
}

bool isOrthogonal(Segment s1,Segment s2){
  return equals(dot(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}

bool isParallel(Vector a,Vector b){
  return equals(cross(a,b),0.0);
}

bool isParallel(Point a1,Point a2,Point b1,Point b2){
  return isParallel(a1-a2,b1-b2);
}

bool isParallel(Segment s1,Segment s2){
  return equals(cross(s1.p2-s1.p1,s2.p2-s2.p1),0.0); 
}

Point project(Segment s,Point p){
  Vector base=s.p2-s.p1;
  double r=dot(p-s.p1,base)/norm(base);
  return s.p1+base*r;
}

Point reflect(Segment s,Point p){
  return p+(project(s,p)-p)*2.0;
}

double arg(Vector p){
  return atan2(p.y,p.x);
}

Vector polar(double a,double r){
  return Point(cos(r)*a,sin(r)*a);
}

int ccw(Point p0,Point p1,Point p2);
bool intersectSS(Point p1,Point p2,Point p3,Point p4);
bool intersectSS(Segment s1,Segment s2);
bool intersectPS(Polygon p,Segment l);
int intersectCC(Circle c1,Circle c2);
bool intersectSC(Segment s,Circle c);
double getDistanceLP(Line l,Point p);
double getDistanceSP(Segment s,Point p);
double getDistanceSS(Segment s1,Segment s2);
Point getCrossPointSS(Segment s1,Segment s2);
Point getCrossPointLL(Line l1,Line l2);
Polygon getCrossPointCL(Circle c,Line l);
Polygon getCrossPointCC(Circle c1,Circle c2);
int contains(Polygon g,Point p);
Polygon andrewScan(Polygon s);
Polygon convex_hull(Polygon ps);
double diameter(Polygon s);
bool isConvex(Polygon p);
double area(Polygon s);
Polygon convexCut(Polygon p,Line l);
Line bisector(Point p1,Point p2);
Vector translate(Vector v,double theta);
vector<Line> corner(Line l1,Line l2);

int ccw(Point p0,Point p1,Point p2){
  Vector a = p1-p0;
  Vector b = p2-p0;
  if(cross(a,b) > EPS) return CCW_COUNTER_CLOCKWISE;
  if(cross(a,b) < -EPS) return CCW_CLOCKWISE;
  if(dot(a,b) < -EPS) return CCW_ONLINE_BACK;
  if(a.norm()<b.norm()) return CCW_ONLINE_FRONT;
  return CCW_ON_SEGMENT;
}

bool intersectSS(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4) <= 0 &&
	  ccw(p3,p4,p1)*ccw(p3,p4,p2) <= 0 );
}

bool intersectSS(Segment s1,Segment s2){
  return intersectSS(s1.p1,s1.p2,s2.p1,s2.p2);
}

bool intersectPS(Polygon p,Segment l){
  int n=p.size();
  for(int i=0;i<n;i++)
    if(intersectSS(Segment(p[i],p[(i+1)%n]),l)) return 1;
  return 0;
}

int intersectCC(Circle c1,Circle c2){
  if(c1.r<c2.r) swap(c1,c2);
  double d=abs(c1.c-c2.c);
  double r=c1.r+c2.r;
  if(equals(d,r)) return ICC_CIRCUMSCRIBE;
  if(d>r) return ICC_SEPERATE;
  if(equals(d+c2.r,c1.r)) return ICC_INSCRIBE;
  if(d+c2.r<c1.r) return ICC_CONTAIN;
  return ICC_INTERSECT;
}

bool intersectSC(Segment s,Circle c){
  double d=getDistanceSP(s,c.c);
  return d<=c.r;
}

double getDistanceLP(Line l,Point p){
  return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}

double getDistanceSP(Segment s,Point p){
  if(dot(s.p2-s.p1,p-s.p1) < 0.0 ) return abs(p-s.p1);
  if(dot(s.p1-s.p2,p-s.p2) < 0.0 ) return abs(p-s.p2);
  return getDistanceLP(s,p);
}

double getDistanceSS(Segment s1,Segment s2){
  if(intersectSS(s1,s2)) return 0.0;
  return min(min(getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2)),
	     min(getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)));
}

Point getCrossPointSS(Segment s1,Segment s2){
  Vector base=s2.p2-s2.p1;
  double d1=abs(cross(base,s1.p1-s2.p1));
  double d2=abs(cross(base,s1.p2-s2.p1));
  double t=d1/(d1+d2);
  return s1.p1+(s1.p2-s1.p1)*t;
}

Point getCrossPointLL(Line l1,Line l2){
  double a=cross(l1.p2-l1.p1,l2.p2-l2.p1);
  double b=cross(l1.p2-l1.p1,l1.p2-l2.p1);
  if(abs(a)<EPS&&abs(b)<EPS) return l2.p1;
  return l2.p1+(l2.p2-l2.p1)*(b/a);
}

Polygon getCrossPointCL(Circle c,Line l){
  Polygon p(2);
  Vector pr=project(l,c.c);
  Vector e=(l.p2-l.p1)/abs(l.p2-l.p1);
  double base=sqrt(c.r*c.r-norm(pr-c.c));
  p[0]=pr+e*base;
  p[1]=pr-e*base;
  return p;
}

Polygon getCrossPointCC(Circle c1,Circle c2){
  Polygon p(2);
  double d=abs(c1.c-c2.c);
  double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
  double t=arg(c2.c-c1.c);
  p[0]=c1.c+polar(c1.r,t+a);
  p[1]=c1.c+polar(c1.r,t-a);
  return p;
}

// IN:2 ON:1 OUT:0
int contains(Polygon g,Point p){
  int n=g.size();
  bool x=false;
  for(int i=0;i<n;i++){
    Point a=g[i]-p,b=g[(i+1)%n]-p;
    if(fabs(cross(a,b)) < EPS && dot(a,b) < EPS) return 1;
    if(a.y>b.y) swap(a,b);
    if(a.y < EPS && EPS < b.y && cross(a,b) > EPS ) x = !x;
  }
  return (x?2:0);
}

Polygon andrewScan(Polygon s){
  Polygon u,l;
  if(s.size()<3) return s;
  sort(s.begin(),s.end());
  u.push_back(s[0]);
  u.push_back(s[1]);
  l.push_back(s[s.size()-1]);
  l.push_back(s[s.size()-2]);
  for(int i=2;i<(int)s.size();i++){
    for(int n=u.size();n>=2&&ccw(u[n-2],u[n-1],s[i])!=CCW_CLOCKWISE;n--){
      u.pop_back();
    }
    u.push_back(s[i]);
  } 
  for(int i=s.size()-3;i>=0;i--){
    for(int n=l.size();n>=2&&ccw(l[n-2],l[n-1],s[i])!=CCW_CLOCKWISE;n--){
      l.pop_back();
    }
    l.push_back(s[i]);
  }
  reverse(l.begin(),l.end());
  for(int i=u.size()-2;i>=1;i--) l.push_back(u[i]);
  return l;
} 

Polygon convex_hull(Polygon ps){
  int n=ps.size();
  sort(ps.begin(),ps.end(),sort_y);
  int k=0;
  Polygon qs(n*2);
  for(int i=0;i<n;i++){
    while(k>1&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0) k--;
    qs[k++]=ps[i];
  }
  for(int i=n-2,t=k;i>=0;i--){
    while(k>t&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0) k--;
    qs[k++]=ps[i];
  }
  qs.resize(k-1);
  return qs;
}

double diameter(Polygon s){
  Polygon p=s;
  int n=p.size();
  if(n==2) return abs(p[0]-p[1]);
  int i=0,j=0;
  for(int k=0;k<n;k++){
    if(p[i]<p[k]) i=k;
    if(!(p[j]<p[k])) j=k;
  }
  double res=0;
  int si=i,sj=j;
  while(i!=sj||j!=si){
    res=max(res,abs(p[i]-p[j]));
    if(cross(p[(i+1)%n]-p[i],p[(j+1)%n]-p[j])<0.0){
      i=(i+1)%n;
    }else{
      j=(j+1)%n;
    }
  }
  return res;
}

bool isConvex(Polygon p){
  bool f=1;
  int n=p.size();
  for(int i=0;i<n;i++){
    int t=ccw(p[(i+n-1)%n],p[i],p[(i+1)%n]);
    f&=t!=CCW_CLOCKWISE;
  }
  return f;
}

double area(Polygon s){
  double res=0;
  for(int i=0;i<(int)s.size();i++){
    res+=cross(s[i],s[(i+1)%s.size()])/2.0;
  }
  return abs(res);
}

double area(Circle c1,Circle c2){
  double d=abs(c1.c-c2.c);
  if(c1.r+c2.r<=d+EPS) return 0;
  if(d<=abs(c1.r-c2.r)){
    double r=min(c1.r,c2.r);
    return PI*r*r;
  }
  double rc=(d*d+c1.r*c1.r-c2.r*c2.r)/(2*d);
  double th=acos(rc/c1.r);
  double ph=acos((d-rc)/c2.r);
  return c1.r*c1.r*th+c2.r*c2.r*ph-d*c1.r*sin(th);
}

Polygon convexCut(Polygon p,Line l){
  Polygon q;
  for(int i=0;i<(int)p.size();i++){
    Point a=p[i],b=p[(i+1)%p.size()];
    if(ccw(l.p1,l.p2,a)!=-1) q.push_back(a);
    if(ccw(l.p1,l.p2,a)*ccw(l.p1,l.p2,b)<0)
      q.push_back(getCrossPointLL(Line(a,b),l));
  }
  return q;
}

Line bisector(Point p1,Point p2){
  Circle c1=Circle(p1,abs(p1-p2)),c2=Circle(p2,abs(p1-p2));
  Polygon p=getCrossPointCC(c1,c2);
  if(cross(p2-p1,p[0]-p1)>0) swap(p[0],p[1]);
  return Line(p[0],p[1]);
}

Vector translate(Vector v,double theta){
  Vector res;
  res.x=cos(theta)*v.x-sin(theta)*v.y;
  res.y=sin(theta)*v.x+cos(theta)*v.y;
  return res;
}

vector<Line> corner(Line l1,Line l2){
  vector<Line> res;
  if(isParallel(l1,l2)){
    double d=getDistanceLP(l1,l2.p1)/2.0;
    Vector v1=l1.p2-l1.p1;
    v1=v1/v1.abs()*d;
    Point p=l2.p1+translate(v1,90.0*(PI/180.0));
    double d1=getDistanceLP(l1,p);
    double d2=getDistanceLP(l2,p);
    if(abs(d1-d2)>d){
      p=l2.p1+translate(v1,-90.0*(PI/180.0));
    }
    res.push_back(Line(p,p+v1));
  }else{
    Point p=getCrossPointLL(l1,l2);
    Vector v1=l1.p2-l1.p1,v2=l2.p2-l2.p1;
    v1=v1/v1.abs();
    v2=v2/v2.abs();
    res.push_back(Line(p,p+(v1+v2)));
    res.push_back(Line(p,p+translate(v1+v2,90.0*(PI/180.0))));
  }
  return res;
}

Polygon tangent(Circle c1,Point p2){
  Circle c2=Circle(p2,sqrt(norm(c1.c-p2)-c1.r*c1.r));
  Polygon p=getCrossPointCC(c1,c2);
  sort(p.begin(),p.end());
  return p;
}


template<typename T>
void chmin(T &a,T b){if(a>b) a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b) a=b;}


signed main(){
  int n;
  while(cin>>n,n){
    vector<Circle> v(n);
    for(int i=0;i<n;i++) cin>>v[i].r>>v[i].c;
    auto calc=[](Circle a,Circle b){
      return abs(a.c-b.c)-(a.r+b.r);
    };
    double ans=calc(v[0],v[1]);
    for(int k=0;k<10;k++){
      sort(v.begin(),v.end(),[](Circle a,Circle b){return sort_x(a.c,b.c);});
      for(int i=0;i<n-1;i++) chmin(ans,calc(v[i],v[i+1]));
      sort(v.begin(),v.end(),[](Circle a,Circle b){return sort_y(a.c,b.c);});
      for(int i=0;i<n-1;i++) chmin(ans,calc(v[i],v[i+1]));
      for(int i=0;i<n;i++) v[i].c=translate(v[i].c,PI/100);
    }
    cout<<fixed<<setprecision(12)<<ans<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 690
memory_kb: 5708
final_rank: 7

code_snippet: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
 
typedef pair<double,double> P;
typedef pair<P,double> P2;
 
P rot(P p, double a){
  a=a*M_PI/180.0;
  return P(p.first*cos(a)+p.second*(-sin(a)),
  p.first*sin(a)+p.second*cos(a));
}
 
double abss(P a,P b){
  return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
}
 
double x,y,r;int tt;
vector<P2>v;
int main(){
 
  int n;
  while(cin >> n,n){
 
    double ans=1e13;
     
    v.clear();
   
    r(i,n){
      cin>>r>>x>>y;
      v.push_back(P2(P(x,y),r));
    }
 
    r(i,1){
      sort(v.begin(),v.end());
      r(j,n){
    for(int k=j+1,c=0;k<n;k++,c++){
      if(c>50)break;
      ans=min(ans,abss(v[k].first,v[j].first)-v[k].second-v[j].second);
    }
      }
      r(j,n)v[i].first=rot(v[i].first,0.5);
    }
 
    printf("%.9f\n",ans);
     
  }
   
  return 0;
}
accuracy: 1
time_ms: 460
memory_kb: 6220
final_rank: 4

code_snippet: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef pair<double,double> P;
typedef pair<P,double> P2;

P rot(P p, double a){
  a=a*M_PI/180.0;
  return P(p.first*cos(a)+p.second*(-sin(a)),
  p.first*sin(a)+p.second*cos(a));
}

double abss(P a,P b){
  return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
}

double x,y,r;int tt;
vector<P2>v;
int main(){

  int n;
  while(cin >> n,n){

    double ans=1e13;
    
    v.clear();
  
    r(i,n){
      cin>>r>>x>>y;
      v.push_back(P2(P(x,y),r));
    }

    r(i,1){
      sort(v.begin(),v.end());
      r(j,n){
	for(int k=j+1,c=0;k<n;k++,c++){
	  if(c>50)break;
	  ans=min(ans,abss(v[k].first,v[j].first)-v[k].second-v[j].second);
	}
      }
      r(j,n)v[i].first=rot(v[i].first,0.5);
    }

    printf("%.9f\n",ans);
    
  }
  
  return 0;
}
accuracy: 1
time_ms: 460
memory_kb: 6212
final_rank: 3

code_snippet: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define ele int
using namespace std;
#define maxn 100010
#define INF 1e18
#define eps 1e-7
struct circle{
	double x,y,r;
};
ele n;
double R;
circle a[maxn];
inline bool cmp1(circle a,circle b){
	return a.x<b.x;
}
inline bool cmp2(circle a,circle b){
	return a.y<b.y;
}
inline double dis(circle a,circle b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))-a.r-b.r;
}
double solve(ele l,ele r){
	if (r-l+1<=10){
		double ans=INF;
		for (int i=l; i<=r; ++i)
			for (int j=i+1; j<=r; ++j)
				ans=min(ans,dis(a[i],a[j]));
		return ans;
	}
	ele mid=(l+r)>>1;
	double ans=min(solve(l,mid-1),solve(mid+1,r));
	for (int i=l; i<=r; ++i)
		if (i!=mid) ans=min(ans,dis(a[i],a[mid]));
	static circle p[maxn],q[maxn];
	ele u=0,v=0;
	for (int i=l; i<mid; ++i)
		if (a[mid].x-a[i].x<ans+R*2+eps) p[u++]=a[i];
	for (int i=mid+1; i<=r; ++i)
		if (a[i].x-a[mid].x<ans+R*2+eps) q[v++]=a[i];
	if (!v) return ans;
	sort(p,p+u,cmp2); sort(q,q+v,cmp2);
	ele s=0,t=0;
	for (int i=0; i<u; ++i){
		while (s<v-1 && p[i].y-q[s].y>ans+R*2+eps) ++s;
		while (t<v-1 && q[t+1].y-p[i].y<ans+R*2+eps) ++t;
		for (int j=s; j<=t; ++j) ans=min(ans,dis(p[i],q[j]));
	}
	return ans;
}
int main(){
	while (scanf("%d",&n),n){
		R=0;
		for (int i=0; i<n; ++i){
			scanf("%lf%lf%lf",&a[i].r,&a[i].x,&a[i].y);
			R=max(R,a[i].r);
		}
		sort(a,a+n,cmp1);
		printf("%.10lf\n",solve(0,n-1));
	}
	return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 7312
final_rank: 8

code_snippet: #include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
struct circle { double x, y, r; };
int n; circle x[100009];
bool operator<(const circle& c1, const circle& c2) {
	return c1.x - c1.r < c2.x - c2.r;
}
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			scanf("%lf%lf%lf", &x[i].r, &x[i].x, &x[i].y);
			double ex = x[i].x * 0.28 - x[i].y * 0.96;
			double ey = x[i].x * 0.96 + x[i].y * 0.28;
			x[i].x = ex, x[i].y = ey;
		}
		sort(x, x + n);
		double ret = 1.0e+9;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (x[i].x + x[i].r + ret < x[j].x - x[j].r) break;
				double dist = hypot(x[i].x - x[j].x, x[i].y - x[j].y) - x[i].r - x[j].r;
				ret = min(ret, dist);
			}
		}
		printf("%.15lf\n", ret);
	}
	return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 5628
final_rank: 2

code_snippet: /*include*/
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#include<complex>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
const double PI=acos(-1);
const double EPS=1e-10;
const double inf=1e8;
using namespace std;
#define shosu(x) fixed<<setprecision(x)
typedef complex<double> P;
typedef vector<P> G;
typedef vector<int> vi;
typedef vector<vi> vvi;

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
struct C{
	P c;double r;
	C(const P &c,double r):c(c),r(r){}
};
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
#define diff(P, i) (next(P, i) - curr(P, i))
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
		//return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);  
	}
	bool operator == (const P& a, const P& b) {
		return a.real()==b.real()&&a.imag()==b.imag();
	}
}
P pin(){
	double x,y;
	char d;
	cin>>x>>y;
	P p(x,y);
	return p;
}
void PIN(P* a,int n){
	rep(i,n)a[i]=pin();
}
double dot(P a,P b){
	return real(conj(a)*b);
}
double cross(P a,P b){
	return imag(conj(a)*b);
}
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
P projection(L a,P p){
	double t=dot(p-a[0],a[0]-a[1])/norm(a[0]-a[1]);
	return a[0]+t*(a[0]-a[1]);
}
P reflection(L a,P p){
	return p+2.0*(projection(a,p)-p);
}
bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}
double distanceLP(const L &l, const P &p) {
	return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
  return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
  if (intersectLS(l, s)) return 0;
  return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
/*bool intersectCS(C c,const L &l){
    return (distanceLP(l,c.c) < c.r+EPS &&
            (c.r < abs(c.c-l[0]) + EPS || c.r < abs(c.c-l[1]) + EPS));
}*/
int intersectCS(C c,L &l){
	if(norm(projection(l,c.c)-c.c)-c.r*c.r>EPS)return 0;
	const double d1=abs(c.c-l[0]),d2=abs(c.c-l[1]);
	if(d1<c.r+EPS&&d2<c.r+EPS)return 0;
	if(d1<c.r-EPS&&d2>c.r+EPS||d1>c.r+EPS&&d2<c.r-EPS)return 1;
	const P h=projection(l,c.c);
	if(dot(l[0]-h,l[1]-h)<0)return 2;
	return 0;
}
P crosspointSS(L a,L b){
	double t1=abs(cross(a[1]-a[0],b[0]-a[0]));
	double t2=abs(cross(a[1]-a[0],b[1]-a[0]));
	return b[0]+(b[1]-b[0])*t1/(t1+t2);
}
L crosspointCL(C c,L l){
	P pr=projection(l,c.c);
	P e=(l[1]-l[0])/abs(l[1]-l[0]);
	double t=sqrt(c.r*c.r-norm(pr-c.c));
	P a=pr+t*e;
	P b=pr-t*e;
	if(b<a)swap(a,b);
	return L(a,b);
}
L crosspointCS(C c,L l){
	if(intersectCS(c,l)==2)return crosspointCL(c,l);
	L ret=crosspointCL(c,l);
	if(dot(l[0]-ret[0],l[1]-ret[0])<0)ret[1]=ret[0];
	else ret[0]=ret[1];
	return ret;
}
L crosspointCC(C a,C b){
	P tmp=b.c-a.c;
	double d=abs(tmp);
	double q=acos((a.r*a.r+d*d-b.r*b.r)/(2*a.r*d));
	double t=arg(tmp);//atan(tmp.imag()/tmp.real());
	P p1=a.c+polar(a.r,t+q);
	P p2=a.c+polar(a.r,t-q);
	if(p2<p1)swap(p1,p2);
	return L(p1,p2);
}
P crosspointLL(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  return m[0] + B / A * (m[1] - m[0]);
}
double area(const G &g){
    double S =0;
    for(int i =0;i <g.size();i++){
        S +=(cross(g[i],g[(i+1)%g.size()]));
    }
    return abs(S/2.0);
}
bool isconvex(const G &g){
	int n=g.size();
	rep(i,n)if(ccw(g[(i+n-1)%n],g[i%n],g[(i+1)%n])==-1)return false;
	return true;
}
int inconvex(const G& g, const P& p) {
	bool in = false;
	int n=g.size();
	rep(i,n){
		P a=g[i%n]-p;
		P b=g[(i+1)%n]-p;
		if(imag(a)>imag(b))swap(a, b);
		if(imag(a)<=0&&0<imag(b))if(cross(a,b)<0)in=!in;
		if(cross(a,b)==0&&dot(a,b)<=0)return 1;//ON
	}
	return in?2:0;//IN : OUT;
}
G convex_hull(G &ps) {
    int n=ps.size(),k=0;
	sort(ps.begin(), ps.end());
	G ch(2*n);
	for(int i=0;i<n;ch[k++]=ps[i++])//lower-hull
		while(k>=2&&ccw(ch[k-2],ch[k-1],ps[i])==-1)--k;//<=0  ->  ==-1
	for(int i=n-2,t=k+1;i>=0;ch[k++]=ps[i--])//upper-hull
		while(k>=t&&ccw(ch[k-2],ch[k-1],ps[i])==-1)--k;//
	ch.resize(k-1);
	return ch;
}
double convex_diameter(const G &pt) {
  const int n = pt.size();
  int is = 0, js = 0;
  for (int i = 1; i < n; ++i) {
    if (imag(pt[i]) > imag(pt[is])) is = i;
    if (imag(pt[i]) < imag(pt[js])) js = i;
  }
  double maxd = norm(pt[is]-pt[js]);

  int i, maxi, j, maxj;
  i = maxi = is;
  j = maxj = js;
  do {
    if (cross(diff(pt,i), diff(pt,j)) >= 0) j = (j+1) % n;
    else i = (i+1) % n;
    if (norm(pt[i]-pt[j]) > maxd) {
      maxd = norm(pt[i]-pt[j]);
      maxi = i; maxj = j;
    }
  } while (i != is || j != js);
  return sqrt(maxd); /* farthest pair is (maxi, maxj). */
}//convex_diameter(g)
G convex_cut(const G& g, const L& l) {
  G Q;
  for (int i = 0; i < g.size(); ++i) {
    P a= curr(g, i), b= next(g, i);
    if (ccw(l[0], l[1], a) != -1) Q.push_back(a);
    if (ccw(l[0], l[1], a)*ccw(l[0], l[1], b) < 0)
      Q.push_back(crosspointLL(L(a,b), l));
  }
  return Q;
}
P turn(P p,double t){
	return p*exp(P(.0,t*PI/180.0));
}
P turn2(P p,double t){
	return p*exp(P(.0,t));
}
vector<L> tangentCC(C a,C b){
	if(a.r<b.r)swap(a,b);
	double d=abs(a.c-b.c);
	vector<L>l;
	if(d<EPS)return l;
	if(a.r+b.r<d-EPS){//hanareteiru
		double t=acos((a.r+b.r)/d);
		t=t*180/PI;
		l.pb(L(a.c+turn(a.r/d*(b.c-a.c),t),b.c+turn(b.r/d*(a.c-b.c),t)));
		l.pb(L(a.c+turn(a.r/d*(b.c-a.c),-t),b.c+turn(b.r/d*(a.c-b.c),-t)));
	}else if(a.r+b.r<d+EPS){//kuttuiteiru soto
		P p=a.c+a.r/d*(b.c-a.c);
		l.pb(L(p,p+turn(b.c-a.c,90)));
	}
	if(abs(a.r-b.r)<d-EPS){//majiwatteiru
		double t1=acos((a.r-b.r)/d);
		t1=t1*180/PI;
		double t2=180-t1;
		l.pb(L(a.c+turn(a.r/d*(b.c-a.c),t1),b.c+turn(b.r/d*(a.c-b.c),-t2)));
		l.pb(L(a.c+turn(a.r/d*(b.c-a.c),-t1),b.c+turn(b.r/d*(a.c-b.c),t2)));
	}else if(abs(a.r-b.r)<d+EPS){//kuttuiteiru uti
		P p=a.c+a.r/d*(b.c-a.c);
		l.pb(L(p,p+turn(b.c-a.c,90)));
	}
	return l;
}
void printL(const L &out){
	printf("%.9f %.9f %.9f %.9f\n",out[0].real(),out[0].imag(),out[1].real(),out[1].imag());
}
C CIN(){
	P p=pin();
	double r;
	cin>>r;
	return C(p,r);
}
bool para(L a,L b){
	return (abs(cross(a[1]-a[0],b[1]-b[0]))<EPS);
}
double min(double a,double b){return a<b?a:b;}
int main(){
	int n;
	while(cin>>n,n){
		vector<C>c;
		rep(i,n){
			double a;cin>>a;
			P p=pin();
			//p=turn(p,17);
			c.pb(C(p,a));
		}
		sort(all(c),[](C a,C b){
			return a.c<b.c;
		});
		double out=inf;
		rep(i,n){
			int r=max(0,i-10),l=min(i+10,n);
			loop(j,r,l)if(j!=i){
				out=min(out,abs(c[i].c-c[j].c)-c[i].r-c[j].r);
			}
		}
		cout<<shosu(9)<<out<<endl;
	}
}
accuracy: 1
time_ms: 450
memory_kb: 8624
final_rank: 11

code_snippet: /*include*/
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#include<complex>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
const double PI=acos(-1);
const double EPS=1e-10;
const double inf=1e8;
using namespace std;
#define shosu(x) fixed<<setprecision(x)
typedef complex<double> P;
typedef vector<P> G;
typedef vector<int> vi;
typedef vector<vi> vvi;

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
struct C{
	P c;double r;
	C(const P &c,double r):c(c),r(r){}
};
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
#define diff(P, i) (next(P, i) - curr(P, i))
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
		//return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);  
	}
	bool operator == (const P& a, const P& b) {
		return a.real()==b.real()&&a.imag()==b.imag();
	}
}
P pin(){
	double x,y;
	char d;
	cin>>x>>y;
	P p(x,y);
	return p;
}
void PIN(P* a,int n){
	rep(i,n)a[i]=pin();
}
double dot(P a,P b){
	return real(conj(a)*b);
}
double cross(P a,P b){
	return imag(conj(a)*b);
}
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
P projection(L a,P p){
	double t=dot(p-a[0],a[0]-a[1])/norm(a[0]-a[1]);
	return a[0]+t*(a[0]-a[1]);
}
P reflection(L a,P p){
	return p+2.0*(projection(a,p)-p);
}
bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}
double distanceLP(const L &l, const P &p) {
	return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
  return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
  if (intersectLS(l, s)) return 0;
  return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
/*bool intersectCS(C c,const L &l){
    return (distanceLP(l,c.c) < c.r+EPS &&
            (c.r < abs(c.c-l[0]) + EPS || c.r < abs(c.c-l[1]) + EPS));
}*/
int intersectCS(C c,L &l){
	if(norm(projection(l,c.c)-c.c)-c.r*c.r>EPS)return 0;
	const double d1=abs(c.c-l[0]),d2=abs(c.c-l[1]);
	if(d1<c.r+EPS&&d2<c.r+EPS)return 0;
	if(d1<c.r-EPS&&d2>c.r+EPS||d1>c.r+EPS&&d2<c.r-EPS)return 1;
	const P h=projection(l,c.c);
	if(dot(l[0]-h,l[1]-h)<0)return 2;
	return 0;
}
P crosspointSS(L a,L b){
	double t1=abs(cross(a[1]-a[0],b[0]-a[0]));
	double t2=abs(cross(a[1]-a[0],b[1]-a[0]));
	return b[0]+(b[1]-b[0])*t1/(t1+t2);
}
L crosspointCL(C c,L l){
	P pr=projection(l,c.c);
	P e=(l[1]-l[0])/abs(l[1]-l[0]);
	double t=sqrt(c.r*c.r-norm(pr-c.c));
	P a=pr+t*e;
	P b=pr-t*e;
	if(b<a)swap(a,b);
	return L(a,b);
}
L crosspointCS(C c,L l){
	if(intersectCS(c,l)==2)return crosspointCL(c,l);
	L ret=crosspointCL(c,l);
	if(dot(l[0]-ret[0],l[1]-ret[0])<0)ret[1]=ret[0];
	else ret[0]=ret[1];
	return ret;
}
L crosspointCC(C a,C b){
	P tmp=b.c-a.c;
	double d=abs(tmp);
	double q=acos((a.r*a.r+d*d-b.r*b.r)/(2*a.r*d));
	double t=arg(tmp);//atan(tmp.imag()/tmp.real());
	P p1=a.c+polar(a.r,t+q);
	P p2=a.c+polar(a.r,t-q);
	if(p2<p1)swap(p1,p2);
	return L(p1,p2);
}
P crosspointLL(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  return m[0] + B / A * (m[1] - m[0]);
}
double area(const G &g){
    double S =0;
    for(int i =0;i <g.size();i++){
        S +=(cross(g[i],g[(i+1)%g.size()]));
    }
    return abs(S/2.0);
}
bool isconvex(const G &g){
	int n=g.size();
	rep(i,n)if(ccw(g[(i+n-1)%n],g[i%n],g[(i+1)%n])==-1)return false;
	return true;
}
int inconvex(const G& g, const P& p) {
	bool in = false;
	int n=g.size();
	rep(i,n){
		P a=g[i%n]-p;
		P b=g[(i+1)%n]-p;
		if(imag(a)>imag(b))swap(a, b);
		if(imag(a)<=0&&0<imag(b))if(cross(a,b)<0)in=!in;
		if(cross(a,b)==0&&dot(a,b)<=0)return 1;//ON
	}
	return in?2:0;//IN : OUT;
}
G convex_hull(G &ps) {
    int n=ps.size(),k=0;
	sort(ps.begin(), ps.end());
	G ch(2*n);
	for(int i=0;i<n;ch[k++]=ps[i++])//lower-hull
		while(k>=2&&ccw(ch[k-2],ch[k-1],ps[i])==-1)--k;//<=0  ->  ==-1
	for(int i=n-2,t=k+1;i>=0;ch[k++]=ps[i--])//upper-hull
		while(k>=t&&ccw(ch[k-2],ch[k-1],ps[i])==-1)--k;//
	ch.resize(k-1);
	return ch;
}
double convex_diameter(const G &pt) {
  const int n = pt.size();
  int is = 0, js = 0;
  for (int i = 1; i < n; ++i) {
    if (imag(pt[i]) > imag(pt[is])) is = i;
    if (imag(pt[i]) < imag(pt[js])) js = i;
  }
  double maxd = norm(pt[is]-pt[js]);

  int i, maxi, j, maxj;
  i = maxi = is;
  j = maxj = js;
  do {
    if (cross(diff(pt,i), diff(pt,j)) >= 0) j = (j+1) % n;
    else i = (i+1) % n;
    if (norm(pt[i]-pt[j]) > maxd) {
      maxd = norm(pt[i]-pt[j]);
      maxi = i; maxj = j;
    }
  } while (i != is || j != js);
  return sqrt(maxd); /* farthest pair is (maxi, maxj). */
}//convex_diameter(g)
G convex_cut(const G& g, const L& l) {
  G Q;
  for (int i = 0; i < g.size(); ++i) {
    P a= curr(g, i), b= next(g, i);
    if (ccw(l[0], l[1], a) != -1) Q.push_back(a);
    if (ccw(l[0], l[1], a)*ccw(l[0], l[1], b) < 0)
      Q.push_back(crosspointLL(L(a,b), l));
  }
  return Q;
}
P turn(P p,double t){
	return p*exp(P(.0,t*PI/180.0));
}
P turn2(P p,double t){
	return p*exp(P(.0,t));
}
vector<L> tangentCC(C a,C b){
	if(a.r<b.r)swap(a,b);
	double d=abs(a.c-b.c);
	vector<L>l;
	if(d<EPS)return l;
	if(a.r+b.r<d-EPS){//hanareteiru
		double t=acos((a.r+b.r)/d);
		t=t*180/PI;
		l.pb(L(a.c+turn(a.r/d*(b.c-a.c),t),b.c+turn(b.r/d*(a.c-b.c),t)));
		l.pb(L(a.c+turn(a.r/d*(b.c-a.c),-t),b.c+turn(b.r/d*(a.c-b.c),-t)));
	}else if(a.r+b.r<d+EPS){//kuttuiteiru soto
		P p=a.c+a.r/d*(b.c-a.c);
		l.pb(L(p,p+turn(b.c-a.c,90)));
	}
	if(abs(a.r-b.r)<d-EPS){//majiwatteiru
		double t1=acos((a.r-b.r)/d);
		t1=t1*180/PI;
		double t2=180-t1;
		l.pb(L(a.c+turn(a.r/d*(b.c-a.c),t1),b.c+turn(b.r/d*(a.c-b.c),-t2)));
		l.pb(L(a.c+turn(a.r/d*(b.c-a.c),-t1),b.c+turn(b.r/d*(a.c-b.c),t2)));
	}else if(abs(a.r-b.r)<d+EPS){//kuttuiteiru uti
		P p=a.c+a.r/d*(b.c-a.c);
		l.pb(L(p,p+turn(b.c-a.c,90)));
	}
	return l;
}
void printL(const L &out){
	printf("%.9f %.9f %.9f %.9f\n",out[0].real(),out[0].imag(),out[1].real(),out[1].imag());
}
C CIN(){
	P p=pin();
	double r;
	cin>>r;
	return C(p,r);
}
bool para(L a,L b){
	return (abs(cross(a[1]-a[0],b[1]-b[0]))<EPS);
}
double min(double a,double b){return a<b?a:b;}
int main(){
	int n;
	while(cin>>n,n){
		vector<C>c;
		rep(i,n){
			double a;cin>>a;
			P p=pin();
			p=turn(p,17);
			c.pb(C(p,a));
		}
		sort(all(c),[](C a,C b){
			return a.c<b.c;
		});
		double out=inf;
		rep(i,n){
			int r=max(0,i-10),l=min(i+10,n);
			loop(j,r,l)if(j!=i){
				out=min(out,abs(c[i].c-c[j].c)-c[i].r-c[j].r);
			}
		}
		cout<<shosu(9)<<out<<endl;
	}
}
accuracy: 1
time_ms: 450
memory_kb: 8640
final_rank: 12

code_snippet: #include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

struct Circle{
	double x,y,r;
	bool operator < (const Circle &)const;
};

bool Circle::operator < (const Circle &a)const{
	return (x*x+y*y)<(a.x*a.x+a.y*a.y);
}

double dist(const Circle &a,const Circle &b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))-a.r-b.r;
}

const int MAX_N=100000;

int N;
Circle c[MAX_N];

vector<double> out;

int main(){
	do{
		scanf("%d",&N);
		if (N){
			for (int i=0;i<N;i++){
				scanf("%lf %lf %lf",&c[i].r,&c[i].x,&c[i].y);
			}
			sort(c,c+N);
			double ans=1e50;
			for (int i=0;i<N;i++){
				for (int j=i+1;j<min(N,i+4001);j++){
					ans=min(ans,dist(c[i],c[j]));
				}
			}
			out.push_back(ans);
		}
	}while(N);
	for (int i=0;i<out.size();i++){
		printf("%.12f\n",out[i]);
	}
	return 0;
}
accuracy: 1
time_ms: 6680
memory_kb: 3468
final_rank: 18

code_snippet: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#define INF 1e10
using namespace std;

int n;
struct P{
	double x,y,r;
	P(){}
	P(double xx,double yy,double rr){
		x=xx;
		y=yy;
		r=rr;
	}
	bool operator<(const P &p1)const{
		return x<p1.x;
	}
};

bool compare_y(P a,P b){
	return a.y<b.y;
}


double closest_pair(P *a,int n){
	if(n<=1)return INF;
	int m=n/2;
	double x=a[m].x;
	double r=a[m].r;
	double d=min(closest_pair(a,m),closest_pair(a+m,n-m));
	inplace_merge(a,a+m,a+n,compare_y);
	vector<P> b;
	for(int i=0;i<n;i++){
		if(fabs(a[i].x-x)-a[i].r-r>=d)continue;
		for(int j=0;j<b.size();j++){
			double dx=a[i].x-b[b.size()-j-1].x;
			double dy=a[i].y-b[b.size()-j-1].y;
			if(dy>=d+r+a[i].r)break;
			d=min(d,sqrt(dx*dx+dy*dy)-b[b.size()-j-1].r-a[i].r);
		}
		b.push_back(a[i]);
		r=max(a[i].r,r);
	}
	return d;
}

P p[100001];

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%lf %lf %lf",&p[i].r,&p[i].x,&p[i].y);
		}
		sort(p,p+n);
		printf("%.9f\n",closest_pair(p,n));
	}
	return 0;
}
accuracy: 1
time_ms: 280
memory_kb: 8840
final_rank: 10

code_snippet: #include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double x[110000];
double y[110000];
double r[110000];
pair<double,int>p[110000];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++){
			double tx,ty;
			scanf("%lf%lf%lf",r+i,&tx,&ty);
			x[i]=cos(1)*tx-sin(1)*ty;
			y[i]=sin(1)*tx+cos(1)*ty;
		}
		double ret=sqrt((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1]))-r[0]-r[1];
		for(int i=0;i<a;i++){
			p[i]=make_pair(x[i]+r[i],i);
		}
		std::sort(p,p+a);
		for(int i=0;i<a;i++){
			for(int j=i-1;j>=0;j--){
				if(p[i].first-r[p[i].second]*2-p[j].first>ret)break;
				int L=p[i].second;
				int R=p[j].second;
				ret=min(ret,sqrt((x[L]-x[R])*(x[L]-x[R])+(y[L]-y[R])*(y[L]-y[R]))-r[L]-r[R]);
			}
		}
		printf("%.12f\n",ret);
	}
}
accuracy: 1
time_ms: 170
memory_kb: 5324
final_rank: 1

code_snippet: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


typedef double DD;

const DD INF = 1LL<<60;
const DD EPS = 1e-10;
const DD PI = acos(-1.0);
DD torad(int deg) {return (DD)(deg) * PI / 180;}
DD todeg(DD ang) {return ang * 180 / PI;}

struct Point {
    DD x, y;
    Point(DD x = 0.0, DD y = 0.0) : x(x), y(y) {}
    friend ostream& operator << (ostream &s, const Point &p) {return s << '(' << p.x << ", " << p.y << ')';}
};

Point operator + (const Point &p, const Point &q) {return Point(p.x + q.x, p.y + q.y);}
Point operator - (const Point &p, const Point &q) {return Point(p.x - q.x, p.y - q.y);}
Point operator * (const Point &p, DD a) {return Point(p.x * a, p.y * a);}
Point operator * (DD a, const Point &p) {return Point(a * p.x, a * p.y);}
Point operator * (const Point &p, const Point &q) {return Point(p.x * q.x - p.y * q.y, p.x * q.y + p.y * q.x);}
Point operator / (const Point &p, DD a) {return Point(p.x / a, p.y / a);}
Point conj(const Point &p) {return Point(p.x, -p.y);}
Point rot(const Point &p, DD ang) {return Point(cos(ang) * p.x - sin(ang) * p.y, sin(ang) * p.x + cos(ang) * p.y);}
Point rot90(const Point &p) {return Point(-p.y, p.x);}
DD cross(const Point &p, const Point &q) {return p.x * q.y - p.y * q.x;}
DD dot(const Point &p, const Point &q) {return p.x * q.x + p.y * q.y;}
DD norm(const Point &p) {return dot(p, p);}
DD abs(const Point &p) {return sqrt(dot(p, p));}
DD amp(const Point &p) {DD res = atan2(p.y, p.x); if (res < 0) res += PI*2; return res;}
bool eq(const Point &p, const Point &q) {return abs(p - q) < EPS;}
bool operator < (const Point &p, const Point &q) {return (abs(p.x - q.x) > EPS ? p.x < q.x : p.y < q.y);}
bool operator > (const Point &p, const Point &q) {return (abs(p.x - q.x) > EPS ? p.x > q.x : p.y > q.y);}
Point operator / (const Point &p, const Point &q) {return p * conj(q) / norm(q);}

int ccw(const Point &a, const Point &b, const Point &c) {
    if (cross(b-a, c-a) > EPS) return 1;
    if (cross(b-a, c-a) < -EPS) return -1;
    if (dot(b-a, c-a) < -EPS) return 2;
    if (norm(b-a) < norm(c-a) - EPS) return -2;
    return 0;
}

struct Line : vector<Point> {
    Line(Point a = Point(0.0, 0.0), Point b = Point(0.0, 0.0)) {
        this->push_back(a);
        this->push_back(b);
    }
};

struct Circle : Point{
    DD r;
    Circle(Point p = Point(0.0, 0.0), DD r = 0.0) : Point(p), r(r) {}
};


DD MAX_R;
bool compare_y(Circle a, Circle b) { return a.y < b.y; }

DD Rec(vector<Circle>::iterator it, int n) {
    if (n <= 1) return INF;
    int m = n/2;
    DD x = it[m].x;
    DD d = min(Rec(it, m), Rec(it+m, n-m));
    inplace_merge(it, it+m, it+n, compare_y);
    
    vector<Circle> vec;
    for (int i = 0; i < n; ++i) {
        if (fabs(it[i].x - x) >= d + MAX_R*2) continue;
        for (int j = 0; j < vec.size(); ++j) {
            DD dx = it[i].x - vec[vec.size()-j-1].x;
            DD dy = it[i].y - vec[vec.size()-j-1].y;
            if (dy >= d + MAX_R*2) break;
            d = min(d, abs(sqrt(dx*dx+dy*dy) - it[i].r - vec[vec.size()-j-1].r));
        }
        vec.push_back(it[i]);
    }
    return d;
}

DD Closet(vector<Circle> vc) {
    int n = vc.size();
    sort(vc.begin(), vc.end());
    return Rec(vc.begin(), n);
}


int n;
double r, x, y;

int main() {
    while (cin >> n) {
        if (n == 0) break;
        MAX_R = 0.0;
        vector<Circle> vc(n);
        for (int i = 0; i < n; ++i) cin >> vc[i].r >> vc[i].x >> vc[i].y, chmax(MAX_R, vc[i].r);
        double res = Closet(vc);
        cout << fixed << setprecision(9) << res << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 630
memory_kb: 11160
final_rank: 16

code_snippet: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



typedef double DD;

const DD INF = 1LL<<60;
const DD EPS = 1e-10;
const DD PI = acos(-1.0);
DD torad(int deg) {return (DD)(deg) * PI / 180;}
DD todeg(DD ang) {return ang * 180 / PI;}

struct Point {
    DD x, y;
    Point(DD x = 0.0, DD y = 0.0) : x(x), y(y) {}
    friend ostream& operator << (ostream &s, const Point &p) {return s << '(' << p.x << ", " << p.y << ')';}
};

Point operator + (const Point &p, const Point &q) {return Point(p.x + q.x, p.y + q.y);}
Point operator - (const Point &p, const Point &q) {return Point(p.x - q.x, p.y - q.y);}
Point operator * (const Point &p, DD a) {return Point(p.x * a, p.y * a);}
Point operator * (DD a, const Point &p) {return Point(a * p.x, a * p.y);}
Point operator * (const Point &p, const Point &q) {return Point(p.x * q.x - p.y * q.y, p.x * q.y + p.y * q.x);}
Point operator / (const Point &p, DD a) {return Point(p.x / a, p.y / a);}
Point conj(const Point &p) {return Point(p.x, -p.y);}
Point rot(const Point &p, DD ang) {return Point(cos(ang) * p.x - sin(ang) * p.y, sin(ang) * p.x + cos(ang) * p.y);}
Point rot90(const Point &p) {return Point(-p.y, p.x);}
DD cross(const Point &p, const Point &q) {return p.x * q.y - p.y * q.x;}
DD dot(const Point &p, const Point &q) {return p.x * q.x + p.y * q.y;}
DD norm(const Point &p) {return dot(p, p);}
DD abs(const Point &p) {return sqrt(dot(p, p));}
DD amp(const Point &p) {DD res = atan2(p.y, p.x); if (res < 0) res += PI*2; return res;}
bool eq(const Point &p, const Point &q) {return abs(p - q) < EPS;}
bool operator < (const Point &p, const Point &q) {return (abs(p.x - q.x) > EPS ? p.x < q.x : p.y < q.y);}
bool operator > (const Point &p, const Point &q) {return (abs(p.x - q.x) > EPS ? p.x > q.x : p.y > q.y);}
Point operator / (const Point &p, const Point &q) {return p * conj(q) / norm(q);}

int ccw(const Point &a, const Point &b, const Point &c) {
    if (cross(b-a, c-a) > EPS) return 1;
    if (cross(b-a, c-a) < -EPS) return -1;
    if (dot(b-a, c-a) < -EPS) return 2;
    if (norm(b-a) < norm(c-a) - EPS) return -2;
    return 0;
}

struct Line : vector<Point> {
    Line(Point a = Point(0.0, 0.0), Point b = Point(0.0, 0.0)) {
        this->push_back(a);
        this->push_back(b);
    }
};

struct Circle : Point{
    DD r;
    Circle(Point p = Point(0.0, 0.0), DD r = 0.0) : Point(p), r(r) {}
};


DD MAX_R;
bool compare_y(Circle a, Circle b) { return a.y < b.y; }

DD Rec(vector<Circle>::iterator it, int n) {
    if (n <= 1) return INF;
    int m = n/2;
    DD x = it[m].x;
    DD d = min(Rec(it, m), Rec(it+m, n-m));
    inplace_merge(it, it+m, it+n, compare_y);
    
    vector<Circle> vec;
    for (int i = 0; i < n; ++i) {
        if (fabs(it[i].x - x) >= d + MAX_R*2) continue;
        for (int j = 0; j < vec.size(); ++j) {
            DD dx = it[i].x - vec[vec.size()-j-1].x;
            DD dy = it[i].y - vec[vec.size()-j-1].y;
            if (dy >= d + MAX_R*2) break;
            d = min(d, abs(sqrt(dx*dx+dy*dy) - it[i].r - vec[vec.size()-j-1].r));
        }
        vec.push_back(it[i]);
    }
    return d;
}

DD Closet(vector<Circle> vc) {
    int n = vc.size();
    sort(vc.begin(), vc.end());
    return Rec(vc.begin(), n);
}


int n;
double r, x, y;

int main() {
    while (cin >> n) {
        if (n == 0) break;
        MAX_R = 0.0;
        vector<Circle> vc(n);
        for (int i = 0; i < n; ++i) cin >> vc[i].r >> vc[i].x >> vc[i].y, chmax(MAX_R, vc[i].r);
        double res = Closet(vc);
        cout << fixed << setprecision(9) << res << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 620
memory_kb: 11360
final_rank: 17