#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int maxn = 1010;
double inf = 10000000000000000000007.0;
using namespace std;
int n, opt[maxn]; bool vis[maxn]; double f[maxn]; 
struct poi { double x, y, r; } a[maxn];
double getdis(poi a, poi b) {
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
int main() {
	scanf("%lf%lf%lf%lf", &a[0].x, &a[0].y, &a[1].x, &a[1].y);
	scanf("%d", &n), ++ n, a[0].r = a[1].r = 0; 
	rep(i, 2, n) scanf("%lf%lf%lf", &a[i].x, &a[i].y, &a[i].r);
	int he = 0, ta = 1; opt[1] = 0;
	rep(i, 1, n) f[i] = inf, vis[i] = true; f[0] = 0, vis[0] = false;
	while (he != ta) {
		he = (he + 1) % maxn; int u = opt[he];
		rep(i, 1, n) {
			double ret = max(getdis(a[u], a[i]) - a[u].r - a[i].r, 0.0) + f[u];
			if (ret < f[i]) {
				f[i] = ret;
				if (vis[i]) vis[i] = false, ta = (ta + 1) % maxn, opt[ta] = i;
			}
		}
		vis[u] = true;
	}
	printf("%.12lf", f[1]);
	return 0;
}