#include<bits/stdc++.h>

using namespace std;

const int MAXN = 1005;
const double INF = 1e18;

int N;
double x[MAXN], y[MAXN], r[MAXN];
double dist[MAXN][MAXN];

double dis(double x1, double y1, double x2, double y2)
{
    return hypot(x1-x2, y1-y2);
}

int main()
{
    cin >> x[0] >> y[0] >> x[1] >> y[1] >> N;
    r[0] = r[1] = 0;
    for(int i=0; i<N ; ++i)
        cin >> x[2+i] >> y[2+i] >> r[2+i];

    for(int i=0 ; i<N+2 ; ++i)
    {
        for(int j=0 ; j<N+2 ; ++j)
        {
            dist[i][j] = 0;
            if(i!=j)
            {
                double d = dis(x[i], y[i], x[j], y[j]);
                if(d > r[i]+r[j])
                {
                    dist[i][j] = d - r[i] - r[j];
                }
            }
        }
    }

    double d[MAXN];
    bool isInQ[MAXN];

    for(int i=0 ; i<MAXN ; ++i)
    {
        d[i] = INF;
        isInQ[i] = false;
    }

    d[0] = 0;
    queue<int> Q;
    Q.push(0);
    isInQ[0] = true;

    while(!Q.empty())
    {
        int cur = Q.front();
        Q.pop();
        isInQ[cur] = false;
        for(int i=0 ; i<2+N ; ++i)
        {
            if(i!=cur)
            {
                if(d[cur]+dist[cur][i] < d[i])
                {
                    d[i] = d[cur]+dist[cur][i];
                    if(!isInQ[i])
                    {
                        Q.push(i);
                        isInQ[i] = true;
                    }
                }
            }
        }
    }

    cout  << fixed  <<  setprecision(9) << d[1] << '\n';

    return 0;
}
