#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;

double distance(double x1,double y1, double x2,double y2)
{
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

int main()
{
    double ax,ay,bx,by,tx,ty;
    scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&tx,&ty);

    int n;
    scanf("%d",&n);

    double cdist[n],D=0;
    pair<double,double> p[n];   //position of bottles
    for(int i=0;i<n;++i)
    {
        scanf("%lf%lf",&p[i].first,&p[i].second);
        cdist[i]=distance(tx,ty,p[i].first,p[i].second);
        D+=2*cdist[i];
    }

    set< pair<double,int> > A,B;
    double distA[n],distB[n];
    for(int i=0;i<n;++i)
    {
        double x=-cdist[i]+distance(ax,ay,p[i].first,p[i].second);
        distA[i]=x;
        A.insert({x,i});

        x=-cdist[i]+distance(bx,by,p[i].first,p[i].second);
        distB[i]=x;
        B.insert({x,i});
    }

    double temp1=D+A.begin()->first;    //only A moves
    double temp2=D+B.begin()->first;    //only B moves

    double temp3=D+A.begin()->first;    //A moves first
    int idx=A.begin()->second;
    B.erase({distB[idx],idx});
    if(not B.empty()) temp3+=B.begin()->first;
    B.insert({distB[idx],idx});

    double temp4=D+B.begin()->first;    //B moves first
    idx=B.begin()->second;
    A.erase({distA[idx],idx});
    if(not A.empty()) temp4+=A.begin()->first;
//     A.insert({distA[idx],idx});

    double ans=min(min(temp1,temp2),min(temp3,temp4));

    printf("%lf\n",ans);

    return 0;
}


#include <iostream>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

double distance(double x1,double y1, double x2,double y2)
{
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

int main()
{
    //ios_base::sync_with_stdio(false);

    double ax,ay,bx,by,tx,ty;
    cin>>ax>>ay>>bx>>by>>tx>>ty;

    int n;
    cin>>n;

    double cdist[n],D=0;
    pair<double,double> p[n];   //position of bottles
    for(int i=0;i<n;++i)
    {
        cin>>p[i].first>>p[i].second;
        cdist[i]=distance(tx,ty,p[i].first,p[i].second);
        D+=2*cdist[i];
    }

    set< pair<double,int> > A,B;
    double distA[n],distB[n];
    for(int i=0;i<n;++i)
    {
        double x=-cdist[i]+distance(ax,ay,p[i].first,p[i].second);
        distA[i]=x;
        A.insert({x,i});

        x=-cdist[i]+distance(bx,by,p[i].first,p[i].second);
        distB[i]=x;
        B.insert({x,i});
    }

    double temp1=D+A.begin()->first;
    double temp2=D+B.begin()->first;

    double temp3,res=999999999999999;
    for(auto it: A)
    {
        temp3=D;
        temp3+=it.first;
        int idx=it.second;
        B.erase({distB[idx],idx});
        if(not B.empty()) temp3+=B.begin()->first;
        res=min(res,temp3);
        B.insert({distB[idx],idx});
    }

    for(auto it: B)
    {
        temp3=D;
        temp3+=it.first;
        int idx=it.second;
        A.erase({distA[idx],idx});
        if(not A.empty()) temp3+=A.begin()->first;
        res=min(res,temp3);
        A.insert({distA[idx],idx});
    }

    double ans=min(min(temp1,temp2),res);

    cout.setf(ios::fixed);
    cout.precision(14);
    cout<<ans<<'\n';

    return 0;
}


#include <iostream>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

double distance(double x1,double y1,double x2,double y2)
{
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

int main()
{
    ios_base::sync_with_stdio(false);

    double ax,ay,bx,by,tx,ty;
    cin>>ax>>ay>>bx>>by>>tx>>ty;

    int n;
    cin>>n;

    double cdist[n],D=0;
    pair<double,double> p[n];   //position of bottles
    for(int i=0;i<n;++i)
    {
        cin>>p[i].first>>p[i].second;
        cdist[i]=distance(tx,ty,p[i].first,p[i].second);
        D+=2*cdist[i];
    }

    set< pair<double,int> > A,B;
    double distA[n],distB[n];
    for(int i=0;i<n;++i)
    {
        double x=-cdist[i]+distance(ax,ay,p[i].first,p[i].second);
        distA[i]=x;
        A.insert({x,i});

        x=-cdist[i]+distance(bx,by,p[i].first,p[i].second);
        distB[i]=x;
        B.insert({x,i});
    }

    double temp1=D+A.begin()->first;
    double temp2=D+B.begin()->first;

    double temp3,res=D;
    set< pair<double,int> >::iterator it1,it2;
    for(it1=A.begin(),it2=B.begin(); it1!=A.end(); ++it1,++it2)
    {
        temp3=D;
        temp3+=(it1)->first;
        int idx=(it1)->second;
        B.erase({distB[idx],idx});
        if(not B.empty()) temp3+=B.begin()->first;
        res=min(res,temp3);
        B.insert({distB[idx],idx});

        temp3=D;
        temp3+=(it2)->first;
        idx=(it2)->second;
        A.erase({distA[idx],idx});
        if(not A.empty()) temp3+=A.begin()->first;
        res=min(res,temp3);
        A.insert({distA[idx],idx});
    }

    double ans=min(min(temp1,temp2),res);

    cout.setf(ios::fixed);
    cout.precision(14);
    cout<<ans<<'\n';

    return 0;
}


#include <iostream>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

double distance(double x1,double y1,double x2,double y2)
{
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

int main()
{
    ios_base::sync_with_stdio(false);

    double ax,ay,bx,by,tx,ty;
    cin>>ax>>ay>>bx>>by>>tx>>ty;

    int n;
    cin>>n;

    double cdist[n],D=0;
    pair<double,double> p[n];   //position of bottles
    for(int i=0;i<n;++i)
    {
        cin>>p[i].first>>p[i].second;
        cdist[i]=distance(tx,ty,p[i].first,p[i].second);
        D+=2*cdist[i];
    }

    set< pair<double,int> > B;
    pair<double,int> distA[n];
    double distB[n];
    for(int i=0;i<n;++i)
    {
        double x=-cdist[i]+distance(ax,ay,p[i].first,p[i].second);
        distA[i]={x,i};

        x=-cdist[i]+distance(bx,by,p[i].first,p[i].second);
        distB[i]=x;
        B.insert({x,i});
    }

    sort(distA,distA+n);

    double temp1=D+distA[0].first;
    double temp2=D+B.begin()->first;

    double temp3;
    double res=D;
    for(int i=0;i<n;++i)
    {
        temp3=D;
        temp3+=distA[i].first;
        int idx=distA[i].second;
        B.erase({distB[idx],idx});
        if(not B.empty()) temp3+=B.begin()->first;
        res=min(res,temp3);

        B.insert({distB[idx],idx});
    }

    double ans=min(min(temp1,temp2),res);

    cout.setf(ios::fixed);
    cout.precision(14);
    cout<<ans<<'\n';

    return 0;
}


#include <iostream>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

double distance(double x1,double y1,double x2,double y2)
{
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

int main()
{
    //ios_base::sync_with_stdio(false);

    double ax,ay,bx,by,tx,ty;
    cin>>ax>>ay>>bx>>by>>tx>>ty;

    int n;
    cin>>n;

    double cdist[n],D=0;
    pair<double,double> p[n];   //position of bottles
    for(int i=0;i<n;++i)
    {
        cin>>p[i].first>>p[i].second;
        cdist[i]=distance(tx,ty,p[i].first,p[i].second);
        D+=2*cdist[i];
    }

    set< pair<double,int> > A,B;
    double distA[n],distB[n];
    for(int i=0;i<n;++i)
    {
        double x=-cdist[i]+distance(ax,ay,p[i].first,p[i].second);
        distA[i]=x;
        A.insert({x,i});

        x=-cdist[i]+distance(bx,by,p[i].first,p[i].second);
        distB[i]=x;
        B.insert({x,i});
    }

    double temp1=D+A.begin()->first;
    double temp2=D+B.begin()->first;

    double temp3,res=D;
    set< pair<double,int> >::iterator it1,it2;
    for(it1=A.begin(),it2=B.begin(); it1!=A.end(); ++it1,++it2)
    {
        temp3=D;
        temp3+=(it1)->first;
        int idx=(it1)->second;
        B.erase({distB[idx],idx});
        if(not B.empty()) temp3+=B.begin()->first;
        res=min(res,temp3);
        B.insert({distB[idx],idx});

        temp3=D;
        temp3+=(it2)->first;
        idx=(it2)->second;
        A.erase({distA[idx],idx});
        if(not A.empty()) temp3+=A.begin()->first;
        res=min(res,temp3);
        A.insert({distA[idx],idx});
    }

    double ans=min(min(temp1,temp2),res);

    cout.setf(ios::fixed);
    cout.precision(14);
    cout<<ans<<'\n';

    return 0;
}


#include <iostream>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

double distance(double x1,double y1, double x2,double y2)
{
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

int main()
{
    ios_base::sync_with_stdio(false);

    double ax,ay,bx,by,tx,ty;
    cin>>ax>>ay>>bx>>by>>tx>>ty;

    int n;
    cin>>n;

    double cdist[n],D=0;
    pair<double,double> p[n];   //position of bottles
    for(int i=0;i<n;++i)
    {
        cin>>p[i].first>>p[i].second;
        cdist[i]=distance(tx,ty,p[i].first,p[i].second);
        D+=2*cdist[i];
    }

    set< pair<double,int> > A,B;
    double distA[n],distB[n];
    for(int i=0;i<n;++i)
    {
        double x=-cdist[i]+distance(ax,ay,p[i].first,p[i].second);
        distA[i]=x;
        A.insert({x,i});

        x=-cdist[i]+distance(bx,by,p[i].first,p[i].second);
        distB[i]=x;
        B.insert({x,i});
    }

    double temp1=D+A.begin()->first;    //only A moves
    double temp2=D+B.begin()->first;    //only B moves

    double temp3=D+A.begin()->first;    //A moves first
    int idx=A.begin()->second;
    B.erase({distB[idx],idx});
    if(not B.empty()) temp3+=B.begin()->first;
    B.insert({distB[idx],idx});

    double temp4=D+B.begin()->first;    //B moves first
    idx=B.begin()->second;
    A.erase({distA[idx],idx});
    if(not A.empty()) temp4+=A.begin()->first;
//     A.insert({distA[idx],idx});

    double ans=min(min(temp1,temp2),min(temp3,temp4));

    cout.setf(ios::fixed);
    cout.precision(14);
    cout<<ans<<'\n';

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
long long ax, ay, bx, by, tx, ty,n;
struct bott
{
	long long x, y;
	double num;
}bott1[100005],bott2[100005];
double dis(long long a, long long b, long long c, long long d)
{
	return pow(((a-c)*(a-c)+ (b - d)*(b - d)), 0.5);
}
int cmp(bott m, bott n)
{
	return dis(ax, ay, m.x, m.y)-dis(tx, ty, m.x, m.y) < dis(ax, ay, n.x, n.y) -dis(tx, ty, n.x, n.y);
}
int cmp1(bott q, bott w)
{
	return dis(bx, by, q.x, q.y) - dis(tx, ty, q.x, q.y) < dis(bx, by, w.x, w.y)-dis(tx, ty, w.x, w.y);
}
int main()
{
	//freopen("C:\\in.txt", "r", stdin);
	double sum = 0;
	scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&ax,&ay,&bx,&by,&tx,&ty);
	scanf("%I64d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &bott1[i].x, &bott1[i].y);
		bott2[i].x = bott1[i].x;
		bott2[i].y = bott1[i].y;
	}
	sort(bott1, bott1 + n, cmp);
	sort(bott2, bott2 + n, cmp1);
	bott2[0].num = dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
	bott1[0].num = dis(ax, ay, bott1[0].x, bott1[0].y) + dis(tx, ty, bott1[0].x, bott1[0].y);
	if (bott1[0].x == bott2[0].x&& bott1[0].y == bott2[0].y)
	{
		bott1[0].num = min(bott1[0].num+dis(bx, by, bott2[1].x, bott2[1].y) + dis(tx, ty, bott2[1].x, bott2[1].y), bott2[0].num+ dis(ax, ay, bott1[1].x, bott1[1].y) + dis(tx, ty, bott1[1].x, bott1[1].y));
		bott1[1].num = 0;
		for (int i = 2; i < n; i++)
		{
			bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
	}
	else
	{
		bott1[0].num += dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
		for (int i = 1; i < n; i++)
		{
			if (bott1[i].x == bott2[0].x&& bott1[i].y == bott2[0].y)
				continue;
			else
				bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
	}
	for (int i = 0; i < n; i++)
		sum += bott1[i].num;
	printf("%.12f\n", sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
long long ax, ay, bx, by, tx, ty,n;
struct bott
{
	long long x, y;
	double num;
}bott1[100005],bott2[100005];
double dis(long long a, long long b, long long c, long long d)
{
	return pow(((a-c)*(a-c)+ (b - d)*(b - d)), 0.5);
}
int cmp(bott m, bott n)
{
	return dis(ax, ay, m.x, m.y)-dis(tx, ty, m.x, m.y) < dis(ax, ay, n.x, n.y) -dis(tx, ty, n.x, n.y);
}
int cmp1(bott q, bott w)
{
	return dis(bx, by, q.x, q.y) - dis(tx, ty, q.x, q.y) < dis(bx, by, w.x, w.y)-dis(tx, ty, w.x, w.y);
}
int main()
{
	//freopen("C:\\in.txt", "r", stdin);
	double sum = 0;
	scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&ax,&ay,&bx,&by,&tx,&ty);
	scanf("%I64d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &bott1[i].x, &bott1[i].y);
		bott2[i].x = bott1[i].x;
		bott2[i].y = bott1[i].y;
	}
	sort(bott1, bott1 + n, cmp);
	sort(bott2, bott2 + n, cmp1);
	bott2[0].num = dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
	bott1[0].num = dis(ax, ay, bott1[0].x, bott1[0].y) + dis(tx, ty, bott1[0].x, bott1[0].y);
	if (bott1[0].x == bott2[0].x&& bott1[0].y == bott2[0].y)
	{
		bott1[0].num = min(bott1[0].num+dis(bx, by, bott2[1].x, bott2[1].y) + dis(tx, ty, bott2[1].x, bott2[1].y), bott2[0].num+ dis(ax, ay, bott1[1].x, bott1[1].y) + dis(tx, ty, bott1[1].x, bott1[1].y));
		bott1[1].num = 0;
		for (int i = 2; i < n; i++)
		{
			bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
		for (int i = 0; i < n; i++)
			sum += bott1[i].num;
		printf("%.12f\n", sum);
	}
	else
	{
		double num;
		for (int i = 0; i < n; i++)
			sum += 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) < 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) < 0)
		{
			num =dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y)+ dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y);
			sum += num;
		}
		 if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) < 0&& dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y)>=0)
			sum += dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y);
		if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) >= 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) < 0)
			sum += dis(bx, by, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y);
		if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) >= 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) >= 0)
		{
			num = min(dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) , dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y));
			sum += num;
		}
		printf("%.12f\n", sum);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
