#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

using Weight = double;
using Data = pair<Weight,int>;

Weight INF = 1e18;

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

namespace bit {
template <typename Tp>
int log2p1(Tp n) {
  if (n == 0) return 0;
  return (CHAR_BIT * sizeof(long long)) - __builtin_clzll(n);
}
}  // bit::

// enable reduce
struct Heap {
  shared_ptr<Heap> l,r,p;
  Data val;
  Heap(Data v) : val(v) {}
  Data top() { return val; }
};
shared_ptr<Heap> meld(
    shared_ptr<Heap> a, shared_ptr<Heap> b, shared_ptr<Heap> p = nullptr) {
  if (!a) {
    if (b) b->p = p;
    return b;
  }
  if (!b) {
    if (a) a->p = p;
    return a;
  }
  if (a->val > b->val) swap(a, b);
  a->p = p;
  a->r = meld(a->r, b, a);
  swap(a->l, a->r);
  return a;
}
pair<shared_ptr<Heap>, shared_ptr<Heap>> push(shared_ptr<Heap> h, Data v) {
  auto n = make_shared<Heap>(v);
  return make_pair(meld(h, n), n);
}
shared_ptr<Heap> pop(shared_ptr<Heap> h) {
  if (h->l) h->l->p.reset();
  if (h->r) h->r->p.reset();
  return meld(h->l, h->r);
}
shared_ptr<Heap> reduce(shared_ptr<Heap> h, shared_ptr<Heap> root, Data v) {
  if (v > h->val) return root;
  h->val = v;
  if (!h->p) return root;
  if (h->val < h->p->val) {
    if (h->p->l && h->p->l == h) {
      h->p->l.reset();
      return meld(h, root);
    } else {
      h->p->r.reset();
      return meld(h, root);
    }
  } else return root;
}

class SkewHeap {
 public:
  using node_handle = int;
  SkewHeap(size_t sz) : nodes(sz) {}
  const Data& top() const { return root->val; }
  void pop() {
    int id = top().second;
    root = ::pop(root);
    nodes[id].reset();
  }
  node_handle push(const Data& data) {
    auto p = ::push(root, data);
    tie(root, nodes[data.second]) = p;
    return data.second;
  }
  void prioritize(const node_handle& id, const Weight key) {
    auto p = nodes[id];
    root = reduce(p, root, Data(key, id));
  }
  bool empty() const { return root == nullptr; }
  bool expired(const node_handle& id) const {
    return id < 0 || nodes[id] != nullptr;
  }
 private:
  shared_ptr<Heap> root;
  std::vector<shared_ptr<Heap>> nodes;
};

template <typename WeightType>
class weighted_edge {
public:
  using size_type = size_t;
  using weight_type = WeightType;

protected:
  size_type M_src, M_dst;
  weight_type M_weight;

public:
  weighted_edge() = default;
  weighted_edge(weighted_edge const&) = default;
  weighted_edge(weighted_edge&&) = default;

  weighted_edge(size_type s, size_type d, weight_type w):
    M_src(s), M_dst(d), M_weight(w)
  {}

  weighted_edge& operator =(weighted_edge const&) = default;
  weighted_edge& operator =(weighted_edge&&) = default;

  bool operator <(weighted_edge const& other) const {
    if (M_weight < other.M_weight) return true;
    if (other.M_weight < M_weight) return false;
    if (M_src != other.M_src) return M_src < other.M_src;
    return M_dst < other.M_dst;
  }

  size_type source() const { return M_src; }
  size_type target() const { return M_dst; }
  weight_type weight() const { return M_weight; }
};

struct directed_tag {};
struct undirected_tag {};

template <typename Edge, typename Directedness>
class adjacency_list {
public:
  using size_type = size_t;
  using edge_type = Edge;
  using weight_type = typename Edge::weight_type;
  static constexpr weight_type inf = std::numeric_limits<weight_type>::max();

private:
  std::vector<std::vector<edge_type>> M_g;

public:
  adjacency_list() = default;
  adjacency_list(adjacency_list const&) = default;
  adjacency_list(adjacency_list&&) = default;
  adjacency_list(size_type n): M_g(n) {}

  template <typename... Args>
  void emplace(size_type src, size_type dst, Args... args) {
    M_g[src].emplace_back(src, dst, args...);
    if (std::is_same<Directedness, undirected_tag>::value)
      M_g[dst].emplace_back(dst, src, args...);
  }

  size_type size() const { return M_g.size(); }
  std::vector<edge_type> const& operator [](size_type i) const { return M_g[i]; }
};

template <typename Edge, typename Directedness>
constexpr typename Edge::weight_type adjacency_list<Edge, Directedness>::inf;

struct dijkstra_tag {} dijkstra;

template <typename Edge, typename Directedness>
auto shortest(adjacency_list<Edge, Directedness> const& g, size_t s, dijkstra_tag) {
  using weight_type = typename Edge::weight_type;
  size_t n = g.size();
  std::vector<weight_type> dp(n, g.inf);
  dp[s] = weight_type(0);
  using heap = SkewHeap;
  heap fh(n);
  fh.push(Data(weight_type(0), s));
  std::vector<typename heap::node_handle> nh(n, -1);
  while (!fh.empty()) {
    weight_type w;
    size_t v;
    std::tie(w, v) = fh.top();
    fh.pop();
    if (dp[v] < w) continue;
    for (auto const& e: g[v]) {
      weight_type nw = dp[e.source()] + e.weight();
      size_t nv = e.target();
      if (nw < dp[nv]) {
        dp[nv] = nw;
        if (fh.expired(nh[nv])) {
          nh[nv] = fh.push(Data(nw, nv));
        } else {
          fh.prioritize(nh[nv], nw);
        }
      }
    }
  }
  return dp;
}
  

int main() {
  double xs, ys, xt, yt;
  scanf("%lf %lf %lf %lf", &xs, &ys, &xt, &yt);

  size_t n;
  scanf("%zu", &n);

  std::vector<std::pair<std::complex<double>, double>> c(n);
  for (auto& ci: c) {
    double x, y, r;
    scanf("%lf %lf %lf", &x, &y, &r);

    std::complex<double> z(x, y);
    ci = std::make_pair(z, r);
  }
  c.emplace_back(std::complex<double>(xs, ys), 0.0);
  c.emplace_back(std::complex<double>(xt, yt), 0.0);
  n += 2;

  adjacency_list<weighted_edge<double>, undirected_tag> g(n);
  for (size_t i = 0; i < n; ++i) {
    std::complex<double> zi;
    double ri;
    std::tie(zi, ri) = c[i];
    for (size_t j = 0; j < i; ++j) {
      std::complex<double> zj;
      double rj;
      std::tie(zj, rj) = c[j];

      double w = std::max(0.0, std::abs(zi-zj) - (ri+rj));
      g.emplace(i, j, w);
    }
  }

  printf("%.12f\n", shortest(g, n-2, dijkstra)[n-1]);
}


Measured memory_bytes: 48000