#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define min(a,b) ((a)<(b) ? (a):(b))
#define max(a,b) ((a)>(b) ? (a):(b))

long long gcd(long long a, long long b){
    if(a<b){
        swap(a,b);
    }
    while(b){
        long long r = a%b;
        a=b;
        b=r;
    }
    return a;
}

long long lcm(long long a, long long b){
    return (a*b)/gcd(a,b);
}

int isPrim(int a){
    if(a==1){
        return 0;
    }
    for(int i=2;i<=(a+1)/2;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}

long long mod_pow(long long x, long long n, long long mod){
    //xのn乗を計算するのにn乗を2進表記にして計算
    //x^22 = x^16 + x^4 + x^2
    long long ret=1;
    while(n>0){
        if(n%2==1){
            ret=(ret*x)%mod;//答えに付加
        }
        x=(x*x)%mod;//2乗
        n=n/2;
    }
    return ret;
}


struct XX{
    int u;
    int v;
    int t;
};

class xxIntu {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第2条件
        if((riLeft.t) == (riRight.t)){
            return riLeft.u < riRight.u;//<:昇順(小さいものから順番)、>:降順(大きいものから順番)
        }
        //第1条件
        return (riLeft.t) < (riRight.t);
    }
};
/*bool operator< (const XX &riLeft, const XX &riRight){
    return riLeft.d < riRight.d;
};*/

int index(string in){
    if(in=="A"){
        return 0;
    }else if(in=="B"){
        return 1;
    }else if(in=="C"){
        return 2;
    }else if(in=="D"){
        return 3;
    }else if(in=="E"){
        return 4;
    }else if(in=="F"){
        return 5;
    }else if(in=="G"){
        return 6;
    }else if(in=="H"){
        return 7;
    }else if(in=="I"){
        return 8;
    }else if(in=="J"){
        return 9;
    }else if(in=="K"){
        return 10;
    }else if(in=="L"){
        return 11;
    }else if(in=="M"){
        return 12;
    }else if(in=="N"){
        return 13;
    }else if(in=="O"){
        return 14;
    }else if(in=="P"){
        return 15;
    }else if(in=="Q"){
        return 16;
    }else if(in=="R"){
        return 17;
    }else if(in=="S"){
        return 18;
    }else if(in=="T"){
        return 19;
    }else if(in=="U"){
        return 20;
    }else if(in=="V"){
        return 21;
    }else if(in=="W"){
        return 22;
    }else if(in=="X"){
        return 23;
    }else if(in=="Y"){
        return 24;
    }else if(in=="Z"){
        return 25;
    }
    return -1;
}

string rindex(int in){
    if(in==65){
        return "A";
    }else if(in==66){
        return "B";
    }else if(in==67){
        return "C";
    }else if(in==68){
        return "D";
    }else if(in==69){
        return "E";
    }else if(in==70){
        return "F";
    }else if(in==71){
        return "G";
    }else if(in==72){
        return "H";
    }else if(in==73){
        return "I";
    }else if(in==74){
        return "J";
    }else if(in==75){
        return "K";
    }else if(in==76){
        return "L";
    }else if(in==77){
        return "M";
    }else if(in==78){
        return "N";
    }else if(in==79){
        return "O";
    }else if(in==80){
        return "P";
    }else if(in==81){
        return "Q";
    }else if(in==82){
        return "R";
    }else if(in==83){
        return "S";
    }else if(in==84){
        return "T";
    }else if(in==85){
        return "U";
    }else if(in==86){
        return "V";
    }else if(in==87){
        return "W";
    }else if(in==88){
        return "X";
    }else if(in==89){
        return "Y";
    }else if(in==90){
        return "Z";
    }
    return "";
}

int ppar[100000];
int rrank[100000];

void init(int n){
    for(int i=1;i<=n;i++){
        ppar[i]=i;
        rrank[i]=0;
    }
}

int find(int x){
    if(ppar[x]==x){
        return x;
    }else{
        return ppar[x]=find(ppar[x]);
    }
}

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y){
        return;
    }
    if(rrank[x]<rrank[y]){
        ppar[x]=ppar[y];
    }else{
        ppar[y]=x;
        if(rrank[x]==rrank[y]){
            rrank[x]++;
        }
    }
}
bool same(int x,int y){
    return find(x)==find(y);
}

int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //getline(cin, target);
    //cin >> x >> y;
    //テスト用
    //ifstream ifs( "1_06.txt" );
    //ifs >> a;
    //ここから

    double xs,ys,xt,yt;
    cin >>  xs >> ys >> xt >>yt;
    int N;
    cin >> N;
    double x[1000];
    double y[1000];
    double r[1000];
    for(int i=0;i<N;i++){
        cin >> x[i] >> y[i] >> r[i];
    }
    
    double cost[N+2][N+2];
    //double cost[10][10];

    for(int i=0;i<N;i++){
        double tmp=sqrt(pow(xs-x[i],2)+pow(ys-y[i],2));
        if(r[i]>=tmp){
            tmp=0;
        }else{
            tmp=tmp-(r[i]);
        }
        cost[0][i+1]=tmp;
    }
    double tmp=sqrt(pow(xs-xt,2)+pow(ys-yt,2));
    cost[0][N+1]=tmp;
    
    for(int i=0;i<N;i++){
        double tmp=sqrt(pow(xt-x[i],2)+pow(yt-y[i],2));
        if(r[i]>=tmp){
            tmp=0;
        }else{
            tmp=tmp-(r[i]);
        }
        cost[i+1][N+1]=tmp;
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i!=j){
                double tmp=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
                if(r[i]+r[j]>=tmp){
                    tmp=0;
                }else{
                    tmp=tmp-(r[i]+r[j]);
                }
                cost[i+1][j+1]=tmp;
            }
        }
    }
    
    double d[N+2];
    //double d[10];
    bool used[N+2];
    //bool used[10];
    for(int i=0;i<N+2;i++) d[i]=9000000000;
    for(int i=0;i<N+2;i++) used[i]=false;
    d[0]=0;
    while(true){
        int vv=-1;
        for(int i=0;i<=N+1;i++){
            if(!used[i] && (vv==-1 || d[i]<d[vv])){
                vv=i;
            }
        }
        if(vv==-1){
            break;
        }
        used[vv]=true;
        for(int i=0;i<=N+1;i++){
            d[i]=min(d[i],d[vv]+cost[vv][i]);
        }
        
    }
    
    printf("%.10f\n",d[N+1]);

    
    //ここまで
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}

Measured memory_bytes: 8064