stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <algorithm>

#include <string>

#include <sstream>

#include <complex>

#include <vector>

#include <list>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

using namespace std;

typedef long long unsigned int ll;



#define EPS (1e-7)

#define INF (1e9)

#define PI (acos(-1))

const long double zero = 0.0;

ll x[1010], y[1010], r[1010];

long double dist(int i, int j)

{

    ll dx = (x[i] - x[j]);

    ll dy = y[i] - y[j];

    return pow((long double)(dx * dx + dy * dy), 0.5);

}



int main() {

    cout.precision(100);

    ll xs, ys, xt, yt;

    cin >> xs >> ys >> xt >> yt;

    int n;

    cin >> n;

    for(int i = 1; i <= n; i++){

        cin >> x[i] >> y[i] >> r[i];

    }

    x[0] = xt;

    y[0] = yt;

    r[0] = 0;

    x[n + 1] = xs;

    y[n + 1] = ys;

    vector<pair<long double, int> > cost;

    for(int i = 0; i <= n; i++){

        pair<long double, int> in;

        in.first = max(zero, dist(i, n + 1) - r[i]);

        in.second = i;

        cost.push_back(in);

    }

    sort(cost.begin(), cost.end());

    for(int i = 0; i <= n; i++){

        if(cost[i].second == 0){

            cout << cost[i].first << endl;

            return 0;

        }

        for(int j = i + 1; j <= n; j++){

            cost[j].first = min(cost[j].first, cost[i].first + max(zero, dist(cost[i].second, cost[j].second) - r[cost[i].second] - r[cost[j].second]));

        }

        sort(cost.begin() + i + 1, cost.end());

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.560308166784476x):
#include<cstdio>

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

double f[1005][1005],dis[1005],a[1005][3];

bool b[1005];

int main()

{

	int i,j,k,n;

	double xi,xs,ys,xt,yt;

	scanf("%lf%lf%lf%lf",&xs,&ys,&xt,&yt);

	scanf("%d",&n);

	a[0][0]=xs;a[0][1]=ys;a[0][2]=0;

	a[n+1][0]=xt;a[n+1][1]=yt;a[n+1][2]=0;

	for(i=1;i<=n;i++)

		scanf("%lf%lf%lf",&a[i][0],&a[i][1],&a[i][2]);

	n++;

	for(i=0;i<=n;i++)

		for(j=i+1;j<=n;j++)

			f[i][j]=f[j][i]=max(0.0,sqrt((a[i][0]-a[j][0])*(a[i][0]-a[j][0])+(a[i][1]-a[j][1])*(a[i][1]-a[j][1]))-(a[i][2]+a[j][2]));

	for(i=0;i<=1003;i++) dis[i]=1e18;

	dis[0]=0; 

	for(i=0;i<n;i++){ 

		xi=1e18;

		k=0; 

		for(j=0;j<=n;j++){

            if(b[j]==0&&dis[j]<xi){

				xi=dis[j]; 

				k=j; 

			} 

        }

		b[k]=1; 

		for(j=0;j<=n;j++)

			dis[j]=min(dis[j],dis[k]+f[k][j]);

	}

	printf("%.9lf",dis[n]);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



const int maxn = 1e3 + 20;

int vis[maxn],n;

double x[maxn],y[maxn],r[maxn],dist[maxn],mp[maxn][maxn];



void SPFA(int s)

{

    queue<int>q;

    for(int i = 1;i <= n;i++) dist[i] = 1e10;

    memset(vis,0,sizeof(vis));

    while(!q.empty()) q.pop();

    dist[s] = 0;

    vis[s] = 1;

    q.push(s);



    while(!q.empty())

    {

        int v = q.front();

        q.pop();

        vis[v] = 0;

        for(int i = 1;i <= n;i++)

        {

            if(dist[i] > dist[v] + mp[v][i])

            {

                dist[i] = dist[v] + mp[v][i];

                if(!vis[i])

                {

                    vis[i] = 1;

                    q.push(i);

                }

            }

        }

    }

}



int main()

{

    while(scanf("%lf%lf%lf%lf",&x[1],&y[1],&x[2],&y[2]) != EOF)

    {

        scanf("%d",&n);

        n += 2;

        r[1] = r[2] = 0;

        mp[1][2] = mp[2][1] = sqrt((x[1] - x[2]) * (x[1] - x[2]) + (y[1] - y[2]) * (y[1] - y[2]));

        for(int i = 3;i <= n;i++)

        {

            scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);

        }

        for(int i = 1;i <= n;i++)

        {

            for(int j = 1;j <= n;j++)

            {

                mp[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));

                mp[i][j] -= r[i] + r[j];

                if(mp[i][j] < 0)

                {

                    mp[i][j] = 0;

                }

            }

        }

        SPFA(1);

        printf("%.10f\n",dist[2]);

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.419521029737133x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<queue>

#include<cmath>

using namespace std;

typedef long long ll;

const int N=1005;

const double INF=23333333333333.0;

double road[N][N];

double dist[N];

double x[N],y[N],r[N];

int xs,xt,ys,yt;

int n;

double D(double x,double y,double xx,double yy){

    return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));

}

