#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


struct circle {
  ld x, y, r;
  circle(ld x, ld y, ld r) : x(x), y(y), r(r) {}
};

ld dist(circle &a, circle &b) {
  ld res = sqrt(pow(a.x-b.x, 2) + pow(a.y-b.y, 2)) - (a.r + b.r);
  return (res > 0) ? res : 0;
}


template<typename T>
struct edge {
  int v; T w;
  edge(int v, T w) : v(v), w(w) {}
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using Graph = vector<Edges<T>>;


template<typename T>
vector<T> dijkstra(Graph<T> &G, int s) {
  const auto INF = numeric_limits<T>::max();
  vector<T> dist(G.size(), INF);

  using PTi = pair<T, int>;
  priority_queue<PTi, vector<PTi>, greater<PTi>> pq;
  dist[s] = 0;
  pq.emplace(dist[s], s);

  while (!pq.empty()) {
    T cost; int u;
    tie(cost, u) = pq.top(); pq.pop();
    if (dist[u] < cost) continue;
    for (auto &e : G[u]) {
      auto n_cost = cost + e.w;
      if (dist[e.v] <= n_cost) continue;
      dist[e.v] = n_cost;
      pq.emplace(dist[e.v], e.v);
    }
  }
  return dist;
}


int main() {
  vector<circle> C;
  ld x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  C.emplace_back(x1, y1, 0);
  C.emplace_back(x2, y2, 0);

  ll n; cin >> n;
  rep(i, n) {
    ld x, y, r; cin >> x >> y >> r;
    C.emplace_back(x, y, r);
  }

  Graph<ld> G(n+2, Edges<ld>());
  rep(i, n+2) rep(j, n+2) {
    if (i == j) continue;
    G[i].emplace_back(j, dist(C[i], C[j]));
    G[j].emplace_back(i, dist(C[i], C[j]));
  }

  auto d = dijkstra(G, 0);
  cout << d[1] << endl;
  return 0;
}


Measured memory_bytes: 75504