#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define RREP(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define NL cerr << endl;

using namespace std;

typedef pair<double,int> P;
struct edge { int from, to; double cost; };
ostream& operator << (ostream& s, const edge& e) {
   s << "(" << e.from << "->" << e.to << ": " << e.cost << ")";
   return s;
}
bool operator< (const edge &edge1, const edge &edge2){
   return edge1.cost < edge2.cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

template<typename T>
void dijkstra(const vector< vector<edge> >& G, vector<T>& d, int s)
{
   priority_queue<P, vector<P>, greater<P> > que;
   fill(d.begin(), d.end(), INF);
   d[s] = 0;
   que.push(P(0, s));
   while(!que.empty()) {
      T temp_cost = que.top().first;
      int from = que.top().second;
      que.pop();
      if (d[from] < temp_cost) continue;
      for (int i = 0; i < G[from].size(); i++) {
         edge e = G[from][i];
         if (d[e.to] > d[from] + e.cost) {
            d[e.to] = d[from] + e.cost;
            que.push(P(d[e.to], e.to));
         }
      }
   }
}

template<typename T>
void add_edge(vector< vector<edge> >& G, int u, int v, T c) {
   G[u].push_back((edge){ u, v, c });
   G[v].push_back((edge){ v, u, c });
}

double dist(int dx, int dy, int r0, int r1) {
   return max(sqrt(dx*dx + dy*dy) - (r0 + r1), 0.);
}

signed main()
{
   int xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt;
   int N; cin >> N;
   vec<int> x(N+2), y(N+2), r(N+2,0);
   REP(i, 0, N) {
      cin >> x[i] >> y[i] >> r[i];
   }
   x[N] = xs; y[N] = ys;
   x[N+1] = xt; y[N+1] = yt;

   vec<vec<edge>> G(N+2);
   REP(i, 0, N+2) {
      REP(j, i+1, N+2) {
         add_edge(G, i, j, dist(x[i]-x[j], y[i]-y[j], r[i], r[j]));
      }
   }
   vec<double> d(N+2);
   dijkstra(G, d, N);

   printf("%.10Lf\n", d[N+1]);

   return 0;
}


Measured memory_bytes: 42732