bool vis[N];

void Dijkstra(){

    for(int i=1;i<=n;i++)

        dist[i]=road[n-1][i];

    int u=n-1;

    int cnt=1;

    vis[u]=1;

    while(cnt<n){

        double minv=INF;

        int x;

        for(int i=1;i<=n;i++)

            if(!vis[i]){

                if(dist[i]>dist[u]+road[u][i]){

                    dist[i]=dist[u]+road[u][i];

                }

                if(dist[i]<minv)

                    minv=dist[i],x=i;

            }

        u=x;

        vis[u]=1;

        cnt++;

    }

}

int main()

{

    scanf("%d%d%d%d",&xs,&ys,&xt,&yt);

    scanf("%d",&n);

    memset(dist,-1,sizeof dist);

    for(int i=1;i<=n;i++)

        scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);

    n++;

    x[n]=xs,y[n]=ys,r[n]=0;

    n++;

    x[n]=xt,y[n]=yt,r[n]=0;

    for(int i=1;i<=n;i++)

        for(int j=i;j<=n;j++){

            double f=D(x[i],y[i],x[j],y[j]);

            if(f<r[i]+r[j]){

                f=0;

            }

            else

                f-=r[i]+r[j];

            road[i][j]=road[j][i]=f;

        }

    Dijkstra();

    printf("%.10lf",dist[n]);

}
// Slower C++ solution:
#include <cstdio>

#include <queue>

#include <cmath>

#include <limits>



using namespace std;



int x[1002], y[1002], r[1002];

double cost[1002][1002];

double d[1002];



double norm(double x1, double x2)

{

    double d = x1 - x2;

    return d * d;

}



int main()

{

    scanf("%d%d%d%d", &x[0], &y[0], &x[1], &y[1]);

    r[0] = r[1] = 0;



    int N;

    scanf("%d", &N);

    N += 2;

    for (int i = 2; i < N; i++) {

        scanf("%d%d%d", &x[i], &y[i], &r[i]);

    }



    for (int i = 0; i < N; i++) {

        for (int j = 0; j < N; j++) {

            cost[i][j] = max(sqrt(norm(x[i], x[j]) +  norm(y[i], y[j])) - r[i] - r[j], 0.0);

        }

    }



    d[0] = 0;

    for (int i = 1; i < N; i++)

        d[i] = numeric_limits<double>::max();



    priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;

    pq.push(make_pair(d[0], 0));



    while (!pq.empty()) {

        auto p = pq.top();

        pq.pop();

        int v = p.second;

        if (d[v] < p.first)

            continue;

        for (int i = 0; i < N; i++) {

            if (d[i] > d[v] + cost[v][i]) {

                d[i] = d[v] + cost[v][i];

                pq.push(make_pair(d[i], i));

            }

        }

    }



    printf("%.10f\n", d[1]);

}


// Faster C++ solution for the same problem (measured speedup: 4.354523921804475x):
#include <cstdio>

#include <cmath>

#include <queue>

#include <limits>

using namespace std;



typedef pair<double, int> P;



int x[1002], y[1002], r[1002];

double cost[1002][1002];

bool fixed[1002];

double d[1002];



int main()

