/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.2.0"
+/

import std.stdio, std.datetime, std.range, std.algorithm, std.conv;
import std.complex;
import std.typecons;

// import dcomp.scanner;
// import dcomp.graph.dijkstra;


alias R = double;
alias P = Complex!R;

alias Edge = Tuple!(int, "to", R, "dist");


int main(string[] argv) {
    auto sc = new Scanner();
    P sp, tp;
    sc.read(sp.re, sp.im);
    sc.read(tp.re, tp.im);
    int n;
    sc.read(n);
    P[] points = new P[](n+2);
    R[] r = new R[](n+2);
    points[n] = sp;
    points[n+1] = tp;
    r[n] = r[n+1] = 0;
    foreach (i; 0..n) {
        sc.read(points[i].re, points[i].im, r[i]);
    }
    Edge[][] g = new Edge[][](n+2, n+2);
    foreach (i; 0..n+2) {
        foreach (j; 0..n+2) {
            g[i][j].to = j;
            R di = abs(points[i]-points[j]);
            g[i][j].dist = max(R(0), di - r[i] - r[j]);
        }
    }
/*    writeln(points);
    writeln(r);
    writeln(g);
    writeln(g.dijkstra!R(n, 1e12));*/
    writefln("%.15f", g.dijkstraDense!R(n, 1e12).dist[n+1]);
    return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File, stdin;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f = stdin) {
        this.f = f;
    }
    string[] buf;
    private bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = f.readln.split;
        }
        return true;
    }
    private bool readSingle(T)(ref T x) {
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                //string or char[10] etc
                x = buf.front;
                buf.popFront;
            } else {
                static if (isStaticArray!T) {
                    //static
                    assert(buf.length == T.length);
                }
                x = buf.map!(to!E).array;
                buf.length = 0;                
            }
        } else {
            x = buf.front.to!T;
            buf.popFront;            
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

unittest {
    import std.path : buildPath;
    import std.file : tempDir;
    import std.algorithm : equal;
    import std.stdio : File;
    string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
    auto fout = File(fileName, "w");
    fout.writeln("1 2 3");
    fout.writeln("ab cde");
    fout.writeln("1.0 1.0 2.0");
    fout.close;
    Scanner sc = new Scanner(File(fileName, "r"));
    int a;
    int[2] b;
    char[2] c;
    string d;
    double e;
    double[] f;
    sc.read(a, b, c, d, e, f);
    assert(a == 1);
    assert(equal(b[], [2, 3]));
    assert(equal(c[], "ab"));
    assert(equal(d, "cde"));
    assert(e == 1.0);
    assert(equal(f, [1.0, 2.0]));
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */
// module dcomp.algorithm;

//[0,0,0,...,1,1,1]で、初めて1となる場所を探す。pred(l) == 0, pred(r) == 1と仮定
T binSearch(alias pred, T)(T l, T r) {
    while (r-l > 1) {
        T md = (l+r)/2;
        if (!pred(md)) l = md;
        else r = md;
    }
    return r;
}

import std.range.primitives;

Rotator!Range rotator(Range)(Range r)
if (isForwardRange!Range && hasLength!Range) {
    return typeof(return)(r);
}

struct Rotator(Range)
if (isForwardRange!Range && hasLength!Range) {
    size_t cnt;
    Range start, now;
    this(Range r) {
        cnt = 0;
        start = r.save;
        now = r.save;
    }
    this(this) {
        start = start.save;
        now = now.save;
    }
    @property bool empty() {
        return now.empty;
    }
    @property auto front() {
        assert(!now.empty);
        import std.range : take, chain;
        return chain(now, start.take(cnt));
    }
    @property Rotator!Range save() {
        return this;
    }
    void popFront() {
        cnt++;
        now.popFront;
    }
}

ElementType!Range minimum(alias pred = "a < b", Range)(Range range)
if (isInputRange!Range && !isInfinite!Range) {
    import std.functional;
    assert(!range.empty, "range must not empty");
    auto e = range.front; range.popFront;
    while (!range.empty) {
        if (binaryFun!pred(range.front, e)) {
            e = range.front;
        }
        range.popFront;
    }
    return e;
}

E minimum(alias pred = "a < b", Range, E = ElementType!Range)(Range range, E seed)
if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, E) == void)) {
    import std.functional;
    while (!range.empty) {
        if (binaryFun!pred(range.front, seed)) {
            seed = range.front;
        }
    }
    return seed;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/graph/dijkstra.d */
// module dcomp.graph.djikstra;

// import dcomp.algorithm;

struct Dijkstra(T) {
    T[] dist;
}

Dijkstra!D dijkstra(D, T)(T g, size_t s, D inf = D.max) {
    import std.typecons : Tuple;
    import std.container : make, Array, heapify;

    size_t V = g.length;
    Dijkstra!D dijk;
    with (dijk) {
        dist = new D[](V); dist[] = inf;
        
        alias P = Tuple!(size_t, "to", D, "dist");
        auto q = heapify!"a.dist>b.dist"(make!(Array!P)([P(s, D(0))]));

        dist[s] = D(0);
        while (!q.empty) {
            P p = q.front; q.popFront();
            if (dist[p.to] < p.dist) continue;
            foreach (e; g[p.to]) {
                if (p.dist+e.dist < dist[e.to]) {
                    dist[e.to] = p.dist+e.dist;
                    q.insert(P(e.to, dist[e.to]));
                }
            }
        }
    }
    return dijk;
}

Dijkstra!D dijkstraDense(D, T)(T g, size_t s, D inf = D.max) {
    import std.typecons : Tuple;
    import std.container : make, Array, heapify;
    import std.range : enumerate;
    import std.algorithm : filter;

    size_t V = g.length;
    Dijkstra!D dijk;
    with (dijk) {
        dist = new D[](V); dist[] = inf;
        
        alias P = Tuple!(size_t, "to", D, "dist");

        bool[] used = new bool[](V);
        dist[s] = D(0);
        while (true) {
            auto rng = dist.enumerate.filter!(a => !used[a.index]);
            if (rng.empty) break;
            auto nx = rng.minimum!"a.value < b.value";
            used[nx.index] = true;
            P p = P(nx.index, nx.value); 
            if (dist[p.to] < p.dist) continue;
            foreach (e; g[p.to]) {
                if (p.dist+e.dist < dist[e.to]) {
                    dist[e.to] = p.dist+e.dist;
                }
            }
        }
    }
    return dijk;
}


Measured memory_bytes: 16508