#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

template <typename _Tp>
struct fibonacci_heap
{
    struct Node
    {
        _Tp val;
        int deg;
        Node *parent, *left, *right, *child;
        bool mark;
        Node() = default;
        Node(Node const &) = default;
        Node(Node &&) = default;
        Node &operator=(Node const &) = default;
        Node &operator=(Node &&) = default;
        Node(_Tp v) : val(v), deg(0), parent(nullptr), left(nullptr), right(nullptr), child(nullptr), mark(false) {}
        friend std::ostream &operator<<(std::ostream &os, const Node &n)
        {
            os << '(' << n.val << ',';
            if (n.child != nullptr) os << *(n.child) << ',';
            Node *now = n.right;
            while (now != &n)
            {
                os << now->val << ',';
                if (now->child != nullptr) os << *now->child  << ',';
                now = now->right;
            }
            os << ')';
            return os;
        }
    };

    int sz;
    std::list<Node*> roots;
    Node *ptop;
    inline void _chmin(Node *cand) noexcept
    {
        if (ptop == nullptr or cand->val < ptop->val) ptop = cand;
    }
    fibonacci_heap() : sz(0), roots({}), ptop(nullptr) {}

    bool empty() const noexcept { return sz == 0; }
    int size() const noexcept { return sz; }

    void _consolidate()
    {
        std::array<Node *, 30> arr;
        arr.fill(nullptr);

        auto fmerge = [&](auto &&func, Node *ptr) -> void {
            int d = ptr->deg;
            if (arr[d] == nullptr) arr[d] = ptr;
            else
            {
                Node *cptr = arr[d];
                if (cptr->val < ptr->val) std::swap(ptr, cptr);
                ptr->deg++;
                cptr->parent = ptr;
                if (ptr->child == nullptr) ptr->child = cptr;
                else
                {
                    Node *cl = ptr->child, *cr = ptr->child->right;
                    assert(cl->right == cr and cr->left == cl);
                    cptr->left = cl, cptr->right = cr, cl->right = cr->left = cptr;
                }
                arr[d] = nullptr;
                func(func, ptr);
            }
        };
        for (auto ptr : roots) if (ptr != nullptr) {
            if (ptr->deg < 0) delete ptr;
            else fmerge(fmerge, ptr);
        }
        roots.clear(), ptop = nullptr;
        for (auto ptr : arr) if (ptr != nullptr) _add_tree(ptr);
    }

    void _add_tree(Node *root) noexcept
    {
        root->parent = nullptr;
        root->left = root->right = root;
        roots.emplace_back(root);
        _chmin(root);
    }

    Node *push(const _Tp &val) noexcept
    {
        sz++;
        Node *ptr = new Node(val);
        _add_tree(ptr);
        return ptr;
    }

    void meld(fibonacci_heap &&hp)
    {
        sz += hp.sz;
        if (ptop == nullptr) ptop = hp.ptop;
        else if (hp.ptop != nullptr) ptop = ptop->val < hp.ptop->val ? ptop : hp.ptop;
        roots.splice(roots.end(), hp.roots);
    }

    void pop()
    {
        assert(sz > 0);
        sz--;
        Node* ch1 = ptop->child;
        if (ch1 != nullptr)
        {
            Node *now = ch1;
            while (true)
            {
                Node *nxt = now->right;
                _add_tree(now);
                now = nxt;
                if (now == ch1) break;
            }
        }
        ptop->deg = -1;
        _consolidate();
    }

    void _cut(Node *x) noexcept
    {
        Node *y = x->parent;
        assert(y != nullptr and y->deg > 0);
        Node *xr = x->right, *xl = x->left;
        if (x == xr)
        {
            y->child = nullptr;
        }
        else
        {
            y->child = xr;
            xl->right = xr, xr->left = xl;
        }
        y->deg--;
        _add_tree(x);
        x->mark = false;
    }
    void _cascading_cut(Node *now) noexcept
    {
        assert(now != nullptr);
        Node *par = now->parent;
        if (par == nullptr) return;
        if (!now->mark) now->mark = true;
        else
        {
            _cut(now);
            _cascading_cut(par);
        }
    }
    bool decrease(Node *r, const _Tp new_val)
    {
        assert(r != nullptr);
        if (!(new_val < r->val)) return false;
        r->val = new_val;
        if (r->parent != nullptr and new_val < r->parent->val) {
            Node *rpar = r->parent;
            _cut(r);
            _cascading_cut(rpar);
        }
        _chmin(r);
        return true;
    }
    _Tp top() const
    {
        assert(ptop != nullptr);
        return ptop->val;
    }
    friend std::ostream &operator<<(std::ostream &os, const fibonacci_heap &hp) {
        os << "[(fibonacci_heap: sz=" << hp.sz << ", top=" << hp.ptop->val << ", #tree = " << hp.roots.size() << ")";
        for (auto x : hp.roots)
        {
            os << *x << ", ";
        }
        os << ']';
        return os;
    }
};

int main()
{
    int N;
    vector<int> X(2), Y(2), R(2);
    cin >> X[0] >> Y[0] >> X[1] >> Y[1] >> N;
    N += 2;
    X.resize(N), Y.resize(N), R.resize(N);
    FOR(i, 2, N) cin >> X[i] >> Y[i] >> R[i];

    using P = pair<double, int>;
    fibonacci_heap<P> heap;
    vector<fibonacci_heap<P>::Node *> pv(N);

    vector<double> D(N, 1e18);
    D[0] = 0.0;

    REP(i, N)
    {
        pv[i] = heap.push(make_pair(D[i], i));
    }
    while (heap.size())
    {
        int now = heap.top().second;
        heap.pop();
        REP(nxt, N)
        {
            double dist = max(sqrt(1LL * (X[nxt] - X[now]) * (X[nxt] - X[now]) + 1LL * (Y[nxt] - Y[now]) * (Y[nxt] - Y[now])) - R[now] - R[nxt], 0.0);
            if (chmin(D[nxt], D[now] + dist)) heap.decrease(pv[nxt], P(D[nxt], nxt));
        }
    }
    cout << D[1] << '\n';
}


Measured memory_bytes: 512