{

    scanf("%d%d%d%d", &x[0], &y[0], &x[1], &y[1]);

    r[0] = r[1] = 0;



    int N;

    scanf("%d", &N);

    N += 2;

    for (int i = 2; i < N; i++)

        scanf("%d%d%d", &x[i], &y[i], &r[i]);



    for (int i = 0; i < N; i++)

        for (int j = 0; j < N; j++)

            cost[i][j] = max(hypot(x[i] - x[j], y[i] - y[j]) - r[i] - r[j], 0.);



    fill(fixed, fixed + N, false);

    fill(d, d + N, numeric_limits<double>::infinity());

    d[0] = 0;

    while (true) {

        int v = -1;

        for (int i = 0; i < N; i++) {

            if (!fixed[i] && (v == -1 || d[i] < d[v]))

                v = i;

        }

        if (v == -1)

            break;

        fixed[v] = true;

        for (int i = 0; i < N; i++) {

            d[i] = min(d[i], d[v] + cost[v][i]);

        }

    }



    printf("%.12f\n", d[1]);

}
// Slower C++ solution:
#include <cstdio>

#include <cmath>

#include <queue>

#include <limits>

using namespace std;



typedef pair<double, int> P;



int x[1002], y[1002], r[1002];

double cost[1002][1002];

double d[1002];



int main()

{

    scanf("%d%d%d%d", &x[0], &y[0], &x[1], &y[1]);

    r[0] = r[1] = 0;



    int N;

    scanf("%d", &N);

    N += 2;

    for (int i = 2; i < N; i++)

        scanf("%d%d%d", &x[i], &y[i], &r[i]);



    for (int i = 0; i < N; i++)

        for (int j = 0; j < N; j++)

            cost[i][j] = max(hypot(x[i] - x[j], y[i] - y[j]) - r[i] - r[j], 0.);



    for (double &nd : d)

        nd = numeric_limits<double>::infinity();

    d[0] = 0;

    priority_queue<P> q;

    q.push(P(0, 0));



    while (!q.empty()) {

        auto p = q.top();

        double nowd = -p.first;

        int v = p.second;

        q.pop();

        if (nowd < d[v])

            continue;

        for (int i = 0; i < N; i++) {

            double nextd = d[v] + cost[v][i];

            if (d[i] > nextd) {

                d[i] = nextd;

                q.push(P(-nextd, i));

            }

        }

    }



    printf("%.12f\n", d[1]);

}


// Faster C++ solution for the same problem (measured speedup: 4.430246542804327x):
#include <cstdio>

#include <cmath>

#include <queue>

#include <limits>

using namespace std;



typedef pair<double, int> P;



int x[1002], y[1002], r[1002];

double cost[1002][1002];

bool fixed[1002];

double d[1002];



int main()

{

    scanf("%d%d%d%d", &x[0], &y[0], &x[1], &y[1]);

    r[0] = r[1] = 0;



    int N;

    scanf("%d", &N);

    N += 2;

    for (int i = 2; i < N; i++)

        scanf("%d%d%d", &x[i], &y[i], &r[i]);



    for (int i = 0; i < N; i++)

        for (int j = 0; j < N; j++)

            cost[i][j] = max(hypot(x[i] - x[j], y[i] - y[j]) - r[i] - r[j], 0.);



    fill(fixed, fixed + N, false);

    fill(d, d + N, numeric_limits<double>::infinity());

    d[0] = 0;

    while (true) {

        int v = -1;

        for (int i = 0; i < N; i++) {

            if (!fixed[i] && (v == -1 || d[i] < d[v]))

                v = i;

        }

        if (v == -1)

            break;

        fixed[v] = true;

        for (int i = 0; i < N; i++) {

            d[i] = min(d[i], d[v] + cost[v][i]);

        }

    }



    printf("%.12f\n", d[1]);

}
// Slower C++ solution:
#include <cstdio>

#include <cmath>

#include <queue>

#include <limits>

using namespace std;



typedef pair<double, int> P;



int x[1002], y[1002], r[1002];

double cost[1002][1002];

double d[1002];



int main()

