#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<cstring>
#include<algorithm>
#define maxn 1005
using namespace std;
int xs,ys,xt,yt,n,x[maxn],y[maxn],r[maxn];
double dist[maxn],g[maxn][maxn];
queue<int> q;
bool inq[maxn];
int main()
{
	scanf("%d%d%d%d%d",&xs,&ys,&xt,&yt,&n);
	x[0]=xs,y[0]=ys,x[n+1]=xt,y[n+1]=yt;
	for(int i=1;i<=n;i++) scanf("%d%d%d",&x[i],&y[i],&r[i]);
	for(int i=0;i<=n+1;i++)
		for(int j=0;j<=n+1;j++)
			g[i][j]=max(0.0,sqrt(1.0*(x[i]-x[j])*(x[i]-x[j])+1.0*(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j]);
	for(int i=1;i<=n+1;i++) dist[i]=1e16;
	q.push(0); inq[0]=true;
	while(!q.empty())
	{
		int u=q.front(); q.pop();
		inq[u]=false;
		for(int v=0;v<=n+1;v++)
			if(dist[v]>dist[u]+g[u][v])
			{
				dist[v]=dist[u]+g[u][v];
				if(!inq[v]) { inq[v]=true; q.push(v); }
			}
	}
	printf("%.10f\n",dist[n+1]);
}