#include <bits/stdc++.h>

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

using R = long double;
using P = complex<R>;
using L = pair<P,P>;
struct C {
    P c; R r;
    C() {}
    C(const P &a, const R &b) : c(a), r(b) {}
};
struct S : public L {
    S() {}
    S(const P &a, const P &b) : L(a,b) {}
};

const R EPS = 1e-8;
const R PI = atan(1)*4;

inline int sgn(const R& r) { return (r>EPS) - (r<-EPS); }
inline R dot(const P& a, const P& b) {
    return real(a)*real(b) + imag(a)*imag(b);
}
inline R det(const P& a, const P& b) {
    return real(a)*imag(b) - imag(a)*real(b);
}
inline P vec(const L& l) {return l.second - l.first;}

enum CCW{LEFT=1, RIGHT=2, BACK=4, FRONT=8, ON_SEG=16};
int ccw(P a, P b, P c) {
    P p = (c-a)/(b-a);
    if(sgn(imag(p)) > 0) return LEFT;
    if(sgn(imag(p)) < 0) return RIGHT;
    if(sgn(real(p)) < 0) return BACK;
    if(sgn(real(p)-1) > 0) return FRONT;
    return ON_SEG;
}

inline bool intersect(const S& s1, const S& s2) {
    int ccw1 = ccw(s1.first, s1.second, s2.first) | ccw(s1.first, s1.second, s2.second);
    int ccw2 = ccw(s2.first, s2.second, s1.first) | ccw(s2.first, s2.second, s1.second);
    return (ccw1 & ccw2) == (LEFT | RIGHT) || ((ccw1 | ccw2) & ON_SEG);
}

vector<P> crosspoint(C a, C b) {
    R d = abs(a.c-b.c);
    R t = (a.r*a.r-b.r*b.r+d*d)/2/d, h = sqrt(a.r*a.r-t*t);
    P m = t/abs(b.c-a.c)*(b.c-a.c)+a.c;
    auto n_vector = [&](P p) -> P { return P(-p.imag(), p.real())/abs(p); };
    P n = n_vector(a.c-b.c);
    vector<P> ret(2, m);
    ret[0] -= h*n; ret[1] += h*n;
    return ret;
}

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

    while(1) {
        ll n;
        cin >> n;
        if(!n) break;
        vector<C> vc(n);
        REP(i, n) {
            R x, y, r;
            cin >> x >> y >> r;
            vc[i] = C(P(x, y), r);
        }

        vector<vector<P>> vp(n+1, vector<P>(2));
        vp[0][0] = vp[0][1] = vc[0].c;
        vp[n][0] = vp[n][1] = vc[n-1].c;
        FOR(i, 1, n) vp[i] = crosspoint(vc[i-1], vc[i]);

        auto ok = [&](PII from, PII to) {
            S s1(vp[from.first][from.second], vp[to.first][to.second]);
            FOR(i, from.first+1, to.first) {
                S s2(vp[i][0], vp[i][1]);
                if(!intersect(s1, s2)) return false;
            }
            return true;
        };

        vector<vector<R>> dp(n+1, vector<R>(2, LLINF));
        dp[0][0] = dp[0][1] = 0;
        REP(i, n) REP(j, 2) FOR(k, i+1, n+1) REP(l, 2) {
            if(ok({i,j},{k,l})) {
                chmin(dp[k][l], dp[i][j] + abs(vp[i][j]-vp[k][l]));
            }
        }
        cout << fixed << setprecision(15) << dp[n][0] << endl;
    }

    return 0;
}



Measured memory_bytes: 3376