/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const int INF = 100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

vector<pair<pair<double,double>,int>> Edge;
//二点間の距離 double,int : dist,index
vector<vector<pair<double,int>>> dist(1005);
vector<double> miniD(1005,1145141919810.0);

void dijkstra(){
    priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>> PQ;
    PQ.push(make_pair(0,0));
    while(!PQ.empty()){
        P p = PQ.top();PQ.pop();
        double nd = p.first;int from = p.second;
        if(miniD.at(from) < nd) continue;
        for(pair<double,int> V : dist.at(from)){
            double needDist = V.first;
            int to = V.second;
            //cout << from << " " << to << " " << needDist << endl;
            if(miniD.at(from)+needDist < miniD.at(to)){
                miniD.at(to) = miniD.at(from)+needDist;
                PQ.push(make_pair(miniD.at(to),to));
            }
        }
    } 
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int sx,sy,gx,gy;cin >> sx >> sy >> gx >> gy;
    int N;cin >> N;
    //始点を入れておく
    Edge.push_back(make_pair(make_pair(sx,sy),0));
    for(int i = 0;i<N;i++){
        int x,y,r;cin >> x >> y >> r;
        Edge.push_back(make_pair(make_pair(x,y),r));
    }
    //終点を入れておく
    Edge.push_back(make_pair(make_pair(gx,gy),0));
    //全点間の距離を計算する
    for(int i = 0;i<N+2;i++){
        for(int j = 0;j<N+2;j++){
            if(i == j) continue;
            double distx = pow(Edge.at(i).first.first-Edge.at(j).first.first,2);
            double disty = pow(Edge.at(i).first.second-Edge.at(j).first.second,2);
            double avoid = Edge.at(i).second+Edge.at(j).second;
            double d = sqrt(distx+disty)-avoid;
            d = max(0.0,d);
            dist.at(i).push_back(make_pair(d,j));
        }
    }
    miniD.at(0) = 0;
    dijkstra();
    /*for(int i = 0;i<N+2;i++){
        cout << fixed << setprecision(10) << miniD.at(i) << endl;
    }*/
    cout << fixed << setprecision(10) << miniD.at(N+1) << endl;
}


Measured memory_bytes: 23504