{

    scanf("%d%d%d%d", &x[0], &y[0], &x[1], &y[1]);

    r[0] = r[1] = 0;



    int N;

    scanf("%d", &N);

    N += 2;

    for (int i = 2; i < N; i++)

        scanf("%d%d%d", &x[i], &y[i], &r[i]);



    for (int i = 0; i < N; i++)

        for (int j = 0; j < N; j++)

            cost[i][j] = max(hypot(x[i] - x[j], y[i] - y[j]) - r[i] - r[j], 0.);



    for (double &nd : d)

        nd = numeric_limits<double>::infinity();

    d[0] = 0;

    priority_queue<P, vector<P>, greater<P>> q;

    q.push(P(0, 0));



    while (!q.empty()) {

        auto p = q.top();

        double nowd = p.first;

        int v = p.second;

        q.pop();

        if (nowd < d[v])

            continue;

        for (int i = 0; i < N; i++) {

            double nextd = d[v] + cost[v][i];

            if (d[i] > nextd) {

                d[i] = nextd;

                q.push(P(nextd, i));

            }

        }

    }



    printf("%.12f\n", d[1]);

}


// Faster C++ solution for the same problem (measured speedup: 4.429895034076094x):
#include <cstdio>

#include <cmath>

#include <queue>

#include <limits>

using namespace std;



typedef pair<double, int> P;



int x[1002], y[1002], r[1002];

double cost[1002][1002];

bool fixed[1002];

double d[1002];



int main()

{

    scanf("%d%d%d%d", &x[0], &y[0], &x[1], &y[1]);

    r[0] = r[1] = 0;



    int N;

    scanf("%d", &N);

    N += 2;

    for (int i = 2; i < N; i++)

        scanf("%d%d%d", &x[i], &y[i], &r[i]);



    for (int i = 0; i < N; i++)

        for (int j = 0; j < N; j++)

            cost[i][j] = max(hypot(x[i] - x[j], y[i] - y[j]) - r[i] - r[j], 0.);



    fill(fixed, fixed + N, false);

    fill(d, d + N, numeric_limits<double>::infinity());

    d[0] = 0;

    while (true) {

        int v = -1;

        for (int i = 0; i < N; i++) {

            if (!fixed[i] && (v == -1 || d[i] < d[v]))

                v = i;

        }

        if (v == -1)

            break;

        fixed[v] = true;

        for (int i = 0; i < N; i++) {

            d[i] = min(d[i], d[v] + cost[v][i]);

        }

    }



    printf("%.12f\n", d[1]);

}
// Slower C++ solution:
#include <stdio.h>

#include <string.h>

#include <math.h>

#include <algorithm>

#include <vector>

using namespace std;



const int N = 1010;



struct node

{

	int x,y,r;

} a[N];



struct edge

{

	int v;

	double cost;

	edge(int x,double b):v(x),cost(b){};

};

int n;

double d[N];

bool vis[N];



vector<edge> G[N];



double cal(int i,int j)

{

	double sum = a[i].r + a[j].r;

	double xx = 1.0 * (a[i].x - a[j].x) * (a[i].x - a[j].x);

	double yy = 1.0 * (a[i].y - a[j].y) * (a[i].y - a[j].y);

	double ans = sqrt(xx+yy);

	if (sum >= ans) return 0;

	else return ans - sum;

}



void dij(void)

{

	for (int i = 0;i <= n + 1;i++) d[i] = 1e30;

	d[0] = 0;

	for (int i = 0;i <= n;i++)

	{

		double mi = 1e30;

		int x;

		for (int j = 0;j <= n + 1;j++)

		{

			if (!vis[j] && d[j] < mi)

			{

				mi = d[j];

				x = j;

			}

		}

		if (mi == 1e30) break;

		vis[x] = 1;

		for (auto e : G[x])

		{

			double cost = e.cost;

			int v = e.v;

			if (d[v] > cost + d[x])

			{

				d[v] = cost + d[x];

			}

		}

	}

}



int main()

