#include <iostream>
#include <cstdio>
#include <cmath>
#define N 1005
using namespace std;

int n, v[N];
double mn, x[N], y[N], r[N], d[N]={0, 1e18};
int main() {
	int i, j, k;
	cin >> x[0] >> y[0] >> x[1] >> y[1] >> n;
	n += 2;
	for(i=2; i<n; i++) {
		cin >> x[i] >> y[i] >> r[i];
		d[i] = 1e18;
	}
	for(i=k=0; i<n; i++) {
		v[k] = 1;
		for(j=0; j<n; j++) {
			d[j] = min(d[j], d[k] + max(0.0, sqrt((x[j]-x[k])*(x[j]-x[k]) + (y[j]-y[k])*(y[j]-y[k])) - r[j] - r[k]));
		}
		mn = 1e18;
		for(j=0; j<n; j++) {
			if(!v[j] && d[j]<mn) mn = d[j], k = j;
		}
	}
	printf("%.12f", d[1]);
	return 0;
}