// Arup Guha
// 3/17/2019
// Solution to 2019 MAPS Problem K: Rebel Portals

import java.util.*;

public class rebelportals {

	final public static double NOSOL = 1000000;
	
	public static int n;
	public static int[][] pts;
	public static double[][] dist;
	
	public static void main(String[] args) {
		
		// Read in points.
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		pts = new int[n][3];
		for (int i=0; i<n; i++)
			for (int j=0; j<3; j++)
				pts[i][j] = stdin.nextInt();
			
		// Pre-comp distances.
		dist = new double[n][n];
		for (int i=0; i<n; i++)
			for (int j=0; j<n; j++)
				dist[i][j] = calc(i, j);
	
		// dp[mask][last] stores best distances for visiting everything in mask ending at vertex last
		double[][] dp = new double[1<<n][n];
		for (int i=0; i<(1<<n); i++) Arrays.fill(dp[i], NOSOL);
		
		// Get this for free.
		for (int i=0; i<n; i++) dp[1<<i][i] = 0;
		
		// Subset we have visited.
		for (int mask=0; mask<(1<<n); mask++) {
			
			if (Integer.bitCount(mask) < 2) continue;
			
			// Get bits that are on.
			ArrayList<Integer> bits = new ArrayList<Integer>();
			for (int i=0; i<n; i++)
				if ((mask & (1<<i)) != 0)
					bits.add(i);
				
			// last vertex visited.
			for (Integer last: bits) {
				
				int prevMask = mask - (1<<last);
				
				// let x be last vertex visited on prevMask.
				for (Integer x: bits) {
					if (x.equals(last)) continue;
					dp[mask][last] = Math.min(dp[mask][last], dp[prevMask][x] + dist[x][last]);
				}
			}
		}
		
		// Get smallest ending mask.
		double res = dp[(1<<n)-1][0];
		for (int i=1; i<n; i++)
			res = Math.min(res, dp[(1<<n)-1][i]);
		
		System.out.println(res);
		
	}
	
	public static double calc(int a, int b) {
		double dsq = 0;
		for (int i=0; i<3; i++)
			dsq += ((pts[a][i]-pts[b][i])*(pts[a][i]-pts[b][i]));
		return Math.sqrt(dsq);
	}
}