#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#define REP(x,y) for(int i=x;i<=y;i++)
using namespace std;

struct point {
	double x; double y;
};
double INF = 100000000000000000;
int const MAX = 1005;
point a[MAX];
double radius[MAX];
double g[MAX][MAX];
int color[MAX];
double dist[MAX];

int main() {
	cin >> a[0].x >> a[0].y >> a[1].x >> a[1].y;
	radius[1] = radius[0] = 0;
	int n;
	cin >> n;
	REP(2, n + 1) {
		cin >> a[i].x >> a[i].y;
		cin >> radius[i];
	}
	REP(0, n + 1) {
		for (int j = 0; j <= i; j++) {
			double dist_x, dist_y;
			dist_x = a[i].x - a[j].x;
			dist_y = a[i].y - a[j].y;
			g[i][j] = g[j][i] = max(double(0),sqrt(dist_x*dist_x + dist_y * dist_y)-radius[i]-radius[j]);
		}
	}
	int now = 0;
	REP(0, n + 1) color[i] = 0;
	REP(0, n + 1) dist[i] = INF;
	color[0] = 1;
	dist[0] = 0;
	while (now != 1) {
		int nearest = 1;
		double nearest_dist = INF;
		REP(1, n + 1) {
			if (color[i] == 0) {
				dist[i] = min(dist[i], g[i][now]+dist[now]);
				if (nearest_dist >= dist[i]) {
					nearest_dist = dist[i];
					nearest = i;
				}
			}
		}
		now = nearest;
		color[now] = 1;
	}
	cout.precision(20);
	cout << dist[1] << endl;
}