#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <random>



#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, int>;

template <class T> inline bool chmax(T& a, T b){
    if(a < b){a = b; return true;}
    return false;
}
template <class T> inline bool chmin(T& a, T b){
    if(a > b){a = b; return true;}
    return false;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


// Dijkstra 法 を行うクラス
template <class DistanceType = int, class AnsType = long long int>
class Dijkstra{
private:
    // 無限大 の距離
    const long long int infinity_cost = 9e18 + 1;
    const int V; // 枝の数, 頂点数
    // (指し示す頂点, コスト)
    using edge = std::pair<int, DistanceType>;
    using edgeSet = std::vector<edge>; // 1つの頂点からでる枝の集合
    std::vector<edgeSet> Edges; // 枝全体
    std::vector<AnsType> Distances; // 距離を表す
    std::vector<bool> hasVisited;
public:
    // コンストラクタ
    Dijkstra(int edgeSize): V(edgeSize){
        Edges.resize(edgeSize, edgeSet(0)); hasVisited.resize(edgeSize);
        Distances.resize(edgeSize, infinity_cost);
    }
    Dijkstra(int edgeSize, std::vector<edgeSet> &A): V(edgeSize){
        Edges = A; hasVisited.resize(edgeSize);
        Distances.resize(edgeSize, infinity_cost);
    }
    // デコンストラクタ
    ~Dijkstra(void){}
    // 頂点 u -> v へ 重み cost を追加
    void add(int u, int v, DistanceType cost){
        Edges[u].emplace_back(std::pair<int, DistanceType>(v, cost));
    }
    // 頂点 vertex 中心の計算を行う
    using Info__Type_ = std::pair<AnsType, int>;
    void computeAround(int vertex){
        std::fill(Distances.begin(), Distances.end(), infinity_cost);
        std::fill(hasVisited.begin(), hasVisited.end(), false);
        std::priority_queue<Info__Type_, std::vector<Info__Type_>,
            std::greater<Info__Type_>> undoneEdge;
        undoneEdge.push(edge(0, vertex));
        int vtx; AnsType dist;
        while(not undoneEdge.empty()){
            std::tie(dist, vtx) = undoneEdge.top(); undoneEdge.pop();
            
            if(hasVisited[vtx]) continue;
            hasVisited[vtx] = true; Distances[vtx] = dist;
            for(edge element : Edges[vtx]){
                AnsType nextDistance = dist + element.second;
                if(nextDistance < Distances[element.first])
                        undoneEdge.push(Info__Type_(nextDistance, element.first));
            }
        }
    }
    AnsType distance(int vertex){
        return Distances.at(vertex);
    }
    void debugShow(void){
        for(int i = 0; i < V; ++i){
            printf("距離[%d] : ", i);
            if(Distances[i] == infinity_cost) std::cout << "INF" << '\n';
            else std::cout << Distances[i] << '\n';
        }
    }
};



using coordinate = std::pair<int, int>;
using barrier = std::pair<coordinate, int>;
std::vector<barrier> A;

std::vector<std::vector<long double>> Edge;

long double distance(barrier& a, barrier& b){
    long long int dx = a.first.first  - b.first.first,
                  dy = a.first.second - b.first.second;
    dx *= dx; dy *= dy;
    long long int R = a.second + b.second; 
    if(dx + dy <= R * R) return 0;
    return sqrt(dx+dy) - R;
}



int main(void){
    // 入力
    int sx, sy, gx, gy;
    scanf("%d%d%d%d", &sx, &sy, &gx, &gy);

    int n; scanf("%d", &n);
    A.resize(n+2);
    A[n] = {{sx, sy}, 0};
    A[n+1] = {{gx, gy}, 0};
    REP(i, n) scanf("%d%d%d", &A[i].first.first, &A[i].first.second, &A[i].second);

    int N = n + 2;
    Dijkstra<long double, long double> DSK(N);
    REP(i, N) REP(j, N) if(i < j){
        long double d = distance(A[i], A[j]);

        DSK.add(i, j, d);
        DSK.add(j, i, d);
    }

    DSK.computeAround(n);


    printf("%.16Lf\n", DSK.distance(n+1));




    return 0;
}


Measured memory_bytes: 51048