#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

#define PI 3.14159265353238463

#define curr(P, i) P[(i) % P.size()]
#define next(P, i) P[(i+1) % P.size()]
#define prev(P, i) P[(i+P.size()-1) % P.size()]
#define diff(P, i) (next(P,i) - curr(P,i))
enum { OUT, ON, IN };

typedef complex<double> P;
typedef vector<P> G;

namespace std{
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(){}
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

P projection(const L &l, const P &p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}
P reflection(const L &l, const P &p) {
  return p + 2.0 * (projection(l, p) - p);
}
double distanceLP(const L &l, const P &p) {
  return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
  return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
  if (intersectLS(l, s)) return 0;
  return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}

vector<P> crosspointCC(P c1, double r1, P c2, double r2){
	vector<P> res;
	P d=c2-c1;
	if(abs(d)>r1+r2 || abs(d)<abs(r1-r2))return res;
	double t=acos((r1*r1+norm(d)-r2*r2)/(2*r1*abs(d)));
	res.pb(c1+d*r1/abs(d)*P(cos(t),sin(t)));
	res.pb(c1+d*r1/abs(d)*P(cos(-t),sin(-t)));
	return res;
}

typedef pair<double,int> DI;

int n;
P c[111],p[222];
L line[111];
double r[111],d[222];

int main(){
	while(cin>>n && n){
		rep(i,n){
			int x,y;
			cin>>x>>y>>r[i];
			c[i]=P(x,y);
		}
		p[0]=c[0];
		rep(i,n-1){
			vector<P> v=crosspointCC(c[i],r[i],c[i+1],r[i+1]);
			rep(j,2)p[1+2*i+j]=v[j];
			line[i]=L(v[0],v[1]);
		}
		p[2*n-1]=c[n-1];
		priority_queue<DI,vector<DI>,greater<DI> > Q;
		Q.push(DI(0,0));
		fill(d,d+2*n,INF);
		d[0]=0;
		while(1){
			DI q=Q.top();Q.pop();
			double dist=q.fir;
			int v=q.sec;
			if(dist>d[v])continue;
			if(v==2*n-1){
				cout<<setprecision(11)<<dist<<endl;
				break;
			}
			rep2(i,v+1,2*n){
				double nd=dist+abs(p[i]-p[v]);
				if(nd<d[i]){
					L course=L(p[v],p[i]);
					rep2(j,(v==0 ? -1:(v-1)/2)+1,(i-1)/2){
						if(!intersectSS(course,line[j]))goto fail;
					}
					d[i]=nd;
					Q.push(DI(nd,i));
					fail:;
				}
			}
		}
	}
}

Measured memory_bytes: 1048