#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <cstdlib>using namespace std;#define P(a) printf("%lfn", (a))const int maxn = 1000 + 10;const double INF = 100000000;const double eps = 1e-8;double g[maxn][maxn], lowcost[maxn];bool vis[maxn];int n;int pre[maxn];struct Point{ double x, y; double h; Point(){} Point(double x, double y):x(x), y(y){}}p[maxn];double prim(double l){ int k; double temp, sum = 0, sum_h = 0, sum_d = 0; memset(vis, false, sizeof(vis)); for(int i = 0; i < n; i++) pre[i] = 0; vis[0] = true; for(int i = 0; i < n; ++i) lowcost[i] = fabs(p[0].h - p[i].h) - l * g[0][i]; for(int i = 0; i < n; ++i) { temp = INF; for(int j = 0; j < n; ++j) if(!vis[j] && temp > lowcost[j]) temp = lowcost[k = j]; if(temp == INF) break; vis[k] = true; sum_h += fabs(p[k].h - p[pre[k]].h); sum_d += g[k][pre[k]]; for(int j = 0; j < n; ++j) if(!vis[j] && lowcost[j] > fabs(p[k].h - p[j].h) - l * g[k][j]){ lowcost[j] = fabs(p[k].h - p[j].h) - l * g[k][j]; pre[j] = k; } } return sum_h / sum_d;}Point read_point(){ Point a; scanf("%lf%lf%lf", &a.x, &a.y, &a.h); return a;}double dist(int i, int j){ return sqrt((p[i].x - p[j].x) * (p[i].x - p[j].x) + (p[i].y - p[j].y) * (p[i].y - p[j].y));}int main(){ while(scanf("%d", &n) != EOF){ if(!n) break; for(int i = 0; i < n; i++){ p[i] = read_point(); } for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){ g[i][j] = dist(i, j); } double ans = 0, tmp; while(1){ tmp = prim(ans); if(fabs(ans - tmp) < eps) break; ans = tmp; } printf("%.3lfn", ans); } return 0;}