{

	scanf("%d%d",&a[0].x,&a[0].y);

	a[0].r = 0;

	int x,y;

	scanf("%d%d",&x,&y);

	scanf("%d",&n);

	a[n+1].x = x,a[n+1].y = y,a[n+1].r = 0;

	for (int i = 1;i <= n;i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].r);

	for (int i = 0;i <= n + 1;i++)

	{

		for (int j = i + 1;j <= n + 1;j++)

		{

			double len = cal(i,j);

			G[i].push_back(edge(j,len));

			G[j].push_back(edge(i,len));

		}

	}

	dij();

	printf("%.15f\n",d[n+1]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.9677401604131215x):
#include<cstdio>

#include<cstring>

#include<cctype>

#include<algorithm>

#define maxn 1005

#include<cmath>

using namespace std;



double sqr(double a){ return a*a; }

int n;

struct Point

{

	double x,y;

	Point(double a=0,double b=0):x(a),y(b){}

	double operator *(const Point &B)const{ return sqrt(sqr(x - B.x) + sqr(y - B.y));}

}P[maxn],S,T;

double r[maxn],dis[maxn][maxn],dist[maxn];

bool vis[maxn];



int main()

{

	scanf("%lf%lf%lf%lf",&S.x,&S.y,&T.x,&T.y);

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%lf%lf%lf",&P[i].x,&P[i].y,&r[i]);

	P[n+1]=S,P[n+2]=T;

	n+=2;

	for(int i=1;i<=n;i++)

		for(int j=1;j<=n;j++)

			dis[i][j] = max(0.0 , P[i] * P[j] -r[i] - r[j]);



	for(int i=1;i<=n;i++)dist[i] = 2e18;

	dist[n-1]=0;

	for(int i=1;i<=n;i++)

	{

		int Minloc = -1;

        for(int j=1;j<=n;j++)

			if(!vis[j] && (Minloc == -1 || dist[j] < dist[Minloc]))

				Minloc = j;

		vis[Minloc] = 1;

		for(int j=1;j<=n;j++)

			if(!vis[j] && dist[j] > dist[Minloc] + dis[Minloc][j])

				dist[j] = dist[Minloc] + dis[Minloc][j];

	}



	printf("%.10lf\n",dist[n]);

}
// Slower C++ solution:
#include <stdio.h>

#include <string.h>

#include <math.h>

#include <algorithm>

#include <vector>

using namespace std;



const int N = 1010;



struct node

{

	int x,y,r;

} a[N];



struct edge

{

	int v;

	double cost;

	edge(int x,double b):v(x),cost(b){};

};

int n;

double d[N];

bool vis[N];



vector<edge> G[N];



double cal(int i,int j)

{

	double sum = a[i].r + a[j].r;

	double xx = 1.0 * (a[i].x - a[j].x) * (a[i].x - a[j].x);

	double yy = 1.0 * (a[i].y - a[j].y) * (a[i].y - a[j].y);

	double ans = sqrt(xx+yy);

	if (sum >= ans) return 0;

	else return ans - sum;

}



void dij(void)

{

	for (int i = 0;i <= n + 1;i++) d[i] = 1e30;

	d[0] = 0;

	for (int i = 0;i <= n;i++)

	{

		double mi = 1e30;

		int x;

		for (int j = 0;j <= n + 1;j++)

		{

			if (!vis[j] && d[j] < mi)

			{

				mi = d[j];

				x = j;

			}

		}

		if (mi == 1e30) break;

		vis[x] = 1;

		for (auto e : G[x])

		{

			double cost = e.cost;

			int v = e.v;

			if (d[v] > cost + d[x])

			{

				d[v] = cost + d[x];

			}

		}

	}

}



int main()

{

	scanf("%d%d",&a[0].x,&a[0].y);

	a[0].r = 0;

	int x,y;

	scanf("%d%d",&x,&y);

	scanf("%d",&n);

	a[n+1].x = x,a[n+1].y = y,a[n+1].r = 0;

	for (int i = 1;i <= n;i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].r);

	for (int i = 0;i <= n + 1;i++)

	{

		for (int j = i + 1;j <= n + 1;j++)

		{

			double len = cal(i,j);

			G[i].push_back(edge(j,len));

			G[j].push_back(edge(i,len));

		}

	}

	dij();

	printf("%.15f\n",d[n+1]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.18554767051774x):
/*Lucky_Glass*/

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;

const int MAXN=1000;

const double INF=1e18;

