#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

vector<int> dy = { 0,0,1,-1 };
vector<int> dx = { 1,-1,0,0 };

template<class T> void corner(bool flg, T hoge) {
	if (flg) {
		cout << hoge << endl;
		exit(0);
	}
	else return;
}

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
	o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}

template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {
	o << "{" << obj.first << ", " << obj.second << "}"; return o;
}

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
	cout << head << " ";
	print(forward<Tail>(tail)...);
}

void YN(bool flg) {
	cout << ((flg) ? "YES" : "NO") << endl;
}

void Yn(bool flg) {
	cout << ((flg) ? "Yes" : "No") << endl;
}

void yn(bool flg) {
	cout << ((flg) ? "yes" : "no") << endl;
}

template<class T> class Dijkstra{
public:
	vector<T> cost; //startからの距離
	vector<vector<pair<T, int>>> edge;//fromからtoへの<T>costの辺 
	
	Dijkstra(const int N, T inf) : cost(vector<T>(N,inf)),edge(vector<vector<pair<T,int>>>(N)) {
	}

	void make_edge(int from, int to, T w){
		edge[from].push_back({w,to});
	}

	void solve(int start){
		priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
		pq.push({0,start});
		cost[start] = 0;
		while(!pq.empty()){
			T v = pq.top().first;
			int from = pq.top().second;
			pq.pop();
			for(auto u: edge[from]){
				T w = v + u.first;
				int to = u.second;
				if(w < cost[to]){
					cost[to] = w;
					pq.push({w,to});
				}
			}
		}
		return;
	}
};

//Euclidean distance
template<class T> T EucDist(T x1, T y1, T x2, T y2) {
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}

int main() {
	double sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	int N; cin >> N;
	V<P<double, double>> xy(N+2);
	V<double> r(N+2,0);
	REP(i,N){
		double xx, yy, rr;
		cin >> xx >> yy >> rr;
		xy[i] = {xx,yy};
		r[i] = rr;
	}
	xy[N] = { sx,sy };
	xy[N+1] = { gx,gy };

	Dijkstra<double> dijk(N+2, 1e18);

	REP(i,N+2)REP(j,N+2){
		if (i == j) continue;
		double d = EucDist(xy[i].first, xy[i].second, xy[j].first, xy[j].second);
		if (r[i] + r[j] >= d) d = 0.;
		else d = d - (r[i] + r[j]);
		dijk.make_edge(i, j, d);
	}
	dijk.solve(N);
	printf("%.10lf",dijk.cost[N+1]);
	
	return 0;
}



Measured memory_bytes: 22404