#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

double dist(int x1, int y1, int x2, int y2) {
  return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

void solve() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int n;
  cin >> n;
  using T = tuple<int, int, int>;
  vector<T> xyr;
  rep(i, n) {
    int x, y, r;
    cin >> x >> y >> r;
    xyr.emplace_back(x, y, r);
  }
  vector<vector<pair<int, double>>> g(n + 2);
  {
    double d = dist(sx, sy, tx, ty);
    g[0].emplace_back(n + 1, d);
    g[n + 1].emplace_back(0, d);
  }
  reps(i, n) {
    int x, y, r;
    tie(x, y, r) = xyr[i - 1];
    double d = max(0.0, dist(sx, sy, x, y) - r);
    g[0].emplace_back(i, d);
    g[i].emplace_back(0, d);
  }
  rep(i, n) {
    int x, y, r;
    tie(x, y, r) = xyr[i];
    double d = max(0.0, dist(tx, ty, x, y) - r);
    g[n + 1].emplace_back(i + 1, d);
    g[i + 1].emplace_back(n + 1, d);
  }
  rep(i, n) rep(j, i) {
    int x1, y1, r1;
    int x2, y2, r2;
    tie(x1, y1, r1) = xyr[i];
    tie(x2, y2, r2) = xyr[j];
    double d = max(0.0, dist(x1, y1, x2, y2) - r1 - r2);
    g[i + 1].emplace_back(j + 1, d);
    g[j + 1].emplace_back(i + 1, d);
  }
  using S = tuple<double, int>;
  vector<double> dp(n + 2, 1e18);
  pqasc<S> q;
  q.emplace(0, 0);
  while (sz(q)) {
    double d;
    int u;
    tie(d, u) = q.top(), q.pop();
    if (dp[u] != 1e18) {
      continue;
    }
    dp[u] = d;
    each(p, g[u]) {
      int v;
      double cost;
      tie(v, cost) = p;
      q.emplace(d + cost, v);
    }
  }
  cout << dp[n + 1] << endl;
}

Measured memory_bytes: 34812