long long ax, ay, bx, by, tx, ty,n;
struct bott
{
	long long x, y;
	double num;
}bott1[100005],bott2[100005];
double dis(long long a, long long b, long long c, long long d)
{
	return pow(((a-c)*(a-c)+ (b - d)*(b - d)), 0.5);
}
int cmp(bott m, bott n)
{
	return dis(ax, ay, m.x, m.y)-dis(tx, ty, m.x, m.y) < dis(ax, ay, n.x, n.y) -dis(tx, ty, n.x, n.y);
}
int cmp1(bott q, bott w)
{
	return dis(bx, by, q.x, q.y) - dis(tx, ty, q.x, q.y) < dis(bx, by, w.x, w.y)-dis(tx, ty, w.x, w.y);
}
int main()
{
	//freopen("C:\\in.txt", "r", stdin);
	double sum = 0;
	scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&ax,&ay,&bx,&by,&tx,&ty);
	scanf("%I64d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &bott1[i].x, &bott1[i].y);
		bott2[i].x = bott1[i].x;
		bott2[i].y = bott1[i].y;
	}
	sort(bott1, bott1 + n, cmp);
	sort(bott2, bott2 + n, cmp1);
	bott2[0].num = dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
	bott1[0].num = dis(ax, ay, bott1[0].x, bott1[0].y) + dis(tx, ty, bott1[0].x, bott1[0].y);
	if (bott1[0].x == bott2[0].x&& bott1[0].y == bott2[0].y)
	{
		double num;
		for (int i = 0; i < n; i++)
			sum += 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		double sum1 = sum;
		if (n > 1) {
			sum += min(dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) + dis(bx, by, bott2[1].x, bott2[1].y) - dis(tx, ty, bott2[1].x, bott2[1].y),
				dis(ax, ay, bott1[1].x, bott1[1].y) - dis(tx, ty, bott1[1].x, bott1[1].y) + dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y)
			);
			sum = min(sum, sum1 + min(dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y), dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y)));
		}
		else
			sum = sum+ min(dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y), dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y));
		printf("%.12f\n", sum);
	}
	else
	{
		double num;
		for (int i = 0; i < n; i++)
			sum += 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) < 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) < 0)
		{
			num =dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y)+ dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y);
			sum += num;
		}
		 if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) < 0&& dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y)>=0)
			sum += dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y);
		if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) >= 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) < 0)
			sum += dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y);
		if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) >= 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) >= 0)
		{
			num = min(dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) , dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y));
			sum += num;
		}
		printf("%.12f\n", sum);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int ax, ay, bx, by, tx, ty,n;
struct bott
{
	int x, y;
	double num;
}bott1[100005],bott2[100005];
double dis(int a, int b, int c, int d)
{
	return pow(((a-c)*(a-c)+ (b - d)*(b - d)), 0.5);
}
int cmp(bott m, bott n)
{
	return dis(ax, ay, m.x, m.y)+ dis(tx, ty, m.x, m.y)-2* dis(tx, ty, m.x, m.y) < dis(ax, ay, n.x, n.y) + dis(tx, ty, n.x, n.y) - 2 * dis(tx, ty, n.x, n.y);
}
int cmp1(bott m, bott n)
{
	return dis(bx, by, m.x, m.y) + dis(tx, ty, m.x, m.y) - 2 * dis(tx, ty, m.x, m.y) < dis(bx, by, n.x, n.y) + dis(tx, ty, n.x, n.y) - 2 * dis(tx, ty, n.x, n.y);
}
int main()
{
	//freopen("C:\\in.txt", "r", stdin);
	double sum = 0;
	memset(bott1, 0, sizeof(bott1));
	scanf("%d%d%d%d%d%d",&ax,&ay,&bx,&by,&tx,&ty);
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &bott1[i].x, &bott1[i].y);
		bott2[i].x = bott1[i].x;
		bott2[i].y = bott1[i].y;
	}
	sort(bott1, bott1 + n, cmp);
	sort(bott2, bott2 + n, cmp1);
	bott2[0].num = dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
	bott1[0].num = dis(ax, ay, bott1[0].x, bott1[0].y) + dis(tx, ty, bott1[0].x, bott1[0].y);
	if (bott1[0].x == bott2[0].x&& bott1[0].y == bott2[0].y&&bott1[0].num <= bott2[0].num)
	{
		for (int i = 1; i < n; i++)
		{
			if(bott1[i].x == bott2[1].x&& bott1[i].y == bott2[1].y)
			bott1[i].num = dis(bx, by, bott2[1].x, bott2[1].y) + dis(tx, ty, bott2[1].x, bott2[1].y);
			else
			bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
	}
	else if (bott1[0].x == bott2[0].x&& bott1[0].y == bott2[0].y&&bott1[0].num >bott2[0].num)
	{
		bott1[0].num = bott2[0].num;
		bott1[1].num = dis(ax, ay, bott1[1].x, bott1[1].y) + dis(tx, ty, bott1[1].x, bott1[1].y);
		for (int i = 2; i < n; i++)
		{
			bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
	}
	else
	{
		bott1[0].num += dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
		for (int i = 1; i < n; i++)
		{
			if (bott1[i].x == bott2[0].x&& bott1[i].y == bott2[0].y)
				continue;
			else
				bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
	}
	for (int i = 0; i < n; i++)
		sum += bott1[i].num;
	printf("%.8f\n", sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
long long ax, ay, bx, by, tx, ty,n;
struct bott
{
	long long x, y;
	double num;
}bott1[100005],bott2[100005];
double dis(long long a, long long b, long long c, long long d)
{
	return pow(((a-c)*(a-c)+ (b - d)*(b - d)), 0.5);
}
int cmp(bott m, bott n)
{
	return dis(ax, ay, m.x, m.y)-dis(tx, ty, m.x, m.y) < dis(ax, ay, n.x, n.y) -dis(tx, ty, n.x, n.y);
}
int cmp1(bott q, bott w)
{
	return dis(bx, by, q.x, q.y) - dis(tx, ty, q.x, q.y) < dis(bx, by, w.x, w.y)-dis(tx, ty, w.x, w.y);
}
int main()
{
	//freopen("C:\\in.txt", "r", stdin);
	double sum = 0;
	scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&ax,&ay,&bx,&by,&tx,&ty);
	scanf("%I64d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &bott1[i].x, &bott1[i].y);
		bott2[i].x = bott1[i].x;
		bott2[i].y = bott1[i].y;
	}
	sort(bott1, bott1 + n, cmp);
	sort(bott2, bott2 + n, cmp1);
	bott2[0].num = dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
	bott1[0].num = dis(ax, ay, bott1[0].x, bott1[0].y) + dis(tx, ty, bott1[0].x, bott1[0].y);
	if (bott1[0].x == bott2[0].x&& bott1[0].y == bott2[0].y)
	{
		double num;
		for (int i = 0; i < n; i++)
			sum += 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		double sum1 = sum;
		if (n > 1) {
			sum += min(dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) + dis(bx, by, bott2[1].x, bott2[1].y) - dis(tx, ty, bott2[1].x, bott2[1].y),
				dis(ax, ay, bott1[1].x, bott1[1].y) - dis(tx, ty, bott1[1].x, bott1[1].y) + dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y)
			);
			sum = min(sum, sum1 + min(dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y), dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y)));
		}
		else
			sum = sum+ min(dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y), dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y));
		printf("%.12f\n", sum);
	}
	else
	{
		double num;
		for (int i = 0; i < n; i++)
			sum += 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) < 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) < 0)
		{
			num =dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y)+ dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y);
			sum += num;
		}
		 if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) < 0&& dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y)>=0)
			sum += dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y);
		if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) >= 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) < 0)
			sum += dis(bx, by, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y);
		if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) >= 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) >= 0)
		{
			num = min(dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) , dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y));
			sum += num;
		}
		printf("%.12f\n", sum);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int ax, ay, bx, by, tx, ty,n;
struct bott
{
	int x, y;
	double num;
}bott1[100005],bott2[100005];
double dis(int a, int b, int c, int d)
{
	return pow(((a-c)*(a-c)+ (b - d)*(b - d)), 0.5);
}
int cmp(bott m, bott n)
{
	return dis(ax, ay, m.x, m.y)-dis(tx, ty, m.x, m.y) < dis(ax, ay, n.x, n.y) -dis(tx, ty, n.x, n.y);
}
int cmp1(bott q, bott w)
{
	return dis(bx, by, q.x, q.y) - dis(tx, ty, q.x, q.y) < dis(bx, by, w.x, w.y)-dis(tx, ty, w.x, w.y);
}
int main()
{
	//freopen("C:\\in.txt", "r", stdin);
	double sum = 0;
	scanf("%d%d%d%d%d%d",&ax,&ay,&bx,&by,&tx,&ty);
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &bott1[i].x, &bott1[i].y);
		bott2[i].x = bott1[i].x;
		bott2[i].y = bott1[i].y;
	}
	sort(bott1, bott1 + n, cmp);
	sort(bott2, bott2 + n, cmp1);
	bott2[0].num = dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
	bott1[0].num = dis(ax, ay, bott1[0].x, bott1[0].y) + dis(tx, ty, bott1[0].x, bott1[0].y);
	if (bott1[0].x == bott2[0].x&& bott1[0].y == bott2[0].y)
	{
		bott1[0].num = min(bott1[0].num+dis(bx, by, bott2[1].x, bott2[1].y) + dis(tx, ty, bott2[1].x, bott2[1].y), bott2[0].num+ dis(ax, ay, bott1[1].x, bott1[1].y) + dis(tx, ty, bott1[1].x, bott1[1].y));
		bott1[1].num = 0;
		for (int i = 2; i < n; i++)
		{
			bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
	}
	else
	{
		bott1[0].num += dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
		for (int i = 1; i < n; i++)
		{
			if (bott1[i].x == bott2[0].x&& bott1[i].y == bott2[0].y)
				continue;
			else
				bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
	}
	for (int i = 0; i < n; i++)
		sum += bott1[i].num;
	printf("%.12f\n", sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
_int64 ax, ay, bx, by, tx, ty,n;
struct bott
{
	_int64 x, y;
	double num;
}bott1[100005],bott2[100005];
double dis(_int64 a, _int64 b, _int64 c, _int64 d)
{
	return pow(((a-c)*(a-c)+ (b - d)*(b - d)), 0.5);
}
int cmp(bott m, bott n)
{
	return dis(ax, ay, m.x, m.y)-dis(tx, ty, m.x, m.y) < dis(ax, ay, n.x, n.y) -dis(tx, ty, n.x, n.y);
}
int cmp1(bott q, bott w)
{
	return dis(bx, by, q.x, q.y) - dis(tx, ty, q.x, q.y) < dis(bx, by, w.x, w.y)-dis(tx, ty, w.x, w.y);
}
int main()
{
	//freopen("C:\\in.txt", "r", stdin);
	double sum = 0;
	scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&ax,&ay,&bx,&by,&tx,&ty);
	scanf("%I64d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &bott1[i].x, &bott1[i].y);
		bott2[i].x = bott1[i].x;
		bott2[i].y = bott1[i].y;
	}
	sort(bott1, bott1 + n, cmp);
	sort(bott2, bott2 + n, cmp1);
	bott2[0].num = dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
	bott1[0].num = dis(ax, ay, bott1[0].x, bott1[0].y) + dis(tx, ty, bott1[0].x, bott1[0].y);
	if (bott1[0].x == bott2[0].x&& bott1[0].y == bott2[0].y)
	{
		bott1[0].num = min(bott1[0].num+dis(bx, by, bott2[1].x, bott2[1].y) + dis(tx, ty, bott2[1].x, bott2[1].y), bott2[0].num+ dis(ax, ay, bott1[1].x, bott1[1].y) + dis(tx, ty, bott1[1].x, bott1[1].y));
		bott1[1].num = 0;
		for (int i = 2; i < n; i++)
		{
			bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
	}
	else
	{
		bott1[0].num += dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
		for (int i = 1; i < n; i++)
		{
			if (bott1[i].x == bott2[0].x&& bott1[i].y == bott2[0].y)
				continue;
			else
				bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
	}
	for (int i = 0; i < n; i++)
		sum += bott1[i].num;
	printf("%.12f\n", sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
long long ax, ay, bx, by, tx, ty,n;
struct bott
{
	long long x, y;
	double num;
}bott1[100005],bott2[100005];
double dis(long long a, long long b, long long c, long long d)
{
	return pow(((a-c)*(a-c)+ (b - d)*(b - d)), 0.5);
}
int cmp(bott m, bott n)
{
	return dis(ax, ay, m.x, m.y)-dis(tx, ty, m.x, m.y) < dis(ax, ay, n.x, n.y) -dis(tx, ty, n.x, n.y);
}
int cmp1(bott q, bott w)
{
	return dis(bx, by, q.x, q.y) - dis(tx, ty, q.x, q.y) < dis(bx, by, w.x, w.y)-dis(tx, ty, w.x, w.y);
}
int main()
{
	//freopen("C:\\in.txt", "r", stdin);
	double sum = 0;
	scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&ax,&ay,&bx,&by,&tx,&ty);
	scanf("%I64d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &bott1[i].x, &bott1[i].y);
		bott2[i].x = bott1[i].x;
		bott2[i].y = bott1[i].y;
	}
	sort(bott1, bott1 + n, cmp);
	sort(bott2, bott2 + n, cmp1);
	bott2[0].num = dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
	bott1[0].num = dis(ax, ay, bott1[0].x, bott1[0].y) + dis(tx, ty, bott1[0].x, bott1[0].y);
	if (bott1[0].x == bott2[0].x&& bott1[0].y == bott2[0].y)
	{
		bott1[0].num = min(bott1[0].num+dis(bx, by, bott2[1].x, bott2[1].y) + dis(tx, ty, bott2[1].x, bott2[1].y), bott2[0].num+ dis(ax, ay, bott1[1].x, bott1[1].y) + dis(tx, ty, bott1[1].x, bott1[1].y));
		bott1[1].num = 0;
		for (int i = 2; i < n; i++)
		{
			bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
		for (int i = 0; i < n; i++)
			sum += bott1[i].num;
		printf("%.12f\n", sum);
	}
	else
	{
		double num;
		for (int i = 0; i < n; i++)
			sum += 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) < 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) < 0)
		{
			num =dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y)+ dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y);
			sum += num;
		}
		 if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) < 0&& dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y)>=0)
			sum += dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y);
		if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) >= 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) < 0)
			sum += dis(bx, by, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y);
			printf("%.12f\n", sum);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
