#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define INF 1e8
bool vis[1030];
double x,dis[1030],dist[1030][1030],cost[1030][1030];
int n,a[1030][4],pre[1030];
double prim(double x){
memset(vis,0,sizeof vis);
vis[1]=1; dis[1]=0;
for (int i=2;i<=n;i++){dis[i]=cost[1][i]-dist[1][i]*x; pre[i]=1;}
double tot_cost=0,tot_dist=0;
for (int i=2;i<=n;i++){
double min_dis=INF;
int k=0;
for (int j=1;j<=n;j++)
if (!vis[j] && dis[j]<min_dis){min_dis=dis[j]; k=j;}
dis[k]=0; vis[k]=1;
tot_cost+=cost[k][pre[k]];
tot_dist+=dist[k][pre[k]];
for (int j=1;j<=n;j++)
if (!vis[j] && dis[j]>cost[k][j]-dist[k][j]*x){dis[j]=cost[k][j]-dist[k][j]*x; pre[j]=k;}
}
return tot_cost/tot_dist;
}
int main(){
do{
scanf("%d",&n); if (n==0) break;
for (int i=1;i<=n;i++) scanf("%d%d%d",&a[i][1],&a[i][2],&a[i][3]);
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++){
dist[i][j]=sqrt((a[i][1]-a[j][1])*(a[i][1]-a[j][1])+(a[i][2]-a[j][2])*(a[i][2]-a[j][2]));
cost[i][j]=abs(a[i][3]-a[j][3]);
}
x=1e6;
while (1){
double tt=prim(x);
if (x-tt<1e-6) break;
else x=tt;
}
printf("%.3f\n",x);
}while (1);
return 0;
}