#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define X real()
#define Y imag()
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;

double dot(xy_t a, xy_t b){
    return (conj(a) * b).X;
}

double cross(xy_t a, xy_t b){
    return (conj(a) * b).Y;
}

pair<xy_t, xy_t> cc_inter(xy_t a, double r, xy_t b, double s){
    double d = abs(a - b);
    double t = (r*r - s*s + d*d) / (2*d);
    double x = sqrt(r*r - t*t);
    xy_t v = t/d * (b-a) + a;
    xy_t u = x/d * (b-a) * xy_t(0, 1);
    return make_pair(v+u, v-u);
}

double f(xy_t a, xy_t b, xy_t c){
    return (b.Y-a.Y)*(c.X-a.X) - (b.X-a.X)*(c.Y-a.Y);
}

bool is_crossing(xy_t a, xy_t b, xy_t c, xy_t d){
    bool b1 = f(a, b, c) * f(a, b, d) <= 0;
    bool b2 = f(c, d, a) * f(c, d, b) <= 0;
    return b1 & b2;
}

int n;
double d[210][210];
xy_t p[210];

int main(){
    while(scanf("%d", &n) && n){
        double x[110], y[110], r[110];
        rep(i, n) scanf("%lf%lf%lf", &x[i], &y[i], &r[i]);
        p[0] = xy_t(x[0], y[0]);
        p[2*n-1] = xy_t(x[n-1], y[n-1]);
        rep(i, n-1){
            auto tmp = cc_inter(xy_t(x[i], y[i]), r[i], xy_t(x[i+1], y[i+1]), r[i+1]);
            p[i*2+1] = tmp.fi;
            p[i*2+2] = tmp.se;
        }
        rep(i, 2*n){
            rep(j, 2*n) d[i][j] = 1e18;
            d[i][i] = 0;
        }
        rep(i, 2*n-1)For(j, i+1, 2*n){
            bool flag = true;
            for(int k=(i+1)/2*2+1; k<(j-1)/2*2; k+=2){
                if(!is_crossing(p[i], p[j], p[k], p[k+1])){
                    flag = false;
                    break;
                }
            }
            if(flag) d[i][j] = d[j][i] = abs(p[i] - p[j]);
        }
        rep(k, 2*n)rep(i, 2*n)rep(j, 2*n)if(d[i][k] < 1e18 && d[k][j] < 1e18){
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
        printf("%.10lf\n", d[0][2*n-1]);
    }
}
