import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.array;
import std.range;
import std.math;

double dist(P p1, P p2) {
    return max(0.0, sqrt(0.0 + (p1.x - p2.x) ^^ 2 + (p1.y - p2.y) ^^ 2) - p1.r - p2.r);
}
struct P {
    int x, y, r;
}
void main() {
    auto buf1 = readln.chomp.split.map!(a => a.to!int);
    int xs = buf1[0];
    int ys = buf1[1];
    int xt = buf1[2];
    int yt = buf1[3];
    int N = readln.chomp.to!int;

    P[] p;
    p ~= P(xs, ys, 0);
    foreach(i; 0 .. N) {
        auto buf2 = readln.chomp.split.map!(a => a.to!int);
        p ~= P(buf2[0], buf2[1], buf2[2]);
    }
    p ~= P(xt, yt, 0);

    double[][] total;
    foreach(i; 0 .. p.length) {
        total ~= new double[](p.length);
    }

    foreach(i; 0 .. p.length)
        foreach(j; 0 .. p.length)
            total[i][j] = dist(p[i], p[j]);

    
    foreach(k; 0 .. p.length)
        foreach(i; 0 .. p.length)
            foreach(j; 0 .. p.length)
                total[i][j] = min(total[i][j], total[i][k] + total[k][j]);
    
    writefln("%.10f", total[0][p.length-1]);
}
