#include "bits/stdc++.h"

using namespace std;

const int INF = numeric_limits<int>::max()/2;

typedef long double ld;
typedef complex<ld> Point;
typedef pair<ld,ld> P;

const ld eps = 1e-12, pi = acos(-1.0);

namespace std {
	bool operator<(const Point &lhs, const Point &rhs) {
		if (lhs.real() < rhs.real() - eps) return true;
		if (lhs.real() > rhs.real() + eps) return false;
		return lhs.imag() < rhs.imag();
	}
}

bool eq(ld a, ld b) {
	return (abs(a - b) < eps);
}

ld dot(Point a, Point b) {
	return real(conj(a) * b);
}

ld cross(Point a, Point b) {
	return imag(conj(a) * b);
}

class Line {
public:
	Point a, b;
	Line() : a(Point(0, 0)), b(Point(0, 0)) {}
	Line(Point a, Point b) : a(a), b(b) {}
};

class Circle {
public:
	Point p;
	ld r;
	Circle() : p(Point(0, 0)), r(0) {}
	Circle(Point p, ld r) : p(p), r(r) {}
};

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

bool isis_ss(Line s, Line t) {
	return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&
		ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

vector<Point> is_cc(Circle c1, Circle c2) {
	vector<Point> res;
	ld d = abs(c1.p - c2.p);
	ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d);
	ld dfr = c1.r * c1.r - rc * rc;
	if (abs(dfr) < eps) dfr = 0.0;
	else if (dfr < 0.0) return res; // no intersection
	ld rs = sqrt(dfr);
	Point diff = (c2.p - c1.p) / d;
	res.push_back(c1.p + diff * Point(rc, rs));
	if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs));
	return res;
}

struct Edge{
    int to;
    ld cost;
    Edge(int to,ld cost): to(to), cost(cost){}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

bool operator < (const Edge &e, const Edge &f){
    return e.cost > f.cost;
}

ld dijkstra(const Graph &g, int s){
    vector<ld> d(g.size(),INF);
    vector<int> p(g.size(),-1);
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0,s)); // P(dis, pos)
    while(!que.empty()){
        ld dist = que.top().first;
        int v = que.top().second;
        que.pop();
        if(d[v]<dist) continue;
        for(const auto &e: g[v]){
            if(d[e.to]<=d[v]+e.cost) continue;
            d[e.to] = d[v] + e.cost;
            que.push(P(d[e.to], e.to));
            p[e.to]=v;
        }
    }
    int tmpp=g.size()-1;
    vector<int> path;
    while(tmpp!=-1){
        path.push_back(tmpp);
        tmpp=p[tmpp];
    }
    reverse(path.begin(),path.end());
    //for(int i=0;i<path.size();++i)cout<<path[i]<<" ";
    //cout<<endl;
    return d[g.size()-1];
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    while(cin>>n,n){
        vector<Circle> c;
        for(int i=0;i<n;i++){
            ld x,y,r;cin>>x>>y>>r;
            c.push_back(Circle(Point(x,y),r));
        }
        Point st=c[0].p, gt=c[n-1].p;
        vector<Point> ps;
        vector<Line> ls;
        ps.push_back(st);
        for(int i=1;i<n;i++){
            vector<Point> res=is_cc(c[i],c[i-1]);
            ps.push_back(res[0]);
            ps.push_back(res[1]);
            ls.push_back(Line(res[0],res[1]));
        }
        ps.push_back(gt);
        
        int sz=ps.size();
        vector<vector<ld>> dis(sz,vector<ld>(sz,INF));
        Graph g(sz);
        for(int i=0;i<sz;i++) dis[i][i]=0;

        // st->mid
        for(int i=1;i<sz-1;i++){
            int idx=(i+1)/2;
            ld d=abs(st-ps[i]);
            bool ftmp=true;
            for(int j=0;j<idx-1;j++){
                if(isis_ss(ls[j],Line(st,ps[i]))) continue;
                ftmp=false;
            }
            if(ftmp){
                dis[0][i]=dis[i][0]=d;
                g[0].push_back(Edge(i,d));
                g[i].push_back(Edge(0,d));
            }
        }
        // st->gt
        bool f=true;
        for(int i=0;i<(int)ls.size();i++){
            if(isis_ss(ls[i],Line(st,gt))) continue;
            f=false;
        }
        if(f){
            dis[0][sz-1]=dis[sz-1][0]=abs(st-gt);
            g[0].push_back(Edge(sz-1,abs(st-gt)));
            g[sz-1].push_back(Edge(0,abs(st-gt)));
        }

        // mid->mid
        for(int i=1;i<sz-1;i++){
            int idx=(i+1)/2;
            for(int j=i+1;j<sz-1;j++){
                int jdx=(j+1)/2;
                if(idx==jdx){
                    dis[i][j]=dis[j][i]=abs(ps[i]-ps[j]);
                    g[i].push_back(Edge(j,abs(ps[i]-ps[j])));
                    g[j].push_back(Edge(i,abs(ps[i]-ps[j])));
                    continue;
                }
                ld d=abs(ps[i]-ps[j]);
                bool ftmp=true;
                for(int k=idx;k<jdx-1;k++){
                    if(isis_ss(ls[k],Line(ps[i],ps[j]))) continue;
                    ftmp=false;
                }
                if(ftmp){
                    dis[i][j]=dis[j][i]=d;
                    g[i].push_back(Edge(j,d));
                    g[j].push_back(Edge(i,d));
                }
            }
        }
        // mid->gt
        for(int i=1;i<sz-1;i++){
            int idx=(i+1)/2;
            ld d=abs(ps[i]-gt);
            bool ftmp=true;
            for(int j=idx;j<(int)ls.size();j++){
                if(isis_ss(ls[j],Line(ps[i],gt))) continue;
                ftmp=false;
            }
            if(ftmp){
                dis[i][sz-1]=dis[sz-1][i]=d;
                g[i].push_back(Edge(sz-1,d));
                g[sz-1].push_back(Edge(i,d));
            }
        }

        //cout<<fixed<<setprecision(10)<<dis[1][10]<<endl;
        for(int k=0;k<sz;k++){
            for(int i=0;i<sz;i++){
                for(int j=0;j<sz;j++){
                    dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
                }
            }
        }
        //cout<<fixed<<setprecision(10)<<dis[0][sz-1]<<endl;
        cout<<fixed<<setprecision(10)<<dijkstra(g,0)<<endl;
    }
}


Measured memory_bytes: 4172