#include<bits/stdc++.h>
using namespace std;
struct node
{
    long long x,y,r;
}s[1005];

int n;
double map1[1005][1005],d[1005];
bool vis[1005];

long double cal(node a,node b)
{
    return (long double)sqrt((long double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void dijkstra(int s)
{
    d[s]=0;
    while(1)
    {
        int v=-1;
        for(int i=0; i<=n+1; i++)
        {
            if(!vis[i] && (v==-1 || d[i]<d[v]))
            v=i;
        }
        if (v==-1) break;
        vis[v]=1;
        for(int i=0; i<=n+1;i++)
        d[i]=min(d[i],d[v]+map1[v][i]);
    }
}

int main()
{
    long long x1,y1;
    scanf("%lld%lld%lld%lld",&s[0].x,&s[0].y,&x1,&y1);
    scanf("%d",&n);
    s[n+1].x=x1;
    s[n+1].y=y1;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld%lld",&s[i].x,&s[i].y,&s[i].r);
    }
    for(int i=0; i<=n+1; i++)
    {
        for(int j=i+1; j<=n+1; j++)
        {
            map1[i][j]=cal(s[i],s[j]);
            map1[i][j]-=s[i].r+s[j].r;
            if(map1[i][j]<0)
                map1[i][j]=0;
            map1[j][i]=map1[i][j];
        }
    }
    for(int i=0; i<=n+1; i++)
        d[i]=1e37;
    dijkstra(0);
    printf("%.9lf\n",d[n+1]);
    return 0;
}
