#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

double dd(double a, double b){
	return sqrt(a * a + b * b);
}

int n, x[1002], y[1002], r[1002];
double dist[1002];
double d[1002][1002];
int main(){
	int xs, ys, xt, yt;
	cin >> xs >> ys >> xt >> yt >> n;
	rep(i, n) cin >> x[i] >> y[i] >> r[i];
	x[n] = xs; y[n] = ys;
	x[n+1] = xt; y[n+1] = yt;
	rep(i, n + 2) rep(j, i) d[j][i] = d[i][j] = max(0.0, dd(x[i] - x[j], y[i] - y[j]) - r[i] - r[j]);
	
	//rep(i, n + 2) rep(j, n + 2) cerr<<d[i][j]<<(j==n+1?"\n":" ");

	rep(i, n + 2) dist[i] = 1e12;
	priority_queue<pair<double,int>> q;
	q.emplace(0, n);
	while(!q.empty()){
		double cd;
		int c;
		cd = q.top().first; c = q.top().second; q.pop();
		if(dist[c] <= -cd) continue;
		dist[c] = -cd;

		rep(i, n + 2) if(dist[i] > -cd + d[c][i] + 1e-9){
			q.emplace(cd - d[c][i], i);
		}
	}
	cout << fixed << setprecision(20) << dist[n + 1] << endl;
	return 0;
}