#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

double sx,sy,tx,ty;
int N;
double x[1003],y[1003],r[1003];

double dist(double x1,double y1,double x2,double y2){
    double dx=x1-x2;
    double dy=y1-y2;
    return sqrt(dx*dx+dy*dy);
}

struct edge{
    int to;
    double cost;
    edge(){}
    edge(int to,double cost) : to(to), cost(cost){}
};

vector<edge> G[1024];

int main(){
    cin >> sx >> sy >> tx >> ty;
    cin >> N;
    rep(i,N) cin >> x[i] >> y[i] >> r[i];

    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            auto d = dist(x[i],y[i],x[j],y[j]);
            double cost = max<double>(0,d-r[i]-r[j]);
            G[i].push_back(edge(j,cost));
            G[j].push_back(edge(i,cost));
        }
    }

    for(int i=0;i<N;i++){
        double d = dist(sx,sy,x[i],y[i]);
        double cost = max<double>(0,d-r[i]);
        G[N].push_back(edge(i,cost));
    }
    for(int i=0;i<N;i++){
        double d = dist(x[i],y[i],tx,ty);
        double cost = max<double>(0,d-r[i]);
        G[i].push_back(edge(N+1,cost));
    }
    G[N].push_back(edge(N+1,dist(sx,sy,tx,ty)));


    using P = pair<double,int>;
    priority_queue<P,vector<P>,greater<P>> que;
    vector<double> d(N+10,numeric_limits<double>::max() / 10);
    que.push(P(0,N));
    d[N] = 0;

    while(!que.empty()){
        int v = que.top().se;
        double cost = que.top().fi;
        que.pop();

        if(v == N+1){
            cout << Double(cost) << endl;
            return 0;
        }

        if(cost > d[v]) continue;

        for(const edge &e : G[v]){
            int nxt = e.to;
            double nc = cost + e.cost;
            if(nc < d[nxt]){
                d[nxt] = nc;
                que.push(P(nc,nxt));
            }
        }
    }
}


Measured memory_bytes: 22404