long long ax, ay, bx, by, tx, ty,n;
struct bott
{
	long long x, y;
	double num;
}bott1[100005],bott2[100005];
double dis(long long a, long long b, long long c, long long d)
{
	return pow(((a-c)*(a-c)+ (b - d)*(b - d)), 0.5);
}
int cmp(bott m, bott n)
{
	return dis(ax, ay, m.x, m.y)-dis(tx, ty, m.x, m.y) < dis(ax, ay, n.x, n.y) -dis(tx, ty, n.x, n.y);
}
int cmp1(bott q, bott w)
{
	return dis(bx, by, q.x, q.y) - dis(tx, ty, q.x, q.y) < dis(bx, by, w.x, w.y)-dis(tx, ty, w.x, w.y);
}
int main()
{
	//freopen("C:\\in.txt", "r", stdin);
	double sum = 0;
	scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&ax,&ay,&bx,&by,&tx,&ty);
	scanf("%I64d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &bott1[i].x, &bott1[i].y);
		bott2[i].x = bott1[i].x;
		bott2[i].y = bott1[i].y;
	}
	sort(bott1, bott1 + n, cmp);
	sort(bott2, bott2 + n, cmp1);
	bott2[0].num = dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
	bott1[0].num = dis(ax, ay, bott1[0].x, bott1[0].y) + dis(tx, ty, bott1[0].x, bott1[0].y);
	if (bott1[0].x == bott2[0].x&& bott1[0].y == bott2[0].y)
	{
		bott1[0].num = min(bott1[0].num+dis(bx, by, bott2[1].x, bott2[1].y) + dis(tx, ty, bott2[1].x, bott2[1].y), bott2[0].num+ dis(ax, ay, bott1[1].x, bott1[1].y) + dis(tx, ty, bott1[1].x, bott1[1].y));
		bott1[1].num = 0;
		for (int i = 2; i < n; i++)
		{
			bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
		for (int i = 0; i < n; i++)
			sum += bott1[i].num;
		printf("%.12f\n", sum);
	}
	else
	{
		double num;
		for (int i = 0; i < n; i++)
			sum += 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		 if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) < 0&& dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y)>=0)
			sum += dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y);
		else if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) >= 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) < 0)
			sum += dis(bx, by, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y);
		else
			{
				num = dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) + dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y);
				sum += num;
			}
		 printf("%.12f\n", sum);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
long long ax, ay, bx, by, tx, ty,n;
struct bott
{
	long long x, y;
	double num;
}bott1[100005],bott2[100005];
double dis(long long a, long long b, long long c, long long d)
{
	return pow(((a-c)*(a-c)+ (b - d)*(b - d)), 0.5);
}
int cmp(bott m, bott n)
{
	return dis(ax, ay, m.x, m.y)-dis(tx, ty, m.x, m.y) < dis(ax, ay, n.x, n.y) -dis(tx, ty, n.x, n.y);
}
int cmp1(bott q, bott w)
{
	return dis(bx, by, q.x, q.y) - dis(tx, ty, q.x, q.y) < dis(bx, by, w.x, w.y)-dis(tx, ty, w.x, w.y);
}
int main()
{
	//freopen("C:\\in.txt", "r", stdin);
	double sum = 0;
	scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&ax,&ay,&bx,&by,&tx,&ty);
	scanf("%I64d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &bott1[i].x, &bott1[i].y);
		bott2[i].x = bott1[i].x;
		bott2[i].y = bott1[i].y;
	}
	sort(bott1, bott1 + n, cmp);
	sort(bott2, bott2 + n, cmp1);
	bott2[0].num = dis(bx, by, bott2[0].x, bott2[0].y) + dis(tx, ty, bott2[0].x, bott2[0].y);
	bott1[0].num = dis(ax, ay, bott1[0].x, bott1[0].y) + dis(tx, ty, bott1[0].x, bott1[0].y);
	if (bott1[0].x == bott2[0].x&& bott1[0].y == bott2[0].y)
	{
		bott1[0].num = min(bott1[0].num+dis(bx, by, bott2[1].x, bott2[1].y) + dis(tx, ty, bott2[1].x, bott2[1].y), bott2[0].num+ dis(ax, ay, bott1[1].x, bott1[1].y) + dis(tx, ty, bott1[1].x, bott1[1].y));
		bott1[1].num = 0;
		for (int i = 2; i < n; i++)
		{
			bott1[i].num = 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		}
		for (int i = 0; i < n; i++)
			sum += bott1[i].num;
		printf("%.12f\n", sum);
	}
	else
	{
		int num;
		for (int i = 0; i < n; i++)
			sum += 2 * dis(tx, ty, bott1[i].x, bott1[i].y);
		if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) < 0 && dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y) < 0)
		{
			num = min(dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y), dis(bx, by, bott2[0].x, bott2[0].y) - dis(tx, ty, bott2[0].x, bott2[0].y));
			sum += num;
		}
		else if (dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y) < 0)
			sum += dis(ax, ay, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y);
		else
			sum += dis(bx, by, bott1[0].x, bott1[0].y) - dis(tx, ty, bott1[0].x, bott1[0].y);
			printf("%.12f\n", sum);
	}
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define X first
#define Y second
#define de(x,y) cout<<#x <<" :" << x<<y;
#define pb push_back
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
const int maxn = 2e5+5;
struct Edge{
    int u, v, w;
    bool operator < (const Edge &node) const{
        return node.w < w;
    }

};

priority_queue<Edge> pq;
vector<pii> G[maxn];
map<pii,int> mp;
main() {
    int n, m, k;
    cin >> n >> m >> k;
    for(int i=1; i<=m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        G[u].pb({v, w});
        G[v].pb({u, w});
        pq.push({u, v, w});
    }
    int ans;
    while(k && pq.size()) {
        Edge now = pq.top();pq.pop();
//        cout <<" Edge : "<< now.u << " " << now.v << " " << now.w << "\n";
        if(now.u > now.v) swap(now.u, now.v);
        if(mp.find({now.u, now.v}) != mp.end() || now.u == now.v) {
            continue;
        }
        mp[{now.u, now.v}] = now.w;
        ans = now.w;
        for(auto a:G[now.u]) {
            pq.push({a.X, now.v, a.Y + now.w});
        }
        for(auto a:G[now.v]) {
            pq.push({a.X, now.u, a.Y + now.w});
        }
        k--;

    }
    cout << ans << "\n";

}


#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define X first
#define Y second
#define de(x,y) cout<<#x <<" :" << x<<y;
#define pb push_back
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
const int maxn = 2e5+5;
struct Edge{
    int u, Fu, v, Fv, w;
    bool operator < (const Edge &node) const{
        return node.w < w;
    }

};

priority_queue<Edge> pq;
vector<pii> G[maxn];
map<pii,int> mp;
main() {
    IOS
    int n, m, k;
    cin >> n >> m >> k;
    for(int i=1; i<=m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        G[u].pb({v, w});
        G[v].pb({u, w});
        pq.push({u, v, v, u, w});
    }
    int ans;
    while(k && pq.size()) {
        Edge now = pq.top();pq.pop();
//        cout <<" Edge : "<< now.u << " " << now.v << " " << now.w << "\n";
        if(now.u > now.v) swap(now.u, now.v), swap(now.Fu, now.Fv);
        if(mp.find({now.u, now.v}) != mp.end() || now.u == now.v) {
            continue;
        }
        mp[{now.u, now.v}] = now.w;
        ans = now.w;
        for(auto a:G[now.u]) {
            if(a.X != now.Fu)
                pq.push({a.X, now.u, now.v, now.Fv, a.Y + now.w});
        }
        for(auto a:G[now.v]) {
            if(a.X != now.Fv)
                pq.push({now.u, now.Fu, a.X, now.v, a.Y + now.w});
        }
        k--;

    }
    cout << ans << "\n";

}


#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define X first
#define Y second
#define de(x,y) cout<<#x <<" :" << x<<y;
#define pb push_back
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
const int maxn = 2e5+5;
struct Edge{
    int u, v, w;
    bool operator < (const Edge &node) const{
        return node.w < w;
    }

};

priority_queue<Edge> pq;
vector<pii> G[maxn];
map<pii,int> mp;
main() {
    int n, m, k;
    cin >> n >> m >> k;
    for(int i=1; i<=m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        G[u].pb({v, w});
        G[v].pb({u, w});
        pq.push({u, v, w});
    }
    int ans;
    while(k && pq.size()) {
        Edge now = pq.top();pq.pop();
        cout <<" Edge : "<< now.u << " " << now.v << " " << now.w << "\n";
        if(now.u > now.v) swap(now.u, now.v);
        if(mp.find({now.u, now.v}) != mp.end() || now.u == now.v) {
            continue;
        }
        mp[{now.u, now.v}] = now.w;
        ans = now.w;
        for(auto a:G[now.u]) {
            pq.push({a.X, now.v, a.Y + now.w});
        }
        for(auto a:G[now.v]) {
            pq.push({a.X, now.u, a.Y + now.w});
        }
        k--;

    }
    cout << ans << "\n";

}


#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define X first
#define Y second
#define de(x,y) cout<<#x <<" :" << x<<y;
#define pb push_back
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
const int maxn = 2e5+5;
struct Edge{
    int u, Fu, v, Fv, w;
    bool operator < (const Edge &node) const{
        return node.w < w;
    }

};

priority_queue<Edge> pq;
vector<pii> G[maxn];
map<pii,int> mp;
vector<Edge> edge;
bool cmp(pii a,pii b) {
    return a.Y < b.Y;
}
main() {
    int n, m, k;
    cin >> n >> m >> k;
    for(int i=1; i<=m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        edge.pb({u, v, v, u, w});
        G[u].pb({v, w});
        G[v].pb({u, w});
        pq.push({u, v, v, u, w});
    }
    for(int i=1; i<=n; i++) {
        sort(G[i].begin(), G[i].end(), cmp);
    }
    sort(edge.begin(), edge.end());
    reverse(edge.begin(), edge.end());
    for(int i=0; i<min((int)edge.size(), k); i++) {
        pq.push(edge[i]);
    }
    int ans;
    while(k && pq.size()) {
        Edge now = pq.top();pq.pop();
  //      cout <<" Edge : "<< now.u << " " << now.v << " " << now.w << "\n";
        if(now.u > now.v) swap(now.u, now.v), swap(now.Fu, now.Fv);
        if(mp.find({now.u, now.v}) != mp.end() || now.u == now.v) {
            continue;
        }
        mp[{now.u, now.v}] = now.w;
        ans = now.w;

        for(auto a:G[now.u]) {
            if(pq.size() > 500000) break;
            if(a.X != now.Fu)
                pq.push({a.X, now.u, now.v, now.Fv, a.Y + now.w});
        }
        for(auto a:G[now.v]) {
            if(pq.size() > 500000) break;
            if(a.X != now.Fv)
                pq.push({now.u, now.Fu, a.X, now.v, a.Y + now.w});
        }
        k--;

    }
    cout << ans << "\n";

}


