import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

class Point{
	static int idcounter = 0;
	int id;
	int x, y;
	int r;
	real value;
	bool visited;
	real[int] distancemap;
	real distanceto(Point p){
		if(p.id in distancemap) return distancemap[p.id];
		else{
			real ans = sqrt(to!real((this.x - p.x) ^^ 2 + (this.y - p.y) ^^ 2)) - this.r - p.r;
			if(ans < 0) ans = 0;
			distancemap[p.id] = ans;
			return ans;
			}
		}
	this(int x, int y, int r){
		this.id = idcounter ++;
		this.x = x;
		this.y = y;
		this.r = r;
		}
	}

void main(){
	Point start, term;
	{
		int[] tmp = readln.chomp.split.map!(to!int).array;
		start = new Point(tmp[0], tmp[1], 0);
		term = new Point(tmp[2], tmp[3], 0);
		}
	int n = readln.chomp.to!int;
	Point[] ps = [start, term];
	for(int i = 0; i < n; i ++){
		int[] tmp = readln.chomp.split.map!(to!int).array;
		ps ~= new Point(tmp[0], tmp[1], tmp[2]);
		}
	
	start.value = 0.0;
	start.visited = true;
	Point newp = start;
	
	while(!term.visited){
		Point minp = term;
		foreach(p; ps){
			if(p.visited) continue;
			real v = newp.value + newp.distanceto(p);
			if(v !>= p.value) p.value = v;
			if(p.value !>= minp.value) minp = p;
			}
		newp = minp;
		newp.visited = true;
		}
	
	writefln("%#.12f", term.value);
	
	}



