// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



const int maxn = 1e3 + 20;

int vis[maxn],n;

double x[maxn],y[maxn],r[maxn],dist[maxn],mp[maxn][maxn];



void SPFA(int s)

{

    queue<int>q;

    for(int i = 1;i <= n;i++) dist[i] = 1e10;

    memset(vis,0,sizeof(vis));

    while(!q.empty()) q.pop();

    dist[s] = 0;

    vis[s] = 1;

    q.push(s);



    while(!q.empty())

    {

        int v = q.front();

        q.pop();

        vis[v] = 0;

        for(int i = 1;i <= n;i++)

        {

            if(dist[i] > dist[v] + mp[v][i])

            {

                dist[i] = dist[v] + mp[v][i];

                if(!vis[i])

                {

                    vis[i] = 1;

                    q.push(i);

                }

            }

        }

    }

}



int main()

{

    while(scanf("%lf%lf%lf%lf",&x[1],&y[1],&x[2],&y[2]) != EOF)

    {

        scanf("%d",&n);

        n += 2;

        r[1] = r[2] = 0;

        mp[1][2] = mp[2][1] = sqrt((x[1] - x[2]) * (x[1] - x[2]) + (y[1] - y[2]) * (y[1] - y[2]));

        for(int i = 3;i <= n;i++)

        {

            scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);

        }

        for(int i = 1;i <= n;i++)

        {

            for(int j = 1;j <= n;j++)

            {

                mp[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));

                mp[i][j] -= r[i] + r[j];

                if(mp[i][j] < 0)

                {

                    mp[i][j] = 0;

                }

            }

        }

        SPFA(1);

        printf("%.10f\n",dist[2]);

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<queue>

#include<cmath>

using namespace std;

typedef long long ll;

const int N=1005;

const double INF=23333333333333.0;

double road[N][N];

double dist[N];

double x[N],y[N],r[N];

int xs,xt,ys,yt;

int n;

double D(double x,double y,double xx,double yy){

    return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));

}

bool vis[N];

void Dijkstra(){

    for(int i=1;i<=n;i++)

        dist[i]=road[n-1][i];

    int u=n-1;

    int cnt=1;

    vis[u]=1;

    while(cnt<n){

        double minv=INF;

        int x;

        for(int i=1;i<=n;i++)

            if(!vis[i]){

                if(dist[i]>dist[u]+road[u][i]){

                    dist[i]=dist[u]+road[u][i];

                }

                if(dist[i]<minv)

                    minv=dist[i],x=i;

            }

        u=x;

        vis[u]=1;

        cnt++;

    }

}

int main()

{

    scanf("%d%d%d%d",&xs,&ys,&xt,&yt);

    scanf("%d",&n);

    memset(dist,-1,sizeof dist);

    for(int i=1;i<=n;i++)

        scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);

    n++;

    x[n]=xs,y[n]=ys,r[n]=0;

    n++;

    x[n]=xt,y[n]=yt,r[n]=0;

    for(int i=1;i<=n;i++)

        for(int j=i;j<=n;j++){

            double f=D(x[i],y[i],x[j],y[j]);

            if(f<r[i]+r[j]){

                f=0;

            }

            else

                f-=r[i]+r[j];

            road[i][j]=road[j][i]=f;

        }

    Dijkstra();

    printf("%.10lf",dist[n]);

}


// Fastest known solution for this problem: