#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
struct node
{
    int x,y,r;
}s[1005];

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

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()
{
    int x1,y1;
    scanf("%d%d%d%d",&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("%d%d%d",&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]=(double)sqrt((double)(s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y));
            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]=1e30;
    dijkstra(0);
    printf("%.9f\n",d[n+1]);
    return 0;
}
