#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
 
typedef long long LL;
typedef pair<int, int> PII;

const int MAX = 1 << 10;

double x[MAX], y[MAX], r[MAX];
double c[MAX][MAX];
bool used[MAX];
double d[MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(10);
	int xs, ys, xt, yt, n;
	cin >> xs >> ys >> xt >> yt >> n;
	FOR(i, 0, n)
		cin >> x[i] >> y[i] >> r[i];
	x[n] = xs;
	y[n] = ys;
	x[n + 1] = xt;
	y[n + 1] = yt;
	FOR(i, 0, n + 2)
		FOR(j, 0, n + 2)
		{
			double dist = sqrt(pow(x[j] - x[i], 2) + pow(y[j] - y[i], 2));
			c[i][j] = max(0.0, dist - r[i] - r[j]);
		}
	FOR(i, 0, n + 2)
		d[i] = 1e18;
	d[n] = 0;
	FOR(i, 0, n + 2)
	{
		int v = -1;
		FOR(j, 0, n + 2)
			if(!used[j] && (v == -1 || d[j] < d[v]))
				v = j;
		used[v] = true;
		FOR(j, 0, n + 2)
			d[j] = min(d[j], d[v] + c[v][j]);
	}
	cout << d[n + 1] << "\n";
	return 0;
}