int beg[2],ove[2],rnd[MAXN+5][3];

double dis[MAXN+5][MAXN+5];

int n;

double F[MAXN+5];

bool vis[MAXN+5];

double Dij()

{

	fill(F,F+MAXN+5,INF);

	F[0]=0;

	for(int i=0;i<=n;i++)

	{

		double MIN=INF;

		int u;

		for(int j=0;j<=n+1;j++)

			if(F[j]<MIN && !vis[j])

				MIN=F[j],u=j;

		vis[u]=true;

		for(int j=0;j<=n+1;j++)

			F[j]=min(F[j],F[u]+dis[u][j]);

	}

	return F[n+1];

}

int main()

{

	scanf("%d%d%d%d",&beg[0],&beg[1],&ove[0],&ove[1]);

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

		for(int j=0;j<3;j++)

			scanf("%d",&rnd[i][j]);

	rnd[0][0]=beg[0];rnd[0][1]=beg[1];

	rnd[n+1][0]=ove[0];rnd[n+1][1]=ove[1];

	for(int i=0;i<=n+1;i++)

		for(int j=i+1;j<=n+1;j++)

			dis[i][j]=dis[j][i]=max(sqrt(1.0*(rnd[i][0]-rnd[j][0])*(rnd[i][0]-rnd[j][0])+1.0*(rnd[i][1]-rnd[j][1])*(rnd[i][1]-rnd[j][1]))-rnd[i][2]-rnd[j][2],0.0);

	printf("%.9lf\n",Dij());

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<cmath>

#include<queue>

#include<vector>

#include<cstring>

#include<algorithm>

#define maxn 1005

using namespace std;

int xs,ys,xt,yt,n,x[maxn],y[maxn],r[maxn];

double dist[maxn],g[maxn][maxn];

queue<int> q;

bool inq[maxn];

int main()

{

	scanf("%d%d%d%d%d",&xs,&ys,&xt,&yt,&n);

	x[0]=xs,y[0]=ys,x[n+1]=xt,y[n+1]=yt;

	for(int i=1;i<=n;i++) scanf("%d%d%d",&x[i],&y[i],&r[i]);

	for(int i=0;i<=n+1;i++)

		for(int j=0;j<=n+1;j++)

			g[i][j]=max(0.0,sqrt(1.0*(x[i]-x[j])*(x[i]-x[j])+1.0*(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j]);

	for(int i=1;i<=n+1;i++) dist[i]=1e16;

	q.push(0); inq[0]=true;

	while(!q.empty())

	{

		int u=q.front(); q.pop();

		inq[u]=false;

		for(int v=0;v<=n+1;v++)

			if(dist[v]>dist[u]+g[u][v])

			{

				dist[v]=dist[u]+g[u][v];

				if(!inq[v]) { inq[v]=true; q.push(v); }

			}

	}

	printf("%.10f\n",dist[n+1]);

}

// Faster C++ solution for the same problem (measured speedup: 4.1101656138123035x):
/*Lucky_Glass*/

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;

const int MAXN=1000;

const double INF=1e18;

int beg[2],ove[2],rnd[MAXN+5][3];

double dis[MAXN+5][MAXN+5];

int n;

double F[MAXN+5];

bool vis[MAXN+5];

double Dij()

{

	fill(F,F+MAXN+5,INF);

	F[0]=0;

	for(int i=0;i<=n;i++)

	{

		double MIN=INF;

		int u;

		for(int j=0;j<=n+1;j++)

			if(F[j]<MIN && !vis[j])

				MIN=F[j],u=j;

		vis[u]=true;

		for(int j=0;j<=n+1;j++)

			F[j]=min(F[j],F[u]+dis[u][j]);

	}

	return F[n+1];

}

int main()

{

	scanf("%d%d%d%d",&beg[0],&beg[1],&ove[0],&ove[1]);

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

		for(int j=0;j<3;j++)

			scanf("%d",&rnd[i][j]);

	rnd[0][0]=beg[0];rnd[0][1]=beg[1];

	rnd[n+1][0]=ove[0];rnd[n+1][1]=ove[1];

	for(int i=0;i<=n+1;i++)

		for(int j=i+1;j<=n+1;j++)

			dis[i][j]=dis[j][i]=max(sqrt(1.0*(rnd[i][0]-rnd[j][0])*(rnd[i][0]-rnd[j][0])+1.0*(rnd[i][1]-rnd[j][1])*(rnd[i][1]-rnd[j][1]))-rnd[i][2]-rnd[j][2],0.0);

	printf("%.9lf\n",Dij());

	return 0;

}
// Slower C++ solution:
#include <stdio.h>

#include <string.h>

#include <math.h>

#include <algorithm>

#include <vector>

using namespace std;



const int N = 1010;



struct node

{

	int x,y,r;

} a[N];



struct edge

{

	int v;

	double cost;

	edge(int x,double b):v(x),cost(b){};

};

int n;

double d[N];

bool vis[N];



vector<edge> G[N];



double cal(int i,int j)

{

	double sum = a[i].r + a[j].r;

	double xx = 1.0 * (a[i].x - a[j].x) * (a[i].x - a[j].x);

	double yy = 1.0 * (a[i].y - a[j].y) * (a[i].y - a[j].y);

	double ans = sqrt(xx+yy);

	if (sum >= ans) return 0;

	else return ans - sum;

}



void dij(void)

{

	for (int i = 0;i <= n + 1;i++) d[i] = 1e30;

	d[0] = 0;

	for (int i = 0;i <= n;i++)

	{

		double mi = 1e30;

		int x;

		for (int j = 0;j <= n + 1;j++)

		{

			if (!vis[j] && d[j] < mi)

			{

				mi = d[j];

				x = j;

			}

		}

		if (mi == 1e30) break;

		vis[x] = 1;

		for (auto e : G[x])

		{

			double cost = e.cost;

			int v = e.v;

			if (d[v] > cost + d[x])

			{

				d[v] = cost + d[x];

			}

		}

	}

}



int main()

{

	scanf("%d%d",&a[0].x,&a[0].y);

	a[0].r = 0;

	int x,y;

	scanf("%d%d",&x,&y);

	scanf("%d",&n);

	a[n+1].x = x,a[n+1].y = y,a[n+1].r = 0;

	for (int i = 1;i <= n;i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].r);

	for (int i = 0;i <= n + 1;i++)

	{

		for (int j = i + 1;j <= n + 1;j++)

		{

			double len = cal(i,j);

			G[i].push_back(edge(j,len));

			G[j].push_back(edge(i,len));

		}

	}

	dij();

	printf("%.15f\n",d[n+1]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.103604171895239x):
#include<cstdio>

#include<cmath>

#include<cstring>

#include<algorithm>

using namespace std;

double f[1005][1005],dis[1005],a[1005][3];

bool b[1005];

int main()

{

	int i,j,k,n;

	double xi,xs,ys,xt,yt;

	scanf("%lf%lf%lf%lf",&xs,&ys,&xt,&yt);

	scanf("%d",&n);

	a[0][0]=xs;a[0][1]=ys;a[0][2]=0;

	a[n+1][0]=xt;a[n+1][1]=yt;a[n+1][2]=0;

	for(i=1;i<=n;i++)

		scanf("%lf%lf%lf",&a[i][0],&a[i][1],&a[i][2]);

	n++;

	for(i=0;i<=n;i++)

		for(j=i+1;j<=n;j++){

			f[i][j]=f[j][i]=sqrt((a[i][0]-a[j][0])*(a[i][0]-a[j][0])+(a[i][1]-a[j][1])*(a[i][1]-a[j][1]))-(a[i][2]+a[j][2]);

			if(f[i][j]<0)

				f[j][i]=f[i][j]=0;

		}

	for(i=0;i<=1003;i++) dis[i]=1e18;

	dis[0]=0; 

	for(i=0;i<n;i++){ 

		xi=1e18;

		k=0; 

		for(j=0;j<=n;j++){

            if(b[j]==0&&dis[j]<xi){ 

				xi=dis[j]; 

				k=j; 

			} 

        }

		b[k]=1; 

		for(j=0;j<=n;j++)

			dis[j]=min(dis[j],dis[k]+f[k][j]);

	}

	printf("%.9lf",dis[n]);

}