#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

//library
#define  EPS (1e-10)
#define equal(a, b) (fabs((a) - (b)) < EPS)


class Point {
public:
	double x,y;
	
	Point(double x = 0,double y = 0): x(x), y(y) {}
	
	Point operator+ (const Point &p) { return Point(x + p.x, y + p.y); }
	Point operator- (const Point &p) { return Point(x - p.x, y - p.y); }
	Point operator* (double k) { return Point(x * k, y * k); }
	Point operator/ (double k) { return Point(x / k, y / k); }
	void operator+= (const Point &p) { x += p.x; y += p.y; }

	double norm() { return x*x + y*y; }
	double abs() { return sqrt(norm()); }

	bool operator< (const Point &p) const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator> (const Point &p) const {
		return x != p.x ? x > p.x : y > p.y;
	}

	bool operator== (const Point &p) const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}

	bool operator!= (const Point &p) const {
		return !(Point(x,y) == p);
	}
};
typedef Point Vector;

class Segment {
public:
	Point p1, p2;
	Segment(Point p1 = Point(0,0), Point p2 = Point(0,0)): p1(p1), p2(p2) {}
};
typedef Segment Line;

class Circle {
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0): c(c), r(r) {};
};
typedef vector<Point> Polygon;


double norm(Vector a);
double abs(Vector a);
double dot(Vector a, Vector b);
double cross(Vector a, Vector b);
bool isParallel(Vector v1, Vector v2);
bool isOrthogonal(Vector v1, Vector v2);
bool isParallel(Segment s1, Segment s2) ;
bool isOrthogonal(Segment s1, Segment s2);
Vector project(Vector v1, Vector v2);
Point project(Line s, Point p);
Point reflect(Line l, Point p);
double getDistance(Point a, Point b);
double getDistanceLP(Line l, Point p);
double getDistance(Segment a, Point b);
int ccw(Point p0, Point p1, Point p2);
bool intersect(Point p0, Point p1, Point p2, Point p3);
bool intersect(Segment a, Segment b);
bool intersect(Circle c, Line s);
bool intersect(Circle a, Circle b);
double getDistance(Segment a, Segment b);
pair<Point, Point> getCrossPoints(Circle c, Line l);


double norm(Vector a) {
	return a.x*a.x + a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y ;
}

double cross(Vector a, Vector b) {
	return a.x*b.y - a.y*b.x;
}

bool isParallel(Vector v1, Vector v2) {
	return equal(cross(v1, v2), 0.0);
}

bool isOrthogonal(Vector v1, Vector v2) {
	return equal(dot(v1, v2), 0.0);
}

bool isParallel(Segment s1, Segment s2) {
	return equal(cross(s1.p1 - s1.p2, s2.p1 - s2.p2), 0.0);
}

bool isOrthogonal(Segment s1, Segment s2) {
	return equal(dot(s1.p1 - s1.p2, s2.p1 - s2.p2), 0);
}

Vector project(Vector v1, Vector v2){
	return v1 * (dot(v1, v2) / v1.norm());
}

Point project(Line s, Point p){
	return project(s.p2 - s.p1, p - s.p1) + s.p1;
}

Point reflect(Line l, Point p){
	return (project(l, p) - p) * 2 + p;
}

double getDistance(Point a, Point b) {
	return (a-b).abs();
}

double getDistanceLP(Line l, Point p) {
	return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1));
}

double getDistance(Segment a, Point b) {
	if(dot(a.p2 - a.p1, b - a.p1) < 0)	return (b - a.p1).abs();
	if(dot(a.p1 - a.p2, b - a.p2) < 0)	return (b - a.p2).abs();
	return getDistanceLP(a, b);
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_FRONT = 2;
static const int ONLINE_BACK  = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2) {
	Vector a = p1 - p0;
	Vector b = p2 - p0;
	if(cross(a,b) > EPS)	return COUNTER_CLOCKWISE;
	if(cross(a,b) < -EPS)	return CLOCKWISE;
	if(dot(a,b) < -EPS)	return ONLINE_BACK;
	if(a.norm() < b.norm())	return ONLINE_FRONT;
	return ON_SEGMENT;
}

