#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
 
#define maxn 1005
 
using namespace std;
 
inline int getint()
{
    int num=0,flag=1;char c;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
    while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();
    return num*flag;
}
 
struct node{
	long long x,y,r;
}p[maxn];

queue<int>Q;

double l[maxn][maxn];
double dis[maxn];
bool vis[maxn];
int n;

inline double dist(int i,int j)
{
	double ans=sqrt((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y));
	ans-=p[i].r+p[j].r;
	return ans>0?ans:0;
}

void spfa()
{
	Q.push(1);vis[1]=1;
	while(!Q.empty())
	{
		int u=Q.front();Q.pop();vis[u]=0;
		for(int i=1;i<=n;i++)
			if(i!=u)
				if(dis[u]+l[u][i]<dis[i])
				{
					dis[i]=dis[u]+l[u][i];
					if(!vis[i])
						Q.push(i),vis[i]=1;
				}
	}
}

int main()
{
	memset(dis,0x7f,sizeof dis);dis[1]=0;
	p[1].x=getint(),p[1].y=getint(),p[2].x=getint(),p[2].y=getint();
	n=getint()+2;
	for(int i=3;i<=n;i++)
		p[i].x=getint(),p[i].y=getint(),p[i].r=getint();
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)
		l[i][j]=l[j][i]=dist(i,j);
	spfa();
	printf("%.10lf\n",dis[2]);
}