#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef pair<double, int> pdi;
const int maxn = 1000 + 10;
const double INF = 1e18;
struct cir
{
	double x, y, r;
}a[maxn];
int n;
vector<pdi> E[maxn];
double dis[maxn];
bool vis[maxn];
double sqr(double x) { return x * x;}
double calc(int i, int j)
{
	double dist = sqrt(sqr(a[i].x - a[j].x) + sqr(a[i].y - a[j].y));
	return max(dist - a[i].r - a[j].r, 0.0);
}
double dij()
{
	priority_queue<pdi> Q;
	for(int i = 1; i <= n + 2; ++i) dis[i] = INF;
	dis[1] = 0;
	Q.push(mp(-dis[1], 1));
	while(!Q.empty())
	{
		auto x = Q.top(); Q.pop();
		if(vis[x.second]) continue;
		vis[x.second] = 1;
		for(auto e : E[x.second])
			if(dis[x.second] + e.first < dis[e.second])
			{
				dis[e.second] = dis[x.second] + e.first;
				Q.push(mp(-dis[e.second], e.second));
			}
	}
	return dis[2];
}		
int main()
{
	cin >> a[1].x >> a[1].y >> a[2].x >> a[2].y;
	cin >> n;
	for(int i = 3; i <= n + 2; ++i) cin >> a[i].x >> a[i].y >> a[i].r;
	for(int i = 1; i <= n + 2; ++i) 
		for(int j = i; j <= n + 2; ++j)
		{
			double dis = calc(i, j);
			E[i].push_back(mp(dis, j));
			E[j].push_back(mp(dis, i));
		}
	printf("%.10lf\n", dij());
	return 0;
}