Problem:
Score : 600 points

Problem Statement

On the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t).
He can move in arbitrary directions with speed 1.
Here, we will consider him as a point without size.

There are N circular barriers deployed on the plane.
The center and the radius of the i-th barrier are (x_i, y_i) and r_i, respectively.
The barriers may overlap or contain each other.

A point on the plane is exposed to cosmic rays if the point is not within any of the barriers.

Snuke wants to avoid exposure to cosmic rays as much as possible during the travel.
Find the minimum possible duration of time he is exposed to cosmic rays during the travel.

Constraints

All input values are integers.

-10^9 ≤ x_s, y_s, x_t, y_t ≤ 10^9

(x_s, y_s) ≠ (x_t, y_t)

1≤N≤1,000

-10^9 ≤ x_i, y_i ≤ 10^9

1 ≤ r_i ≤ 10^9

Input

The input is given from Standard Input in the following format:

x_s y_s x_t y_t
N
x_1 y_1 r_1
x_2 y_2 r_2
:
x_N y_N r_N

Output

Print the minimum possible duration of time Snuke is exposed to cosmic rays during the travel.
The output is considered correct if the absolute or relative error is at most 10^{-9}.

Sample Input 1

-2 -2 2 2
1
0 0 1

Sample Output 1

3.6568542495

An optimal route is as follows:

Sample Input 2

-2 0 2 0
2
-1 0 2
1 0 2

Sample Output 2

0.0000000000

An optimal route is as follows:

Sample Input 3

4 -2 -2 4
3
0 0 2
4 0 1
0 4 1

Sample Output 3

4.0000000000

An optimal route is as follows:

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Gosu_Hiroo
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, _begin, _end) for (__typeof(_end) end = _end, begin = _begin,  i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0, _len = (end); i < (_len); i += 1)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args,cerr); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define readint ({int t;cin >> t;t;})
#define fcout cout << fixed << setprecision(12)
#define fcerr cerr << fixed << setprecision(12)
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args, std::ostream& cerr) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}

template <typename T>
ostream& operator << (ostream& os, const vector<T> V) {
    for(auto v : V)os << v << ", ";
    return os;
}



template <typename T>
ostream& operator << (ostream& os, const set<T> V) {
    for(auto v : V)os << v << ", ";
    return os;
}

template <typename T>
ostream& operator << (ostream& os, const deque<T> V) {
    for(auto v : V)os << v << ", ";
    return os;
}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

//#define int ll

//const int maxV=114514;

class ECosmicRays {
public:
    struct Barrier{
        double x,y,r;
    }Barriers[1011];

    int shortest[1011];
//    int dist[1011][1011];
    template<typename T>
    struct wGraph{
        struct edge{
            int to;T cost;
            bool operator > (const edge R)const{
                return cost > R.cost;
            }
        };

     vector<vector<edge>> adj;
     vector<T> dist;
     int V;
     wGraph(int V): V(V), adj(V),dist(V){};

     void addEdge(int u, int v, T weight){
//         adj[u].emplace_back(v, weight);
            adj[u].push_back((edge){v, weight});
     }

        double dijkstra(int s){
            priority_queue<edge,vector<edge>,greater<edge> > que;
            for(int i=0;i<V;i++){dist[i] = INF;}
            dist[s]=0;
            que.push({s,0});
            while(!que.empty()){
                edge p = que.top();
                que.pop();
                int v = p.to;
                if(dist[v]<p.cost)continue;
                for(edge e : adj[v]){
                    if(dist[e.to] > dist[v] + e.cost){
                        dist[e.to] = dist[v] + e.cost;
                        que.push({e.to, dist[e.to]});
                    }
                }
            }
        };
    };
void solve(std::istream& cin, std::ostream& cout, std::ostream& cerr) {
    double xs,ys,xt,yt;
    cin >> xs >> ys >> xt >> yt;
    int N;
    cin >> N;
    Barriers[0] = {xs,ys,0};
    rep(i,1,N+1){
        cin >> Barriers[i].x >> Barriers[i].y >> Barriers[i].r;
    }
    Barriers[N+1]= {xt,yt,0};
    wGraph<double> G(N+2);
    _for(i,N+2)_for(j,N+2){
        double w = max(0., sqrt((Barriers[i].x - Barriers[j].x)*(Barriers[i].x - Barriers[j].x) +
                                  (Barriers[i].y - Barriers[j].y)*(Barriers[i].y - Barriers[j].y)) - Barriers[i].r - Barriers[j].r);
        G.addEdge(i, j, w);
//        G.addEdge(j, i, w);
    }

    G.dijkstra(0);
//    _for(i,N+2)error(G.adj[i])
    error(G.dist)
    fcout << G.dist[N+1] << endl;





}


};


#undef int
int main() {

	ECosmicRays solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
    std::ostringstream err;
	in.tie(0); ios::sync_with_stdio(0);
//	solver.solve(in, out);
    solver.solve(in, out,err);
	return 0;
}