#include <cstdio>
#include <iostream>
#include <cmath>

#define INF 1000000.0

using namespace std;

struct P{
	double x, y;
	P(double X=0.0, double Y=0.0){
		x = X;
		y = Y;
	} 
	P operator+( const P &in ){
		P tmp( x + in.x , y + in.y );
		return tmp;
	}
	P operator-( const P &in ){
		P tmp( x - in.x , y - in.y );
		return tmp;
	}
	P operator*( const double &in ){
		P tmp( x * in , y * in );
		return tmp;
	}
	double dot( const P &in ){
		return x * in.x + y * in.y;
	}
	double cross( const P &in ){
		return x * in.y - y * in.x;
	}
};


//交差しているか求める(どの3点も同直線上にない)
bool check(P a1, P a2, P b1, P b2){
	P va = a2 - a1, vb = b2 - b1;
	P v1 = b1 - a1, v2 = b2 - a2;

//	cout << "va " << va.first << " " << va.second << endl;
//	cout << "vb " << vb.first << " " << vb.second << endl;
//	cout << "v1 " << v1.first << " " << v1.second << endl;
//	cout << "v2 " << v2.first << " " << v2.second << endl;
//	cout << "va.cross(v1) " << va.cross( v1 ) << endl;
//	cout << "va.cross(v2) " << va.cross( v2 ) << endl;
	
	if( ( va.cross( v1 ) * va.cross( v2 ) ) >= 0 )
		return false;

	if( ( vb.cross( v1 ) * vb.cross( v2 ) ) >= 0 )
		return false;
	
	return true;
}

//2円の交点を求める(2円の中心の中点cからのベクトルvを返す(交点はc±v) )
P circlecross(P a, double ra, P b, double rb, P *cen){
	//P cen = ( a + b ) * 0.5;
//	double r = ra / (ra + rb);

	double c = sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
	double r = (ra*ra - rb*rb + c*c ) / ( 2.0 * c*c );
//	cout << "r  " << r << endl;
	double e = c * r;
//	cout << "e  " << e << endl;
	double d = sqrt( ra*ra - e*e );
//	cout << "d  " << d << endl;
	
	P tmp;
//	cout << "d " << d << "  c " << c << endl;
	tmp.x = d * (a.y - b.y) / c;
	tmp.y = d * (b.x - a.x) / c;

	*cen = a * (1.0-r) + b * r;
	
	return tmp;
}

int n;

int solve(){
	P c[100], p[101][2];
	double r[100];
	double dist[205][205];
	
	cin >> c[0].x >> c[0].y >> r[0];
	p[0][0] = c[0];
	p[0][1] = c[0];
	for(int i=1; i<n; i++){
		cin >> c[i].x >> c[i].y >> r[i];
		P cen;
		P d = circlecross( c[i-1], r[i-1], c[i], r[i], &cen );
//		cout << "circlecross " << d.x << d.y << endl;
	//	double rate = sqrt( (r[i-1]*r[i-1] - r[i]*r[i] + c*c ) / ( 2.0 * c*c ) );
//		P cen = ( c[i] * (1-rate) + ( c[i-1] * rate );
		p[i][0] = cen + d;
		p[i][1] = cen - d;
	}
	p[n][0] = c[n-1];
	p[n][1] = c[n-1];

	//求める
	fill( dist[0], dist[0]+205*205, INF );
	for(int i=0; i<n*2; i++){
		for(int j=i+1; j<=n*2; j++){
			bool f=true;
			for(int k=i/2+1; k<j/2; k++){
	//			cout << "ijk " << i << " " << j << " " << k << endl;
				if( !check( p[i/2][i%2], p[j/2][j%2], p[k][0], p[k][1] ) )
					f = false;
			}
			if( f ){
				double x = p[i/2][i%2].x - p[j/2][j%2].x;
				double y = p[i/2][i%2].y - p[j/2][j%2].y;
				dist[i][j] = sqrt( x*x + y*y );
			}
		}
	}
	//最短経路
	for(int k=1; k<n*2; k++){
		for(int i=0; i<=n*2; i++){
			for(int j=0; j<=n*2; j++){
				dist[i][j] = min( dist[i][j], dist[i][k] + dist[k][j] );
			}
		}
	}

//	cout << dist[0][n*2] << endl;
	printf("%0.6f\n", dist[0][n*2] );
	
	return 0;
}

int main(){
	while( cin >> n, n ){
		solve();
	}
	return 0;
}