// Arup Guha
// 11/8/2009
// My Solution to 2009 SE Regional Problem H: Robot Challenge

import java.util.*;
import java.io.*;

class target {
	public int x;
	public int y;
	public int p;
	
	public target(int my_x, int my_y, int my_p) {
		x = my_x;
		y = my_y;
		p = my_p;
	}
}

public class h {
	
	public static void main(String[] args) throws Exception {
		
		Scanner fin = new Scanner(new File("h.in"));
		
		int n = fin.nextInt();
		
		// Loop until the end of the data.
		while (n > 0) {
			
			// Make room for the initial spot and end spot.
			target[] all = new target[n+2];
			
			// We start here.
			all[0] = new target(0,0,0);
			
			// We keep track of the sums of all the penalties upto
			// target i.
			int[] sumpenalty = new int[n+2];
			sumpenalty[0] = 0;
			
			// Read in the rest of the targets.
			for (int i=1; i<=n; i++) {
				int x = fin.nextInt();
				int y = fin.nextInt();
				int p = fin.nextInt();
				all[i] = new target(x,y,p);
				sumpenalty[i] = sumpenalty[i-1] + p;
			}
			
			// We end here.
			all[n+1] = new target(100,100,0);
			sumpenalty[n+1] = sumpenalty[n];
			
			// Make room here for both the begin and end spots.
			// The value stored in bestScore[i] will represent the
			// fastest we can get to target i, if that was our ending
			// spot.
			double[] bestScore = new double[n+2];
			
			// We start here, so this one is obvious.
			bestScore[0] = 0;
			bestScore[1] = dist(all[0], all[1]) + 1;
			
			// Determine the best score for target i.
			for (int i=2; i<n+2; i++) {
				
				// Each segment must take fewer than 1000 seconds (by a lot) and
				// there are at most 100 of them.
				double bestSoFar = 100000;
				
				// Try each of these as your last ending point!
				for (int j=0; j<i; j++) {
					
					// This would be your score if you last ended at spot j.
					// Plus the penalty for skipping targets j+1, j+2, ..., i-1.
					// Plus the time it would take to go directly from target j to target i.
					// Plus the one second we are stopping here.
					double score = bestScore[j] + sumpenalty[i-1] - sumpenalty[j] + dist(all[j], all[i]) + 1;
					
					// Update our max.
					if (score < bestSoFar)
						bestSoFar = score;
				}
				
				// Now, set our best score for ending at target i.
				bestScore[i] = bestSoFar;
			}
			
			// Print this out and add our tolerance for rounding purposes.
			System.out.printf("%.3f\n",bestScore[n+1]+1e-9);
			
			// Get the next case.
			n = fin.nextInt();
		}
	}
	
	// Returns the distance between a and b.
	public static double dist(target a, target b) {
		return Math.sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
	}
}
		
		