#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define X first
#define Y second
#define de(x,y) cout<<#x <<" :" << x<<y;
#define pb push_back
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
const int maxn = 2e5+5;
struct Edge{
    int u, Fu, v, Fv, w;
    bool operator < (const Edge &node) const{
        return node.w < w;
    }

};

priority_queue<Edge> pq;
vector<pii> G[maxn];
map<pii,int> mp;
vector<Edge> edge;
bool cmp(pii a,pii b) {
    return a.Y < b.Y;
}
main() {
    int n, m, k;
    cin >> n >> m >> k;
    for(int i=1; i<=m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        edge.pb({u, v, v, u, w});
        G[u].pb({v, w});
        G[v].pb({u, w});
        pq.push({u, v, v, u, w});
    }
    for(int i=1; i<=n; i++) {
        sort(G[i].begin(), G[i].end(), cmp);
    }
    sort(edge.begin(), edge.end());
    reverse(edge.begin(), edge.end());
    for(int i=0; i<min((int)edge.size(), k); i++) {
        pq.push(edge[i]);
    }
    int ans;
    while(k && pq.size()) {
        Edge now = pq.top();pq.pop();
  //      cout <<" Edge : "<< now.u << " " << now.v << " " << now.w << "\n";
        if(now.u > now.v) swap(now.u, now.v), swap(now.Fu, now.Fv);
        if(mp.find({now.u, now.v}) != mp.end() || now.u == now.v) {
            continue;
        }
        mp[{now.u, now.v}] = now.w;
        ans = now.w;

        for(auto a:G[now.u] && pq.size() <= 500000) {
            if(a.X != now.Fu)
                pq.push({a.X, now.u, now.v, now.Fv, a.Y + now.w});
        }
        for(auto a:G[now.v] && pq.size() <= 500000) {
            if(a.X != now.Fv)
                pq.push({now.u, now.Fu, a.X, now.v, a.Y + now.w});
        }
        k--;

    }
    cout << ans << "\n";

}


#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define X first
#define Y second
#define de(x,y) cout<<#x <<" :" << x<<y;
#define pb push_back
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
const int maxn = 2e5+5;
struct Edge{
    int u, Fu, v, Fv, w;
    bool operator < (const Edge &node) const{
        return node.w < w;
    }

};

priority_queue<Edge> pq;
vector<pii> G[maxn];
map<pii,int> mp;
vector<Edge> edge;
main() {
    int n, m, k;
    cin >> n >> m >> k;
    for(int i=1; i<=m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        edge.pb({u, v, v, u, w});
        G[u].pb({v, w});
        G[v].pb({u, w});
        pq.push({u, v, v, u, w});
    }
    sort(edge.begin(), edge.end());
    reverse(edge.begin(), edge.end());
    for(int i=0; i<min((int)edge.size(), k); i++) {
        pq.push(edge[i]);
    }
    int ans;
    while(k && pq.size()) {
        Edge now = pq.top();pq.pop();
//        cout <<" Edge : "<< now.u << " " << now.v << " " << now.w << "\n";
        if(now.u > now.v) swap(now.u, now.v), swap(now.Fu, now.Fv);
        if(mp.find({now.u, now.v}) != mp.end() || now.u == now.v) {
            continue;
        }
        mp[{now.u, now.v}] = now.w;
        ans = now.w;
        for(auto a:G[now.u]) {
            if(a.X != now.Fu)
                pq.push({a.X, now.u, now.v, now.Fv, a.Y + now.w});
        }
        for(auto a:G[now.v]) {
            if(a.X != now.Fv)
                pq.push({now.u, now.Fu, a.X, now.v, a.Y + now.w});
        }
        k--;

    }
    cout << ans << "\n";

}


#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<cstring>
using namespace std;
long long d[1005][1005];
struct node{
	int u,v,w;
};
bool cmp(node a,node b){
	return a.w<b.w;
}
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	memset(d,0x3f,sizeof d);
	if(n<100){
		for(int i=1;i<=m;++i){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			d[x][y]=d[y][x]=z;
		}
	}
	else {
		int cnt=0;
		vector<node> q;
		for(int i=1;i<=m;++i){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			q.push_back((node){x,y,z});
		}
		sort(q.begin(),q.end(),cmp);
		map<int ,int >mm;
		while((int)q.size()>k)q.pop_back();
		for(int i=0;i<(int)q.size();++i){
			if(!mm[q[i].u])mm[q[i].u]=++cnt;
			if(!mm[q[i].v])mm[q[i].v]=++cnt;
		}
		for(int i=0;i<(int)q.size();++i){
			int u=mm[q[i].u];
			int v=mm[q[i].v];
			d[u][v]=d[v][u]=q[i].w;
		}
		n=cnt;
	}
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				if(d[i][j]>d[i][k]+d[k][j])
					d[i][j]=d[i][k]+d[k][j];
	vector<long long>p;
	for(int i=2;i<=n;++i)
		for(int j=1;j<i;++j)
			p.push_back(d[i][j]);
	sort(p.begin(),p.end());
	printf("%Ld",p[k-1]);
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<cstring>
using namespace std;
long long d[805][805];
long long p[320000];
struct node{
	int u,v,w;
};
bool cmp(node a,node b){
	return a.w<b.w;
}
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	memset(d,0x3f,sizeof d);
	if(n<100){
		for(int i=1;i<=m;++i){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			d[x][y]=d[y][x]=z;
		}
	}
	else {
		int cnt=0;
		vector<node> q;
		for(int i=1;i<=m;++i){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			q.push_back((node){x,y,z});
		}
		sort(q.begin(),q.end(),cmp);
		map<int ,int >mm;
		while((int)q.size()>k)q.pop_back();
		for(int i=0;i<(int)q.size();++i){
			if(!mm[q[i].u])mm[q[i].u]=++cnt;
			if(!mm[q[i].v])mm[q[i].v]=++cnt;
		}
		for(int i=0;i<(int)q.size();++i){
			int u=mm[q[i].u];
			int v=mm[q[i].v];
			d[u][v]=d[v][u]=q[i].w;
		}
		n=cnt;
	}
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				if(d[i][j]>d[i][k]+d[k][j])
					d[i][j]=d[i][k]+d[k][j];
	int toto=0;
	for(int i=2;i<=n;++i)
		for(int j=1;j<i;++j)
			p[++toto]=d[i][j];
	sort(p+1,p+toto+1);
	printf("%lld",p[k]);
}


#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
long long d[1005][1005];
struct node{
	int u,v,w;
};
bool cmp(node a,node b){
	return a.w<b.w;
}
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=1001;++i)
		for(int j=1;j<=1001;++j)
			if(i!=j)d[i][j]=1000000000000000;
	if(n>400){
		int cnt=0;
		vector<node> q;
		for(int i=1;i<=m;++i){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			q.push_back((node){x,y,z});
		}
		sort(q.begin(),q.end(),cmp);
		map<int ,int >mm;
		while((int)q.size()>k)q.pop_back();
		for(int i=0;i<(int)q.size();++i){
			if(!mm[q[i].u])mm[q[i].u]=++cnt;
			if(!mm[q[i].v])mm[q[i].v]=++cnt;
		}
		for(int i=0;i<(int)q.size();++i){
			int u=mm[q[i].u];
			int v=mm[q[i].v];
			d[u][v]=d[v][u]=q[i].w;
		}
		n=cnt;
	}
	else for(int i=1;i<=m;++i){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		if(d[x][y]>z)d[x][y]=d[y][x]=z;
	}
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				if(d[i][j]>d[i][k]+d[k][j])
					d[i][j]=d[i][k]+d[k][j];
	priority_queue<long long ,vector<long long  >,greater<long long > >p;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			p.push(d[i][j]);
	while(k--)p.pop();
	printf("%Ld",p.top());
}


// luogu-judger-enable-o2
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<cstring>
using namespace std;
long long d[805][805];
long long p[320000];
struct node{
	int u,v,w;
};
bool cmp(node a,node b){
	return a.w<b.w;
}
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	memset(d,0x3f,sizeof d);
	if(n<100){
		for(int i=1;i<=m;++i){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			d[x][y]=d[y][x]=z;
		}
	}
	else {
		int cnt=0;
		vector<node> q;
		for(int i=1;i<=m;++i){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			q.push_back((node){x,y,z});
		}
		sort(q.begin(),q.end(),cmp);
		map<int ,int >mm;
		while((int)q.size()>k)q.pop_back();
		for(int i=0;i<(int)q.size();++i){
			if(!mm[q[i].u])mm[q[i].u]=++cnt;
			if(!mm[q[i].v])mm[q[i].v]=++cnt;
		}
		for(int i=0;i<(int)q.size();++i){
			int u=mm[q[i].u];
			int v=mm[q[i].v];
			d[u][v]=d[v][u]=q[i].w;
		}
		n=cnt;
	}
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				if(d[i][j]>d[i][k]+d[k][j])
					d[i][j]=d[i][k]+d[k][j];
	int toto=0;
	for(int i=2;i<=n;++i)
		for(int j=1;j<i;++j)
			p[++toto]=d[i][j];
	sort(p+1,p+toto+1);
	printf("%lld",p[k]);
}


#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
long long d[1005][1005];
struct node{
	int u,v,w;
};
bool cmp(node a,node b){
	return a.w<b.w;
}
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=1001;++i)
		for(int j=1;j<=1001;++j)
			d[i][j]=1000000000000000;
	if(n>400){
		int cnt=0;
		vector<node> q;
		for(int i=1;i<=m;++i){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			q.push_back((node){x,y,z});
		}
		sort(q.begin(),q.end(),cmp);
		map<int ,int >mm;
		while((int)q.size()>k)q.pop_back();
		for(int i=0;i<(int)q.size();++i){
			if(!mm[q[i].u])mm[q[i].u]=++cnt;
			if(!mm[q[i].v])mm[q[i].v]=++cnt;
		}
		for(int i=0;i<(int)q.size();++i){
			int u=mm[q[i].u];
			int v=mm[q[i].v];
			d[u][v]=d[v][u]=q[i].w;
		}
		n=cnt;
	}
	else for(int i=1;i<=m;++i){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		d[x][y]=d[y][x]=z;
	}
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				if(i!=j&&k!=i&&d[i][j]>d[i][k]+d[k][j])
					d[i][j]=d[i][k]+d[k][j];
	priority_queue<long long ,vector<long long  >,greater<long long > >p;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			p.push(d[i][j]);
	while(k--)p.pop();
	printf("%lld",p.top());
}


#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
long long d[1005][1005];
struct node{
	int u,v,w;
};
bool cmp(node a,node b){
	return a.w<b.w;
}
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	memset(d,0x3f,sizeof d);
	if(n>100){
		int cnt=0;
		vector<node> q;
		for(int i=1;i<=m;++i){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			q.push_back((node){x,y,z});
		}
		sort(q.begin(),q.end(),cmp);
		map<int ,int >mm;
		while((int)q.size()>k)q.pop_back();
		for(int i=0;i<(int)q.size();++i){
			if(!mm[q[i].u])mm[q[i].u]=++cnt;
			if(!mm[q[i].v])mm[q[i].v]=++cnt;
		}
		for(int i=0;i<(int)q.size();++i){
			int u=mm[q[i].u];
			int v=mm[q[i].v];
			d[u][v]=d[v][u]=q[i].w;
		}
		n=cnt;
	}
	else for(int i=1;i<=m;++i){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		if(d[x][y]>z)d[x][y]=d[y][x]=z;
	}
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				if(d[i][j]>d[i][k]+d[k][j])
					d[i][j]=d[i][k]+d[k][j];
	priority_queue<long long ,vector<long long  >,greater<long long > >p;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			p.push(d[i][j]);
	while(k--)p.pop();
	printf("%Ld",p.top());
}


// luogu-judger-enable-o2
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
int d[500][500],cnt;
struct node{
	int u,v,w;
};
bool cmp(node a,node b){
	return a.w<b.w;
}
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	memset(d,0x3f,sizeof d);
	if(n>400){
		vector<node> q;
		for(int i=1;i<=m;++i){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			q.push_back((node){x,y,z});
		}
		sort(q.begin(),q.end(),cmp);
		map<int ,int >mm;
		while((int)q.size()>k)q.pop_back();
		for(int i=0;i<(int)q.size();++i){
			if(!mm[q[i].u])mm[q[i].u]=++cnt;
			if(!mm[q[i].v])mm[q[i].v]=++cnt;
		}
		for(int i=0;i<(int)q.size();++i){
			int u=mm[q[i].u];
			int v=mm[q[i].v];
			d[u][v]=d[v][u]=q[i].w;
		}
		n=cnt;
	}
	else for(int i=1;i<=m;++i){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		d[x][y]=d[y][x]=z;
	}
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				if(d[i][j]>d[i][k]+d[k][j])
					d[i][j]=d[i][k]+d[k][j];
	priority_queue<int ,vector<int >,greater<int > >p;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			p.push(d[i][j]);
	while(k--)p.pop();
	printf("%d",p.top());
}


