// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<cmath>
#define INF 10000000000000
using namespace std;
typedef long long ll;
typedef pair<double,ll> P;
struct edge{
  ll to;
  double cost;
};
signed main(){
  double sx,sy,tx,ty;
  ll n;
  cin >> sx >> sy >> tx >> ty >> n;
  vector<edge> G[1100];
  double d[1100],dis;
  priority_queue<P,vector<P>,greater<P>> que;
  double x[n+2],y[n+2],r[n+2];
  x[0] = sx;
  y[0] = sy;
  x[n+1] = tx;
  y[n+1] = ty;
  for(int i=1;i<=n;i++){
    cin >> x[i] >> y[i] >> r[i];
  }
  for(int i=0;i<n+2;i++){
    for(int j=0;j<n+2;j++){
      if(i==j) continue;
      dis = max(0.0,sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2))-r[i]-r[j]);
      G[i].push_back({j,dis});
    }
  }
  fill(d,d+1100,INF);
  que.push(P(0,0));
  while(!que.empty()){
    P tmp = que.top();
    que.pop();
    ll nv = tmp.second;
    double dis = tmp.first;
    if(d[nv]<=dis){
      continue;
    }
    d[nv] = dis;
    for(auto v:G[nv]){
      que.push(P(v.cost+dis,v.to));
    }
  }
  printf("%.12lf\n",d[n+1]);
}