bool intersect(Point p0, Point p1, Point p2, Point p3){
	return ccw(p0,p1,p2)*ccw(p0,p1,p3) <= 0 && ccw(p2,p3,p0)*ccw(p2,p3,p1) <= 0;
}

bool intersect(Segment a, Segment b){
	return intersect(a.p1, a.p2, b.p1, b.p2);
}

bool intersect(Circle c, Line s){
	return getDistance(s, c.c)-c.r < EPS;
}

bool intersect(Circle a, Circle b){
	return getDistance(a.c, b.c) < a.r+b.r+EPS;
}

double getDistance(Segment a, Segment b) {
	if(intersect(a, b))	return 0;
	else	return min({getDistance(a, b.p1), getDistance(a, b.p2), getDistance(b, a.p1), getDistance(b, a.p2)});
}

Point getCrossPoint(Segment s1, Segment s2){
	Vector base = s2.p2-s2.p1;
	double d1 = abs(cross(base, s1.p1-s2.p1));
	double d2 = abs(cross(base, s1.p2-s2.p1));
	double t = d1/(d1+d2);
	return s1.p1+(s1.p2-s1.p1)*t;
}

pair<Point, Point> getCrossPoints(Circle c, Line l){
	assert(intersect(c,l));
	Vector pr = project(l, c.c);
	Vector e = (l.p2 - l.p1) / abs(l.p2 - l.p1);
	double base = sqrt(c.r*c.r - norm(pr - c.c));
	return make_pair(pr + e*base, pr - e*base);
}

double arg(Vector p) { return atan2(p.y, p.x); }
Vector polar(double a, double r){ return Point(cos(r)*a, sin(r)*a); }

pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
	assert(intersect(c1, c2));
	double d = abs(c1.c-c2.c);
	double a = acos((c1.r * c1.r + d * d - c2.r * c2.r)/(2 * c1.r * d));
	double t = arg(c2.c - c1.c);
	return make_pair(c1.c+polar(c1.r, t+a), c1.c+polar(c1.r, t-a));
}

//library

//library
class uftree {
//private:
public:
	int *par;
	int *rank;
	int *num;

//public:
	uftree(int n)
	{
		par = new int[n];
		rank = new int[n];
		num = new int[n];
		for(int i = 0; i < n; i++){
			par[i] = i;
			rank[i] = 0;
			num[i] = 1;
		}
	}

	~uftree()
	{
		delete[] par;
		delete[] rank;
		delete[] num;
	}

	int find(int x)
	{
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			num[y] += num[x];
		}else{
			par[y] = x;
			num[x] += num[y];
			if(rank[x] == rank[y])	rank[x]++;
		}
	}

	int count(int x)
	{
		return num[find(x)];
	}

	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};
//library

//library
typedef double cost_t;

class Edge {
public:
	int to;
	cost_t cost;
	
	Edge(){
	}

	Edge(int x,cost_t y){
		to = x;
		cost = y;
	}

	bool operator< (const Edge& x) const {
		if(cost != x.cost) return cost < x.cost;
		return to < x.to;
	}

	bool operator> (const Edge& x) const {
		if(cost != x.cost) return cost > x.cost;
		return to > x.to;
	}
};

class Graph {
private:
	//const long long int INF = (long long)1e18;
	vector<vector<Edge> > v; 
	int n;
public:
	Graph(int x){
		n = x;
		v = vector<vector<Edge> >(x);
	}

	vector<Edge>& operator[](int x){
		return v[x];
	}

	const vector<Edge>& operator[](int x) const {
		return v[x];
	}

	int size() const {
		return n;
	}

	void add_edge(int from, Edge e){
		v[from].push_back(e);
	}

	void add_edge(int from, int to, cost_t cost){
		add_edge(from,Edge(to,cost));
	}

	void add_uedge(int from, int to, cost_t cost){
		add_edge(from,to,cost);
		add_edge(to,from,cost);
	}
};

