#include <iostream>
#include <utility>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

#define ll long long

int main() {
	ll xs, ys, xt, yt;
	cin >> xs >> ys >> xt >> yt;
	int N; cin >> N;
	vector<pair<pair<ll, ll>, ll>> mp;
	mp.push_back(make_pair(make_pair(xs, ys), 0));
	for(int i=1; i<=N; ++i){
	    ll x, y, r;
	    cin >> x >> y >> r;
	    mp.push_back(make_pair(make_pair(x, y), r));
	}
	mp.push_back(make_pair(make_pair(xt, yt), 0));
	vector<double> dist(N+2, 1e20);
	vector<bool> used(N+2, false);
	used[0]=true;
	int now=0;
	dist[0]=0.0;
	while(now<=N){
	    int mn=-1;
	    for(int i=1; i<=N+1; ++i){
	        if(!used[i]){
	            ll p=mp[i].first.first-mp[now].first.first, q=mp[i].first.second-mp[now].first.second;
	            dist[i]=min(dist[i], dist[now]+max(0.0, sqrt(p*p+q*q)-(mp[i].second+mp[now].second)));
	            if(mn<0) mn=i;
	            else if(dist[mn]>dist[i]) mn=i;
	        }
	    }
	    used[mn]=true;
	    now=mn;
	}
	cout << setprecision(15) << dist[N+1] << endl;
	return 0;
}
