#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<double,int>;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

const ll max_V=1010;//大きすぎ注意

struct edge{ll to;double cost;};

int N;//頂点数
int M;
//ll cst[max_V][max_V];
vector<edge> G[max_V];
double d[max_V];//頂点sからの最短距離

void dijkstra(ll s){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d,d+N+2,(double)INF);
    d[s]=0;
    que.push(P(0,s));//pair...first->最短距離、second->頂点

    while(!que.empty()){
        P p=que.top();que.pop();
        ll v=p.second;
        if(d[v]<p.first) continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

signed main(){
    V<ll> a(2),b(2);
    rep(i,2) cin>>a[i]>>b[i];
    cin>>N;
    V<ll> x(N),y(N),r(N);
    rep(i,N) cin>>x[i]>>y[i]>>r[i];
    rep(i,N-1){
        for(int j=i+1;j<N;j++){
            edge e,f;
            e.to=i;
            f.to=j;
            if(((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-(r[i]+r[j])*(r[i]+r[j])>0){
                double rr=(double)sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j];
                e.cost=rr;
                f.cost=rr;
            }else{
                e.cost=f.cost=0.0;
            }
            G[i].push_back(f);
            G[j].push_back(e);
        }
    }
    rep(i,N){
        edge e,f,g,h;
        e.to=i;f.to=N;
        g.to=i;h.to=N+1;
        rep(j,2){
            if(((a[j]-x[i])*(a[j]-x[i])+(b[j]-y[i])*(b[j]-y[i]))-r[i]*r[i]>0){
                double rr=(double)sqrt((a[j]-x[i])*(a[j]-x[i])+(b[j]-y[i])*(b[j]-y[i]))-r[i];
                if(j==0){
                    e.cost=rr;
                    f.cost=rr;
                    G[i].push_back(f);
                    G[N].push_back(e);
                }else{
                    g.cost=h.cost=rr;
                    G[i].push_back(h);
                    G[N+1].push_back(g);
                }
            }else{
                e.cost=f.cost=g.cost=h.cost=0;
                if(j==0){
                    G[i].push_back(f);
                    G[N].push_back(e);
                }else{
                    G[i].push_back(h);
                    G[N+1].push_back(g);
                }
            }
        }
    }
    edge e,f;
    e.to=N;f.to=N+1;
    double rr=sqrt((a[0]-a[1])*(a[0]-a[1])+(b[0]-b[1])*(b[0]-b[1]));
    e.cost=f.cost=rr;
    G[N].push_back(f);
    G[N+1].push_back(e);
    dijkstra(N);
    cout<<fixed<<setprecision(15)<<d[N+1]<<endl;
}

Measured memory_bytes: 21872