vector<cost_t> dijkstra(int from, const Graph& v)
{
	vector<cost_t> dist(v.size(),INF);
	priority_queue<Edge,vector<Edge>,greater<Edge>> que;
	que.push(Edge(from,0));
	while(!que.empty()){
		Edge e = que.top();
		que.pop();
		if(dist[e.to] == INF){
			dist[e.to] = e.cost;
			for(auto to : v[e.to]){
				if(dist[to.to] == INF)
					que.push(Edge(to.to, e.cost+to.cost));
			}
		}
	}
	return dist;
}

vector<cost_t> bellmanford(int from, const Graph& g)
{
	vector<cost_t> res(g.size(),INF);
	res[from] = 0;
	bool conf = true;
	int cnt = 0;
	while(conf){
		conf = false;
		for(int i = 0; i < g.size(); i++){
			if(res[i] != INF)
			for(const auto& e : g[i]){
				if(res[e.to] > res[i]+e.cost){
					conf = true;
					res[e.to] = res[i]+e.cost;
				}
			}
		}
		if(cnt > g.size()+5) return vector<cost_t>();
		cnt++;
	}
	return res;
}

Graph prim(const Graph g)
{
	using T = tuple<cost_t, int, int>;
	priority_queue<T, vector<T>, greater<T>> qu;
	int n = g.size();
	assert(n != 0);
	vector<bool> added(n,false);
	qu.emplace(0,0,0);
	Graph res(n);
	while(!qu.empty()){
		int from, to;
		cost_t cost;
		tie(cost, from, to) = qu.top();
		qu.pop();
		if(!added[to]){
			added[to] = true;
			res.add_edge(from, to, cost);
			res.add_edge(to, from, cost);
			for(const auto &e : g[to]){
				if(!added[e.to]){
					qu.emplace(e.cost, to, e.to);
				}
			}
		}
	}
	return res;
}

vector<int> tree_getorder(const Graph &g, int root)
{
	vector<int> res;
	function<void(int p, int pre)> func = [&](int p, int pre){
		for(auto &e : g[p]){
			if(e.to != pre){
				func(e.to,p);
			}
		}
		res.push_back(p);
	};
	func(root,-1);
	return res;
}

vector<int> tree_getpar(const Graph &g, int root)
{
	vector<int> par(g.size(),root);
	function<void(int p, int pre)> func = [&](int p, int pre){
		par[p] = pre;
		for(auto &e : g[p]){
			if(e.to != pre){
				func(e.to,p);
			}
		}
	};
	func(root,root);
	return par;
}


//未検証
vector<int> toposort(const Graph &g, int start)
{
	int n = g.size();
	vector<int> res;
	res.reserve(n);
	vector<bool> used(n,false);
	function<void(int)> rec = [&](int p){
		if(used[p]) return;
		used[p] = true;
		for(auto&& e : g[p]) {
			rec(e.to);
		}
		res.push_back(p);
	};
	rec(start);
	return res;
}

//liblary

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	cout.setf(ios::fixed);
	cout.precision(15);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	Point sp, st;
	while(cin >> sp.x >> sp.y >> st.x >> st.y){
		int n;
		cin >> n;
		n += 2;
		vector<Circle> vc(n);
		REP(i,n-2){
			cin >> vc[i].c.x >> vc[i].c.y >> vc[i].r;
		}
		vc[n-2] = Circle(sp,0);
		vc[n-1] = Circle(st,0);
		vector<vector<double>> d(n,vector<double>(n));
		REP(i,n){
			REP(j,i){
				d[i][j] = abs(vc[i].c-vc[j].c)-(vc[i].r+vc[j].r);
			}
		}
		REP(i,n) dpite(ALL(d[i]));
		Graph g(n);
		REP(i,n){
			REP(j,i){
				if(d[i][j] < EPS){
					d[i][j] = 0;
				}
				DEBUG(i); DEBUG(j); DEBUG(d[i][j]);
				g.add_uedge(i,j,d[i][j]);
			}
		}
		auto res = dijkstra(n-2,g);
		dpite(ALL(res));
		cout << res[n-1] << endl;
	}
	return 0;
}


Measured memory_bytes: 32620