#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<cstring>
using namespace std;
long long d[805][805];
long long p[320000];
struct node{
	int u,v,w;
};
bool cmp(node a,node b){
	return a.w<b.w;
}
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	memset(d,0x3f,sizeof d);
	if(n<100){
		for(int i=1;i<=m;++i){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			d[x][y]=d[y][x]=z;
		}
	}
	else {
		int cnt=0;
		vector<node> q;
		for(int i=1;i<=m;++i){
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			q.push_back((node){x,y,z});
		}
		sort(q.begin(),q.end(),cmp);
		map<int ,int >mm;
		while((int)q.size()>k)q.pop_back();
		for(int i=0;i<(int)q.size();++i){
			if(!mm[q[i].u])mm[q[i].u]=++cnt;
			if(!mm[q[i].v])mm[q[i].v]=++cnt;
		}
		for(int i=0;i<(int)q.size();++i){
			int u=mm[q[i].u];
			int v=mm[q[i].v];
			d[u][v]=d[v][u]=q[i].w;
		}
		n=cnt;
	}
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				if(d[i][j]>d[i][k]+d[k][j])
					d[i][j]=d[i][k]+d[k][j];
	int toto=0;
	for(int i=2;i<=n;++i)
		for(int j=1;j<i;++j)
			p[++toto]=d[i][j];
	sort(p+1,p+toto+1);
	printf("%lld",p[k]);
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200010;

typedef pair<int,int> ii;

vector<ii> adj[MAXN];
set< pair<long long, ii> > P;
map<int, long long> min_dist[MAXN];
set<ii> done;
int n, m, k;

void add_path(int u, int v, long long dist){
  if(u > v) swap(u, v);
  if(u == v or done.count(ii(u, v))) return;

  if(min_dist[u].count(v) and min_dist[u][v] <= dist){
    return;
  }

  P.erase(make_pair(min_dist[u][v], ii(u, v)));
  min_dist[u][v] = dist;
  P.insert(make_pair(dist, ii(u, v)));

  if(P.size() > k){
    pair<long long, ii> tmp = *P.rbegin();
    int u = tmp.second.first, v = tmp.second.second;
    P.erase(tmp);
    min_dist[u].erase(v);
  }
}

int main(){
  while(scanf("%d%d%d", &n, &m, &k) > 0){
    P.clear(); done.clear();

    while(m--){
      int x, y, w;
      scanf("%d%d%d", &x, &y, &w);
      adj[x].push_back(ii(y, w));
      adj[y].push_back(ii(x, w));
      add_path(x, y, w);
    }

    for(int j=0; j<k-1; j++){
      long long dist;
      int u, v;

      do {
        pair<long long, ii> tmp = *P.begin(); P.erase(tmp);
        dist = tmp.first;
        u = tmp.second.first;
        v = tmp.second.second;
      } while(done.count(ii(u, v)));

      done.insert(ii(u, v));

      for(int i=0; i<adj[u].size(); i++){
        int x = adj[u][i].first, w = adj[u][i].second;
        add_path(v, x, dist+w);
      }

      for(int i=0; i<adj[v].size(); i++){
        int x = adj[v][i].first, w = adj[v][i].second;
        add_path(u, x, dist+w);
      }
    }

    printf("%lld\n", P.begin()->first);

    for(int i=1; i<=n; i++){
      adj[i].clear();
      min_dist[i].clear();
    }
  }
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200010;

typedef pair<int,int> ii;

vector<ii> adj[MAXN];
set< pair<long long, ii> > P;
map<int, long long> min_dist[MAXN];
set<ii> done;
int n, m, k;

void add_path(int u, int v, long long dist){
  if(u > v) swap(u, v);
  if(u == v or done.count(ii(u, v))) return;

  P.insert(make_pair(dist, ii(u, v)));
}

int main(){
  while(scanf("%d%d%d", &n, &m, &k) > 0){
    P.clear(); done.clear();

    while(m--){
      int x, y, w;
      scanf("%d%d%d", &x, &y, &w);
      adj[x].push_back(ii(y, w));
      adj[y].push_back(ii(x, w));
      add_path(x, y, w);
    }

    for(int j=0; j<k-1; j++){
      long long dist;
      int u, v;

      do {
        pair<long long, ii> tmp = *P.begin(); P.erase(tmp);
        dist = tmp.first;
        u = tmp.second.first;
        v = tmp.second.second;
      } while(done.count(ii(u, v)));

      done.insert(ii(u, v));

      for(int i=0; i<adj[u].size(); i++){
        int x = adj[u][i].first, w = adj[u][i].second;
        add_path(v, x, dist+w);
      }

      for(int i=0; i<adj[v].size(); i++){
        int x = adj[v][i].first, w = adj[v][i].second;
        add_path(u, x, dist+w);
      }
    }

    printf("%lld\n", P.begin()->first);

    for(int i=1; i<=n; i++){
      adj[i].clear();
      min_dist[i].clear();
    }
  }
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200010;

typedef pair<int,int> ii;

vector<ii> adj[MAXN];
set< pair<long long, ii> > P;
map<int, long long> min_dist[MAXN];
int n, m, k;

void add_path(int u, int v, long long dist){
  if(u > v) swap(u, v);
  if(u == v or min_dist[u].count(v) and min_dist[u][v] <= dist) return;

  P.erase(make_pair(min_dist[u][v], ii(u, v)));
  min_dist[u][v] = dist;
  P.insert(make_pair(min_dist[u][v], ii(u, v)));

  if(P.size() > k){
    P.erase(*P.rbegin());
  }
}

int main(){
  while(scanf("%d%d%d", &n, &m, &k) > 0){
    P.clear();

    while(m--){
      int x, y, w;
      scanf("%d%d%d", &x, &y, &w);
      adj[x].push_back(ii(y, w));
      adj[y].push_back(ii(x, w));
      add_path(x, y, w);
    }

    for(int j=0; j<k-1; j++){
      pair<long long, ii> tmp = *P.begin(); P.erase(tmp);
      long long dist = tmp.first;
      int u = tmp.second.first, v = tmp.second.second;

      for(int i=0; i<adj[u].size(); i++){
        int x = adj[u][i].first, w = adj[u][i].second;
        add_path(v, x, dist+w);
      }

      for(int i=0; i<adj[v].size(); i++){
        int x = adj[v][i].first, w = adj[v][i].second;
        add_path(u, x, dist+w);
      }
    }

    printf("%lld\n", P.begin()->first);

    for(int i=1; i<=n; i++){
      adj[i].clear();
      min_dist[i].clear();
    }
  }
}


#include <bits/stdc++.h>

using namespace std;

const long long INF = (1ll << 60);

const int MAXK = 410;
const int MAXM = 200010;

typedef pair<int,int> ii;

pair<int, ii> E[MAXM];
long long adj[MAXK][MAXK];

int main(){
  int n, m, k;
  while(scanf("%d%d%d", &n, &m, &k) > 0){
    for(int i=0; i<m; i++){
      int x, y, w;
      scanf("%d%d%d", &x, &y, &w);
      E[i] = make_pair(w, ii(x, y));
    }

    sort(E, E+m);

    m = min(k, m);
    map<int,int> cvt;

    for(int i=0; i<m; i++){
      cvt[E[i].second.first] = 0;
      cvt[E[i].second.second] = 0;
    }

    n = 0;
    for(map<int,int>::iterator it=cvt.begin(); it!=cvt.end(); it++){
      it->second = ++n;
    }

    for(int i=1; i<=n; i++){
      for(int j=1; j<=n; j++){
        adj[i][j] = INF * (i != j);
      }
    }

    for(int i=0; i<m; i++){
      int u = cvt[E[i].second.first];
      int v = cvt[E[i].second.second];
      int w = E[i].first;
      adj[u][v] = adj[v][u] = w;
    }

    for(int l=1; l<=n; l++){
      for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
          adj[i][j] = min(adj[i][j], adj[i][l] + adj[l][j]);
        }
      }
    }

    vector<long long> Ds;

    for(int i=1; i<=n; i++){
      for(int j=i+1; j<=n; j++){
        if(adj[i][j] != INF){
          Ds.push_back(adj[i][j]);
        }
      }
    }

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

    printf("%lld\n", Ds[k-1]);
  }
}


#include <bits/stdc++.h>

using namespace std;

const long long INF = (1ll << 60);

const int MAXK = 410;
const int MAXM = 200010;

typedef pair<int,int> ii;

pair<int, ii> E[MAXM];
long long adj[2*MAXK][2*MAXK];

int main(){
  int n, m, k;
  while(scanf("%d%d%d", &n, &m, &k) > 0){
    for(int i=0; i<m; i++){
      int x, y, w;
      scanf("%d%d%d", &x, &y, &w);
      E[i] = make_pair(w, ii(x, y));
    }

    sort(E, E+m);

    m = min(k, m);
    map<int,int> cvt;

    for(int i=0; i<m; i++){
      cvt[E[i].second.first] = 0;
      cvt[E[i].second.second] = 0;
    }

    n = 0;
    for(map<int,int>::iterator it=cvt.begin(); it!=cvt.end(); it++){
      it->second = ++n;
    }

    for(int i=1; i<=n; i++){
      for(int j=1; j<=n; j++){
        adj[i][j] = INF * (i != j);
      }
    }

    for(int i=0; i<m; i++){
      int u = cvt[E[i].second.first];
      int v = cvt[E[i].second.second];
      int w = E[i].first;
      adj[u][v] = adj[v][u] = w;
    }

    for(int l=1; l<=n; l++){
      for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
          adj[i][j] = min(adj[i][j], adj[i][l] + adj[l][j]);
        }
      }
    }

    vector<long long> Ds;

    for(int i=1; i<=n; i++){
      for(int j=i+1; j<=n; j++){
        if(adj[i][j] != INF){
          Ds.push_back(adj[i][j]);
        }
      }
    }

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

    printf("%lld\n", Ds[k-1]);
  }
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200010;

typedef pair<int,int> ii;

vector<ii> adj[MAXN];
set< pair<long long, ii> > P;
map<ii, long long> min_dist;
int n, m, k;

void add_path(int u, int v, long long dist){
  if(u > v) swap(u, v);
  if(u == v) return;

  if(min_dist.count(ii(u, v)) and min_dist[ii(u, v)] <= dist){
    return;
  }

  P.insert(make_pair(dist, ii(u, v)));
  min_dist[ii(u, v)] = dist;

  pair<long long, ii> tmp = make_pair(dist, ii(u, v));
  //printf("%lld (%d, %d)\n", tmp.first, tmp.second.first, tmp.second.second);

  if(P.size() > k){
    //pair<long long, ii> tmp = *P.rbegin();
    //printf("removing %lld (%d, %d)\n", tmp.first, tmp.second.first, tmp.second.second);
    //exit(0);
    P.erase(*P.rbegin());
  }

  /*
  printf("\n");
  for(auto tmp : P){
    printf("%d --- %d : %lld\n", tmp.second.first, tmp.second.second, tmp.first);
  }
  printf("\n");*/
}

int main(){
  while(scanf("%d%d%d", &n, &m, &k) > 0){
    P.clear(); min_dist.clear();

    while(m--){
      int x, y, w;
      scanf("%d%d%d", &x, &y, &w);
      adj[x].push_back(ii(y, w));
      adj[y].push_back(ii(x, w));
      add_path(x, y, w);
    }

    for(int j=0; j<k-1; j++){
      pair<long long, ii> tmp = *P.begin(); P.erase(tmp);
      long long dist = tmp.first;
      int u = tmp.second.first, v = tmp.second.second;
      //printf("(u, v) = (%d, %d) : %lld\n", u, v, dist);

      for(int i=0; i<adj[u].size(); i++){
        int x = adj[u][i].first, w = adj[u][i].second;
        add_path(v, x, dist+w);
      }

      for(int i=0; i<adj[v].size(); i++){
        int x = adj[v][i].first, w = adj[v][i].second;
        add_path(u, x, dist+w);
      }
    }

    printf("%lld\n", P.begin()->first);

    for(int i=1; i<=n; i++){
      adj[i].clear();
    }
  }
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200010;

typedef pair<int,int> ii;

vector<ii> adj[MAXN];
set< pair<long long, ii> > P;
map<ii, long long> min_dist;
int n, m, k;

void add_path(int u, int v, long long dist){
  if(u > v) swap(u, v);
  if(u == v or min_dist.count(ii(u, v)) and min_dist[ii(u, v)] <= dist) return;

  P.erase(make_pair(min_dist[ii(u, v)], ii(u, v)));
  min_dist[ii(u, v)] = dist;
  P.insert(make_pair(min_dist[ii(u, v)], ii(u, v)));

  //pair<long long, ii> tmp = make_pair(dist, ii(u, v));
  //printf("%lld (%d, %d)\n", tmp.first, tmp.second.first, tmp.second.second);

  if(P.size() > k){
    //pair<long long, ii> tmp = *P.rbegin();
    //printf("removing %lld (%d, %d)\n", tmp.first, tmp.second.first, tmp.second.second);
    //exit(0);
    P.erase(*P.rbegin());
  }

  /*
  printf("\n");
  for(auto tmp : P){
    printf("%d --- %d : %lld\n", tmp.second.first, tmp.second.second, tmp.first);
  }
  printf("\n");*/
}

int main(){
  while(scanf("%d%d%d", &n, &m, &k) > 0){
    P.clear(); min_dist.clear();

    while(m--){
      int x, y, w;
      scanf("%d%d%d", &x, &y, &w);
      adj[x].push_back(ii(y, w));
      adj[y].push_back(ii(x, w));
      add_path(x, y, w);
    }

    for(int j=0; j<k-1; j++){
      pair<long long, ii> tmp = *P.begin(); P.erase(tmp);
      long long dist = tmp.first;
      int u = tmp.second.first, v = tmp.second.second;
      //printf("(u, v) = (%d, %d) : %lld\n", u, v, dist);

      for(int i=0; i<adj[u].size(); i++){
        int x = adj[u][i].first, w = adj[u][i].second;
        add_path(v, x, dist+w);
      }

      for(int i=0; i<adj[v].size(); i++){
        int x = adj[v][i].first, w = adj[v][i].second;
        add_path(u, x, dist+w);
      }
    }

    printf("%lld\n", P.begin()->first);

    for(int i=1; i<=n; i++){
      adj[i].clear();
    }
  }
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200010;

typedef pair<int,int> ii;

vector<ii> adj[MAXN];
set< pair<long long, ii> > P;
map<int, long long> min_dist[MAXN];
int n, m, k;

void add_path(int u, int v, long long dist){
  if(u > v) swap(u, v);
  if(u == v) return;

  if(min_dist[u].count(v)){
    if(min_dist[u][v] <= dist){
      return;
    }
    P.erase(make_pair(min_dist[u][v], ii(u, v)));
  }

  min_dist[u][v] = dist;
  P.insert(make_pair(dist, ii(u, v)));

  if(P.size() > k){
    pair<long long, ii> tmp = *P.rbegin();
    int u = tmp.second.first, v = tmp.second.second;
    P.erase(tmp);
    min_dist[u].erase(v);
  }
}

int main(){
  while(scanf("%d%d%d", &n, &m, &k) > 0){
    P.clear();

    while(m--){
      int x, y, w;
      scanf("%d%d%d", &x, &y, &w);
      adj[x].push_back(ii(y, w));
      adj[y].push_back(ii(x, w));
      add_path(x, y, w);
    }

    for(int j=0; j<k-1; j++){
      pair<long long, ii> tmp = *P.begin(); P.erase(tmp);
      long long dist = tmp.first;
      int u = tmp.second.first;
      int v = tmp.second.second;

      for(int i=0; i<adj[u].size(); i++){
        int x = adj[u][i].first, w = adj[u][i].second;
        add_path(v, x, dist+w);
      }

      for(int i=0; i<adj[v].size(); i++){
        int x = adj[v][i].first, w = adj[v][i].second;
        add_path(u, x, dist+w);
      }
    }

    printf("%lld\n", P.begin()->first);

    for(int i=1; i<=n; i++){
      adj[i].clear();
      min_dist[i].clear();
    }
  }
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
struct edge{
    int u,v;
    long long c;
    bool operator<(const edge &tmp)const{
        return c<tmp.c;
    }
}A[N];
bool vis[N];
int B[808],C[808];
long long dis[808][808],D[808*404];
int main(){
    int n,m,k,maxx=0;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<m;i++){
        int u,v,c;
        scanf("%d %d %I64d",&A[i].u,&A[i].v,&A[i].c);
    }
    int b=min(k,m),c=0;
    sort(A,A+m);
    for(int i=0;i<b;i++){
        if(!vis[A[i].u]){
            B[++c]=A[i].u;
            vis[A[i].u]=1;
        }
        if(!vis[A[i].v]){
            B[++c]=A[i].v;
            vis[A[i].v]=1;
        }
    }
    sort(B+1,B+1+c);
    memset(dis,0x3f3f,sizeof(dis));
    for(int i=0;i<b;i++){
        int u=lower_bound(B+1,B+1+c,A[i].u)-B;
        int v=lower_bound(B+1,B+1+c,A[i].v)-B;
        dis[u][v]=dis[v][u]=A[i].c;
    }
    for(int i=1;i<=c;i++){
        for(int j=1;j<=c;j++){
            for(int k=1;k<=c;k++){
                dis[j][k]=min(dis[j][k],dis[j][i]+dis[i][k]);
            }
        }
    }
    int d=0;
    for(int i=1;i<c;i++){
        for(int j=i+1;j<=c;j++){
            D[++d]=dis[i][j];
        }
    }
    sort(D+1,D+1+d);
    printf("%I64d\n",D[k]);
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
struct edge{
    int u,v;
    long long c;
    bool operator<(const edge &tmp)const{
        return c>tmp.c;
    }
};
struct node{
    int t,c;
};
vector<node>mp[N];
priority_queue<edge>q;
map<int,map<int,int> >dis;
int main(){
    int n,m,k,maxx=0;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<m;i++){
        int u,v,c;
        scanf("%d %d %d",&u,&v,&c);
        if(u>v)swap(u,v);
        mp[u].push_back({v,c});
        mp[v].push_back({u,c});
        q.push({u,v,c});
        dis[u][v]=c;
    }
    while(!q.empty()){
        edge e=q.top(); q.pop();
        if(--k==0){
            printf("%I64d\n",e.c);
            return 0;
        }
        for(int i=0;i<mp[e.u].size();i++){
            node x=mp[e.u][i];
            int u=x.t,v=e.v;
            if(u>v)swap(u,v);
            if(u==v)continue;
            if(!dis[u].count(v)||e.c+x.c<dis[u][v]){
                q.push({u,v,e.c+x.c});
                dis[u][v]=e.c+x.c;
            }
        }
        for(int i=0;i<mp[e.v].size();i++){
            node x=mp[e.v][i];
            int u=x.t,v=e.u;
            if(u>v)swap(u,v);
            if(u==v)continue;
            if(!dis[u].count(v)||e.c+x.c<dis[u][v]){
                q.push({u,v,e.c+x.c});
                dis[u][v]=e.c+x.c;
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
struct edge{
    int u,v;
    long long c;
    bool operator<(const edge &tmp)const{
        return c>tmp.c;
    }
};
struct node{
    int t,c;
};
vector<node>mp[N];
priority_queue<edge>q;
map<int,map<int,bool> >vis;
int main(){
    int n,m,k;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<m;i++){
        int u,v,c;
        scanf("%d %d %d",&u,&v,&c);
        if(u>v)swap(u,v);
        mp[u].push_back({v,c});
        mp[v].push_back({u,c});
        q.push({u,v,c});
    }
    while(!q.empty()){
        edge e=q.top(); q.pop();
        if(vis[e.u][e.v])continue;
        vis[e.u][e.v]=1;
        if(--k==0){
            printf("%I64d\n",e.c);
            return 0;
        }
        for(int i=0;i<mp[e.u].size();i++){
            node x=mp[e.u][i];
            int u=x.t,v=e.v;
            if(u>v)swap(u,v);
            if(u==v)continue;
            q.push({u,v,e.c+x.c});
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
struct edge{
    int u,v;
    long long c;
    bool operator<(const edge &tmp)const{
        return c>tmp.c;
    }
};
struct node{
    int t,c;
};
vector<node>mp[N];
priority_queue<edge>q;
map<int,map<int,int> >dis,vis;
int main(){
    int n,m,k,maxx=0;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<m;i++){
        int u,v,c;
        scanf("%d %d %d",&u,&v,&c);
        if(u>v)swap(u,v);
        mp[u].push_back({v,c});
        mp[v].push_back({u,c});
        q.push({u,v,c});
        dis[u][v]=c;
    }
    while(!q.empty()){
        edge e=q.top(); q.pop();
        if(vis[e.u][e.v])continue;
        vis[e.u][e.v]=1;
        if(--k==0){
            printf("%I64d\n",e.c);
            return 0;
        }
        for(int i=0;i<mp[e.u].size();i++){
            node x=mp[e.u][i];
            int u=x.t,v=e.v;
            if(u>v)swap(u,v);
            if(u==v)continue;
            if(!dis[u].count(v)||e.c+x.c<dis[u][v]){
                q.push({u,v,e.c+x.c});
                dis[u][v]=e.c+x.c;
            }
        }
        for(int i=0;i<mp[e.v].size();i++){
            node x=mp[e.v][i];
            int u=x.t,v=e.u;
            if(u>v)swap(u,v);
            if(u==v)continue;
            if(!dis[u].count(v)||e.c+x.c<dis[u][v]){
                q.push({u,v,e.c+x.c});
                dis[u][v]=e.c+x.c;
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
struct edge{
    int u,v;
    long long c;
    bool operator<(const edge &tmp)const{
        return c>tmp.c;
    }
};
struct node{
    int t,c;
};
vector<node>mp[N];
priority_queue<edge>q;
map<int,map<int,bool> >vis;
int main(){
    int n,m,k,maxx=0;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<m;i++){
        int u,v,c;
        scanf("%d %d %d",&u,&v,&c);
        if(u>v)swap(u,v);
        mp[u].push_back({v,c});
        mp[v].push_back({u,c});
        q.push({u,v,c});
    }
    while(!q.empty()){
        edge e=q.top(); q.pop();
        if(vis[e.u][e.v])continue;
        vis[e.u][e.v]=1;
        if(--k==0){
            printf("%I64d\n",e.c);
            return 0;
        }
        for(int i=0;i<mp[e.u].size();i++){
            node x=mp[e.u][i];
            int u=x.t,v=e.v;
            if(u>v)swap(u,v);
            if(u==v)continue;
            if(q.size()<10*n)q.push({u,v,e.c+x.c});
        }
        for(int i=0;i<mp[e.v].size();i++){
            node x=mp[e.v][i];
            int u=x.t,v=e.u;
            if(u>v)swap(u,v);
            if(u==v)continue;
            if(q.size()<10*n)q.push({u,v,e.c+x.c});
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
struct edge{
    int u,v;
    long long c;
    bool operator<(const edge &tmp)const{
        return c>tmp.c;
    }
};
struct node{
    int t,c;
};
vector<node>mp[N];
priority_queue<edge>q;
map<int,map<int,bool> >vis;
int main(){
    int n,m,k,maxx=0;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<m;i++){
        int u,v,c;
        scanf("%d %d %d",&u,&v,&c);
        if(u>v)swap(u,v);
        mp[u].push_back({v,c});
        mp[v].push_back({u,c});
        q.push({u,v,c});
    }
    while(!q.empty()){
        edge e=q.top(); q.pop();
        if(vis[e.u][e.v])continue;
        vis[e.u][e.v]=1;
        if(--k==0){
            printf("%I64d\n",e.c);
            return 0;
        }
        for(int i=0;i<mp[e.u].size();i++){
            node x=mp[e.u][i];
            int u=x.t,v=e.v;
            if(u>v)swap(u,v);
            if(u==v)continue;
            if(q.size()<10*m)q.push({u,v,e.c+x.c});
        }
        for(int i=0;i<mp[e.v].size();i++){
            node x=mp[e.v][i];
            int u=x.t,v=e.u;
            if(u>v)swap(u,v);
            if(u==v)continue;
            if(q.size()<10*m)q.push({u,v,e.c+x.c});
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
struct edge{
    int u,v;
    long long c;
    bool operator<(const edge &tmp)const{
        return c>tmp.c;
    }
};
struct node{
    int t,c;
};
vector<node>mp[N];
priority_queue<edge>q;
map<int,map<int,bool> >vis;
int main(){
    int n,m,k;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<m;i++){
        int u,v,c;
        scanf("%d %d %d",&u,&v,&c);
        if(u>v)swap(u,v);
        mp[u].push_back({v,c});
        mp[v].push_back({u,c});
        q.push({u,v,c});
    }
    while(!q.empty()){
        edge e=q.top(); q.pop();
        if(vis[e.u][e.v])continue;
        vis[e.u][e.v]=1;
        if(--k==0){
            printf("%I64d\n",e.c);
            return 0;
        }
        for(int i=0;i<mp[e.u].size();i++){
            node x=mp[e.u][i];
            int u=x.t,v=e.v;
            if(u>v)swap(u,v);
            if(u==v)continue;
            q.push({u,v,e.c+x.c});
        }
        for(int i=0;i<mp[e.v].size();i++){
            node x=mp[e.v][i];
            int u=x.t,v=e.u;
            if(u>v)swap(u,v);
            if(u==v)continue;
            q.push({u,v,e.c+x.c});
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
struct edge{
    int u,v;
    long long c;
    bool operator<(const edge &tmp)const{
        return c>tmp.c;
    }
    bool operator ==(const edge &tmp)const{
        if(c==tmp.c)return 1;
        return 0;
    }
}A[404];
struct node{
    int t,c;
};
vector<node>mp[N];
priority_queue<edge>q;
map<int,map<int,int> >dis,vis;
int main(){
    int n,m,k,maxx=0;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<m;i++){
        int u,v,c;
        scanf("%d %d %d",&u,&v,&c);
        if(u>v)swap(u,v);
        mp[u].push_back({v,c});
        mp[v].push_back({u,c});
        q.push({u,v,c});
        dis[u][v]=c;
    }
    while(!q.empty()){
        edge e=q.top();
        int cnt=0;
        while(!q.empty()&&e==q.top()){
            e=q.top(); q.pop();
            A[cnt++]=e;
            if(vis[e.u][e.v])continue;
            vis[e.u][e.v]=1;
            if(--k==0){
                printf("%I64d\n",e.c);
                return 0;
            }
        }
        for(int j=0;j<cnt;j++){
            e=A[j];
            for(int i=0;i<mp[e.u].size();i++){
                node x=mp[e.u][i];
                int u=x.t,v=e.v;
                if(u>v)swap(u,v);
                if(u==v)continue;
                if(!dis[u].count(v)||e.c+x.c<dis[u][v]){
                    q.push({u,v,e.c+x.c});
                    dis[u][v]=e.c+x.c;
                }
            }
            for(int i=0;i<mp[e.v].size();i++){
                node x=mp[e.v][i];
                int u=x.t,v=e.u;
                if(u>v)swap(u,v);
                if(u==v)continue;
                if(!dis[u].count(v)||e.c+x.c<dis[u][v]){
                    q.push({u,v,e.c+x.c});
                    dis[u][v]=e.c+x.c;
                }
            }
        }
    }
}


#include<iostream>
using namespace std;

int main(void){
	unsigned long NodeNum;
	cin >> NodeNum;
	unsigned long EdgeNum;
	cin >> EdgeNum;
	unsigned long KthNum;
	cin >> KthNum;
	long long Path[801][801];
	for (int i = 0; i < 2*EdgeNum+1; ++i)
	{
		for (int j = 0; j < 2*EdgeNum+1; ++j)
		{
			Path[i][j] = 1000000000;
		}
	}

	int mcount = 1;
	unsigned long Index[NodeNum+1];
	for (int i = 0; i <= NodeNum; ++i){
		Index[i] = 0;
	}

	int weight;
	for (unsigned long i = 0; i < EdgeNum; ++i){
		unsigned long index1, index2;
		cin>>index1;
		cin>>index2;
		if(Index[index1] == 0){
			Index[index1] = mcount;
			mcount++;
		}

		if(Index[index2] == 0){
			Index[index2] = mcount;
			mcount++;
		}

		cin >> weight;

		Path[Index[index1]][Index[index2]] = weight;
		Path[Index[index2]][Index[index1]] = weight;
	}

	int Num = mcount-1;

	for (int i = 1; i <= Num; ++i)
	{
		Path[i][i] = 0;
	}

	// for(int i = 1; i <= Num; i++){
	// 	for (int j = 0; j <= Num; ++j)
	// 	{
	// 		cout<<Path[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }

	//Floyd's Algorithm
	for(unsigned long k = 1; k <= Num; ++k){
		for(unsigned long i = 1; i <= Num ; ++i){
			for(unsigned long j = 1; j <= Num ; ++j){
				if(Path[i][j] > Path[i][k] + Path[k][j])
					Path[i][j] = Path[i][k] + Path[k][j];
			}
		}
	}

	//Extracted
	unsigned long PathNum = Num*(Num-1)/2;
	unsigned long Mylist[PathNum+1];

	unsigned long count = 1;
	for (unsigned long i = 1; i <= Num; ++i)
	{
		for (unsigned long j = i+1; j <= Num; ++j)
		{
			Mylist[count] = Path[i][j];
			count++;
		}
	}
	// MaxHeap-sort: Build
	unsigned long temp;
	for (unsigned long i = (PathNum >> 1); i >= 1; --i)
	{
		unsigned long j = i;
		while(2*j <= PathNum){
			if(2*j+1 <= PathNum){
				if(Mylist[2*j] < Mylist[2*j+1] ){
					temp = Mylist[2*j+1];
					if(Mylist[j] < temp){
						Mylist[2*j+1] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j+1;
					}
					else{
						break;
					}
				}
				else{
					temp = Mylist[2*j];
					if(Mylist[j] < temp){
						Mylist[2*j] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j;
					}
					else{
						break;
					}
				}
			}
			else{
				if(Mylist[j] < Mylist[2*j]){
					temp = Mylist[j];
					Mylist[j] = Mylist[2*j];
					Mylist[2*j] = temp;

					j = 2*j;
				}
				else{
					break;
				}
			}
		}
		temp = 0;
	}

	// Max-Heap: Sort
	unsigned long *TailPtr = &Mylist[PathNum];
	unsigned long temp1;
	for (unsigned long i = 1; i <= PathNum; ++i)
	{
		temp1 = Mylist[1];
		Mylist[1] = *TailPtr;
		*TailPtr = temp1;
		TailPtr--;
		unsigned long j = 1;
		while(2*j <= PathNum - i){
			if(2*j+1 <= PathNum-i){
				if(Mylist[2*j] < Mylist[2*j+1] ){
					temp = Mylist[2*j+1];
					if(Mylist[j] < temp){
						Mylist[2*j+1] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j+1;
					}
					else{
						break;
					}
				}
				else{
					temp = Mylist[2*j];
					if(Mylist[j] < temp){
						Mylist[2*j] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j;
					}
					else{
						break;
					}
				}
			}
			else{
				if(Mylist[j] < Mylist[2*j]){
					temp = Mylist[j];
					Mylist[j] = Mylist[2*j];
					Mylist[2*j] = temp;

					j = 2*j;
				}
				else{
					break;
				}
			}
		}
	}

	cout<<Mylist[KthNum];
	return 0;
}


#include<iostream>
using namespace std;

class Node{
public:
	long long m_value;
	long long m_index1;
	long long m_index2;
	Node(long long value, long long index1, long long index2){
		m_value = value;
		m_index1 = index1;
		m_index2 = index2;
	}
	~Node(){}
};

int main(void){
	long long NodeNum;
	cin >> NodeNum;
	long long EdgeNum;
	cin >> EdgeNum;
	long long KthNum;
	cin >> KthNum;

	long long CNum;
	if(KthNum <= EdgeNum){
		CNum = KthNum;
	}
	else
	{
		CNum = EdgeNum;
	}

	Node* Memo[EdgeNum+1];
	long long index1, index2, weight;
	for (int i = 1; i <= EdgeNum; ++i){
		cin>>index1>>index2>>weight;
		Memo[i] = new Node(weight,index1,index2);
	}

	//MinHeap:Build
	Node* temp01;
	for (int i = (EdgeNum >> 1); i >= 1; --i)
	{
		long long j = i;
		while(2*j <= EdgeNum){
			if(2*j+1 <= EdgeNum){
				if(Memo[2*j]->m_value < Memo[2*j+1]->m_value){
					temp01 = Memo[2*j];
					if(Memo[2*j]->m_value < Memo[j]->m_value){
						Memo[2*j] = Memo[j];
						Memo[j] = temp01;
						j = 2*j;
					}
					else
					{
						break;
					}
				}
				else{
					temp01 = Memo[2*j+1];
					if(Memo[2*j+1]->m_value < Memo[j]->m_value){
						Memo[2*j+1] = Memo[j];
						Memo[j] = temp01;
						j = 2*j + 1;
					}
					else{
						break;
					}
				}
			}
			else
			{
				temp01 = Memo[2*j];
				if(Memo[2*j]->m_value < Memo[j]->m_value){
					Memo[2*j] = Memo[j];
					Memo[j] = temp01;
					j = 2*j;
				}
				else
				{
					break;
				}
			}
		}
	}
	//MinHeap:Sort
	Node* Memo1[CNum+1];
	int j = 0;
	for (int i = 1; i <= CNum; ++i){
		Memo1[i] = Memo[1];
		Memo[1] = nullptr;
		j = 1;
		while(2*j <= EdgeNum){
			if (Memo[2*j] == nullptr && Memo[2*j+1] == nullptr)
				break;
			if(Memo[2*j+1] == nullptr){
				Memo[j] = Memo[2*j];
				Memo[2*j] = nullptr;
				j = 2*j;
			}
			else if(Memo[2*j] == nullptr){
				Memo[j] = Memo[2*j+1];
				Memo[2*j+1] = nullptr;
				j = 2*j +1;
			}
			else{
				if(Memo[2*j] -> m_value < Memo[2*j+1] -> m_value){
					Memo[j] = Memo[2*j];
					Memo[2*j] = nullptr;
					j = 2*j;
				}
				else{
					Memo[j] = Memo[2*j+1];
					Memo[2*j+1] = nullptr;
					j = 2*j+1;
				}
			}
		}
	}

	// for (int i = 1; i <= CNum; ++i)
	// {
	// 	cout<<Memo1[i] -> m_value<<" ";
	// }

	//Extract valid nodes
	int Index[NodeNum+1];
	int mcount = 1;
	for(int i = 0; i <= NodeNum; ++i)
		Index[i] = 0;

	for (int i = 1; i <= CNum; ++i)
	{
		if(Index[Memo1[i]->m_index1] == 0){
			Index[Memo1[i]->m_index1] = mcount;
			mcount++;
		}

		if(Index[Memo1[i] -> m_index2] == 0){
			Index[Memo1[i] -> m_index2] = mcount;
			mcount++;
		}
	}
	int Num = mcount-1;//The number of valid nodes.
	long long Path[Num+1][Num+1];
	for (int i = 1; i <= Num; ++i)
	{
		for (int j = 1; j <= Num; ++j)
		{
			Path[i][j] = 2000000001;
		}
	}
	for (int i = 1; i <= CNum; ++i)
	{
		Path[Index[Memo1[i]->m_index1]][Index[Memo1[i]->m_index2]] = Memo1[i] -> m_value;
		//cout<<"Index1: "<<Index[Memo1[i]->m_index1]<<" Index2: "<<Index[Memo1[i]->m_index2]<<" Value: "<<Memo1[i]->m_value<<endl;
		Path[Index[Memo1[i]->m_index2]][Index[Memo1[i]->m_index1]] = Memo1[i] -> m_value;
	}
	for (int i = 1; i <= Num; ++i)
	{
		Path[i][i] = 0;
	}

	// cout<<endl;
	// for (int i = 1; i <= Num; ++i)
	// {
	// 	for (int j = 1; j <= Num; ++j)
	// 	{
	// 		cout<<Path[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }

	// for(int i = 1; i <= Num; i++){
	// 	for (int j = 0; j <= Num; ++j)
	// 	{
	// 		cout<<Path[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	//Floyd's Algorithm
	for( int k = 1; k <= Num; ++k){
		for(int i = 1; i <= Num ; ++i){
			for(int j = 1; j <= Num ; ++j){
				if(Path[i][j] > Path[i][k] + Path[k][j])
					Path[i][j] = Path[i][k] + Path[k][j];
			}
		}
	}

	//Extracted
	long long PathNum = Num*(Num-1)/2;
	long long Mylist[PathNum+1];

	long long count = 1;
	for (long long i = 1; i <= Num; ++i)
	{
		for (long long j = i+1; j <= Num; ++j)
		{
			Mylist[count] = Path[i][j];
			count++;
		}
	}
	// MaxHeap-sort: Build
	long long temp;
	for (long long i = (PathNum >> 1); i >= 1; --i)
	{
		long long j = i;
		while(2*j <= PathNum){
			if(2*j+1 <= PathNum){
				if(Mylist[2*j] < Mylist[2*j+1] ){
					temp = Mylist[2*j+1];
					if(Mylist[j] < temp){
						Mylist[2*j+1] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j+1;
					}
					else{
						break;
					}
				}
				else{
					temp = Mylist[2*j];
					if(Mylist[j] < temp){
						Mylist[2*j] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j;
					}
					else{
						break;
					}
				}
			}
			else{
				if(Mylist[j] < Mylist[2*j]){
					temp = Mylist[j];
					Mylist[j] = Mylist[2*j];
					Mylist[2*j] = temp;

					j = 2*j;
				}
				else{
					break;
				}
			}
		}
		temp = 0;
	}

	// Max-Heap: Sort
	long long *TailPtr = &Mylist[PathNum];
	long long temp1;
	for (long long i = 1; i <= PathNum; ++i)
	{
		temp1 = Mylist[1];
		Mylist[1] = *TailPtr;
		*TailPtr = temp1;
		TailPtr--;
		long long j = 1;
		while(2*j <= PathNum - i){
			if(2*j+1 <= PathNum-i){
				if(Mylist[2*j] < Mylist[2*j+1] ){
					temp = Mylist[2*j+1];
					if(Mylist[j] < temp){
						Mylist[2*j+1] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j+1;
					}
					else{
						break;
					}
				}
				else{
					temp = Mylist[2*j];
					if(Mylist[j] < temp){
						Mylist[2*j] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j;
					}
					else{
						break;
					}
				}
			}
			else{
				if(Mylist[j] < Mylist[2*j]){
					temp = Mylist[j];
					Mylist[j] = Mylist[2*j];
					Mylist[2*j] = temp;

					j = 2*j;
				}
				else{
					break;
				}
			}
		}
	}

// cout<<endl;
// 	for (int i = 1; i <= PathNum; ++i)
// 	{
// 		cout<<Mylist[i]<<" ";
// 	}
//	cout<<endl;
	cout<<Mylist[KthNum];
	return 0;
}


#include<iostream>
using namespace std;

class Node{
public:
	long m_value;
	long m_index1;
	long m_index2;
	Node(long value, long index1, long index2){
		m_value = value;
		m_index1 = index1;
		m_index2 = index2;
	}
	~Node(){}
};

int main(void){
	long NodeNum;
	cin >> NodeNum;
	long EdgeNum;
	cin >> EdgeNum;
	long KthNum;
	cin >> KthNum;
	long Path[2*KthNum+5][2*KthNum+5];
	for (int i = 1; i <= 2*KthNum+1; ++i)
	{
		for (int j = 1; j <= 2*KthNum+1; ++j)
		{
			Path[i][j] = 10000;
		}
	}

	long Index[NodeNum+1];
	for(int i = 0; i <= NodeNum; ++i)
		Index[i] = 0;

	Node* Memo[EdgeNum+1];
	long mcount = 1;
	long index1, index2, weight;
	for (int i = 1; i <= EdgeNum; ++i){
		cin>>index1>>index2>>weight;
		if(Index[index1] == 0){
			Index[index1] = mcount;
			mcount++;
		}

		if(Index[index2] == 0){
			Index[index2] = mcount;
			mcount++;
		}
		Memo[i] = new Node(weight,Index[index1],Index[index2]);
	}

	//MinHeap:Build
	Node* temp01;
	for (int i = (EdgeNum >> 1); i >= 1; --i)
	{
		long j = i;
		while(2*j <= EdgeNum){
			if(2*j+1 <= EdgeNum){
				if(Memo[2*j]->m_value < Memo[2*j+1]->m_value){
					temp01 = Memo[2*j];
					if(Memo[2*j]->m_value < Memo[j]->m_value){
						Memo[2*j] = Memo[j];
						Memo[j] = temp01;
						j = 2*j;
					}
					else
					{
						break;
					}
				}
				else{
					temp01 = Memo[2*j+1];
					if(Memo[2*j+1]->m_value < Memo[j]->m_value){
						Memo[2*j+1] = Memo[j];
						Memo[j] = temp01;
						j = 2*j + 1;
					}
					else{
						break;
					}
				}
			}
			else
			{
				temp01 = Memo[2*j];
				if(Memo[2*j]->m_value < Memo[j]->m_value){
					Memo[2*j] = Memo[j];
					Memo[j] = temp01;
					j = 2*j;
				}
				else
				{
					break;
				}
			}
		}
	}

	Node* Nodeptr;
	Node** Nodetail = &Memo[EdgeNum];
	Node* Memo1[KthNum+1];
	for (int i = 1; i <= KthNum; ++i)
	{
		long j = 1;
		Memo1[i] = Memo[1];
		Memo[1] = *Nodetail;
		*Nodetail = nullptr;
		Nodetail--;
		while(2*j <= EdgeNum - i){
			if(2*j+1 <= EdgeNum - i){
				if(Memo[2*j]->m_value < Memo[2*j+1]->m_value){
					temp01 = Memo[2*j];
					if(Memo[2*j]->m_value < Memo[j]->m_value){
						Memo[2*j] = Memo[j];
						Memo[j] = temp01;
						j = 2*j;
					}
					else{
						break;
					}
				}
				else{
					temp01 = Memo[2*j+1];
					if(Memo[2*j+1]->m_value < Memo[j]->m_value){
						Memo[2*j+1] = Memo[j];
						Memo[j] = temp01;
						j = 2*j + 1;
					}
					else{
						break;
					}
				}
			}
			else{
				temp01 = Memo[2*j];
				if(Memo[2*j]->m_value < Memo[j]->m_value){
					Memo[2*j] = Memo[j];
					Memo[j] = temp01;
					j = 2*j;
				}
				else{
					break;
				}
			}
		}
	}

	for (long i = 1; i <= KthNum; ++i){
		Path[Memo1[i]->m_index1][Memo1[i]->m_index2] = Memo1[i]->m_value;
		Path[Memo1[i]->m_index2][Memo1[i]->m_index1] = Memo1[i]->m_value;
	}

	int Num = mcount-1;

	for (int i = 1; i <= Num; ++i)
	{
		Path[i][i] = 0;
	}

	// for(int i = 1; i <= Num; i++){
	// 	for (int j = 0; j <= Num; ++j)
	// 	{
	// 		cout<<Path[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }

	//Floyd's Algorithm
	for( int k = 1; k <= Num; ++k){
		for(int i = 1; i <= Num ; ++i){
			for(int j = 1; j <= Num ; ++j){
				if(Path[i][j] > Path[i][k] + Path[k][j])
					Path[i][j] = Path[i][k] + Path[k][j];
			}
		}
	}

	//Extracted
	long PathNum = Num*(Num-1)/2;
	long Mylist[PathNum+1];

	long count = 1;
	for (long i = 1; i <= Num; ++i)
	{
		for (long j = i+1; j <= Num; ++j)
		{
			Mylist[count] = Path[i][j];
			count++;
		}
	}
	// MaxHeap-sort: Build
	long temp;
	for (long i = (PathNum >> 1); i >= 1; --i)
	{
		long j = i;
		while(2*j <= PathNum){
			if(2*j+1 <= PathNum){
				if(Mylist[2*j] < Mylist[2*j+1] ){
					temp = Mylist[2*j+1];
					if(Mylist[j] < temp){
						Mylist[2*j+1] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j+1;
					}
					else{
						break;
					}
				}
				else{
					temp = Mylist[2*j];
					if(Mylist[j] < temp){
						Mylist[2*j] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j;
					}
					else{
						break;
					}
				}
			}
			else{
				if(Mylist[j] < Mylist[2*j]){
					temp = Mylist[j];
					Mylist[j] = Mylist[2*j];
					Mylist[2*j] = temp;

					j = 2*j;
				}
				else{
					break;
				}
			}
		}
		temp = 0;
	}

	// Max-Heap: Sort
	long *TailPtr = &Mylist[PathNum];
	long temp1;
	for (long i = 1; i <= PathNum; ++i)
	{
		temp1 = Mylist[1];
		Mylist[1] = *TailPtr;
		*TailPtr = temp1;
		TailPtr--;
		long j = 1;
		while(2*j <= PathNum - i){
			if(2*j+1 <= PathNum-i){
				if(Mylist[2*j] < Mylist[2*j+1] ){
					temp = Mylist[2*j+1];
					if(Mylist[j] < temp){
						Mylist[2*j+1] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j+1;
					}
					else{
						break;
					}
				}
				else{
					temp = Mylist[2*j];
					if(Mylist[j] < temp){
						Mylist[2*j] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j;
					}
					else{
						break;
					}
				}
			}
			else{
				if(Mylist[j] < Mylist[2*j]){
					temp = Mylist[j];
					Mylist[j] = Mylist[2*j];
					Mylist[2*j] = temp;

					j = 2*j;
				}
				else{
					break;
				}
			}
		}
	}

	cout<<Mylist[KthNum];
	return 0;
}


#include<iostream>
using namespace std;

class Node{
public:
	long m_value;
	long m_index1;
	long m_index2;
	Node(long value, long index1, long index2){
		m_value = value;
		m_index1 = index1;
		m_index2 = index2;
	}
	~Node(){}
};

int main(void){
	long NodeNum;
	cin >> NodeNum;
	long EdgeNum;
	cin >> EdgeNum;
	long KthNum;
	cin >> KthNum;
	long CNum;

	if(KthNum <= EdgeNum){
		CNum = KthNum;
	}
	else
	{
		CNum = EdgeNum;
	}

	Node* Memo[EdgeNum+1];
	long index1, index2, weight;
	for (int i = 1; i <= EdgeNum; ++i){
		cin>>index1>>index2>>weight;
		Memo[i] = new Node(weight,index1,index2);
	}

	//MinHeap:Build
	Node* temp01;
	for (int i = (EdgeNum >> 1); i >= 1; --i)
	{
		long j = i;
		while(2*j <= EdgeNum){
			if(2*j+1 <= EdgeNum){
				if(Memo[2*j]->m_value < Memo[2*j+1]->m_value){
					temp01 = Memo[2*j];
					if(Memo[2*j]->m_value < Memo[j]->m_value){
						Memo[2*j] = Memo[j];
						Memo[j] = temp01;
						j = 2*j;
					}
					else
					{
						break;
					}
				}
				else{
					temp01 = Memo[2*j+1];
					if(Memo[2*j+1]->m_value < Memo[j]->m_value){
						Memo[2*j+1] = Memo[j];
						Memo[j] = temp01;
						j = 2*j + 1;
					}
					else{
						break;
					}
				}
			}
			else
			{
				temp01 = Memo[2*j];
				if(Memo[2*j]->m_value < Memo[j]->m_value){
					Memo[2*j] = Memo[j];
					Memo[j] = temp01;
					j = 2*j;
				}
				else
				{
					break;
				}
			}
		}
	}
	//MinHeap:Sort
	Node* Nodeptr;
	Node** Nodetail = &Memo[EdgeNum];
	Node* Memo1[CNum+1];
	for (int i = 1; i <= CNum; ++i){
		long j = 1;
		Memo1[i] = Memo[1];
		Memo[1] = *Nodetail;
		*Nodetail = nullptr;
		Nodetail--;
		while(2*j <= EdgeNum - i){
			if(2*j+1 <= EdgeNum - i){
				if(Memo[2*j]->m_value < Memo[2*j+1]->m_value){
					temp01 = Memo[2*j];
					if(Memo[2*j]->m_value < Memo[j]->m_value){
						Memo[2*j] = Memo[j];
						Memo[j] = temp01;
						j = 2*j;
					}
					else{
						break;
					}
				}
				else{
					temp01 = Memo[2*j+1];
					if(Memo[2*j+1]->m_value < Memo[j]->m_value){
						Memo[2*j+1] = Memo[j];
						Memo[j] = temp01;
						j = 2*j + 1;
					}
					else{
						break;
					}
				}
			}
			else{
				temp01 = Memo[2*j];
				if(Memo[2*j]->m_value < Memo[j]->m_value){
					Memo[2*j] = Memo[j];
					Memo[j] = temp01;
					j = 2*j;
				}
				else{
					break;
				}
			}
		}
	}

	// for (int i = 1; i <= CNum; ++i)
	// {
	// 	cout<<Memo1[i] -> m_value<<" ";
	// }

	//Extract valid nodes
	int Index[NodeNum+1];
	int mcount = 0;
	for(int i = 0; i <= NodeNum; ++i)
		Index[i] = 0;

	for (int i = 1; i <= CNum; ++i)
	{
		if(Index[Memo1[i]->m_index1] == 0){
			Index[Memo1[i]->m_index1] = mcount;
			mcount++;
		}

		if(Index[Memo1[i] -> m_index2] == 0){
			Index[Memo1[i] -> m_index2] = mcount;
			mcount++;
		}
	}
	int Num = mcount-1;//The number of valid nodes.
	long Path[Num+1][Num+1];
	for (int i = 1; i <= Num; ++i)
	{
		for (int j = 1; j <= Num; ++j)
		{
			Path[i][j] = 10000;
		}
	}
	for (int i = 1; i <= CNum; ++i)
	{
		Path[Index[Memo1[i]->m_index1]][Index[Memo1[i]->m_index2]] = Memo1[i] -> m_value;
		//cout<<"Index1: "<<Index[Memo1[i]->m_index1]<<" Index2: "<<Index[Memo1[i]->m_index2]<<" Value: "<<Memo1[i]->m_value<<endl;
		Path[Index[Memo1[i]->m_index2]][Index[Memo1[i]->m_index1]] = Memo1[i] -> m_value;
	}
	for (int i = 1; i <= Num; ++i)
	{
		Path[i][i] = 0;
	}

	// cout<<endl;
	// for (int i = 1; i <= Num; ++i)
	// {
	// 	for (int j = 1; j <= Num; ++j)
	// 	{
	// 		cout<<Path[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }

	// for(int i = 1; i <= Num; i++){
	// 	for (int j = 0; j <= Num; ++j)
	// 	{
	// 		cout<<Path[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	//Floyd's Algorithm
	for( int k = 1; k <= Num; ++k){
		for(int i = 1; i <= Num ; ++i){
			for(int j = 1; j <= Num ; ++j){
				if(Path[i][j] > Path[i][k] + Path[k][j])
					Path[i][j] = Path[i][k] + Path[k][j];
			}
		}
	}

	//Extracted
	long PathNum = Num*(Num-1)/2;
	long Mylist[PathNum+1];

	long count = 1;
	for (long i = 1; i <= Num; ++i)
	{
		for (long j = i+1; j <= Num; ++j)
		{
			Mylist[count] = Path[i][j];
			count++;
		}
	}
	// MaxHeap-sort: Build
	long temp;
	for (long i = (PathNum >> 1); i >= 1; --i)
	{
		long j = i;
		while(2*j <= PathNum){
			if(2*j+1 <= PathNum){
				if(Mylist[2*j] < Mylist[2*j+1] ){
					temp = Mylist[2*j+1];
					if(Mylist[j] < temp){
						Mylist[2*j+1] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j+1;
					}
					else{
						break;
					}
				}
				else{
					temp = Mylist[2*j];
					if(Mylist[j] < temp){
						Mylist[2*j] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j;
					}
					else{
						break;
					}
				}
			}
			else{
				if(Mylist[j] < Mylist[2*j]){
					temp = Mylist[j];
					Mylist[j] = Mylist[2*j];
					Mylist[2*j] = temp;

					j = 2*j;
				}
				else{
					break;
				}
			}
		}
		temp = 0;
	}

	// Max-Heap: Sort
	long *TailPtr = &Mylist[PathNum];
	long temp1;
	for (long i = 1; i <= PathNum; ++i)
	{
		temp1 = Mylist[1];
		Mylist[1] = *TailPtr;
		*TailPtr = temp1;
		TailPtr--;
		long j = 1;
		while(2*j <= PathNum - i){
			if(2*j+1 <= PathNum-i){
				if(Mylist[2*j] < Mylist[2*j+1] ){
					temp = Mylist[2*j+1];
					if(Mylist[j] < temp){
						Mylist[2*j+1] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j+1;
					}
					else{
						break;
					}
				}
				else{
					temp = Mylist[2*j];
					if(Mylist[j] < temp){
						Mylist[2*j] = Mylist[j];
						Mylist[j] = temp;
						j = 2*j;
					}
					else{
						break;
					}
				}
			}
			else{
				if(Mylist[j] < Mylist[2*j]){
					temp = Mylist[j];
					Mylist[j] = Mylist[2*j];
					Mylist[2*j] = temp;

					j = 2*j;
				}
				else{
					break;
				}
			}
		}
	}

// cout<<endl;
// 	for (int i = 1; i <= PathNum; ++i)
// 	{
// 		cout<<Mylist[i]<<" ";
// 	}
//	cout<<endl;
	cout<<Mylist[KthNum];
	return 0;
}