Problem: You are given a set of circles C of a variety of radii (radiuses) placed at a variety of positions, possibly overlapping one another. Given a circle with radius r, that circle may be placed so that it encircles all of the circles in the set C if r is large enough.

There may be more than one possible position of the circle of radius r to encircle all the member circles of C. We define the region U as the union of the areas of encircling circles at all such positions. In other words, for each point in U, there exists a circle of radius r that encircles that point and all the members of C. Your task is to calculate the length of the periphery of that region U.

Figure I.1 shows an example of the set of circles C and the region U. In the figure, three circles contained in C are expressed by circles of solid circumference, some possible positions of the encircling circles are expressed by circles of dashed circumference, and the area U is expressed by a thick dashed closed curve.

<image>



Input

The input is a sequence of datasets. The number of datasets is less than 100.

Each dataset is formatted as follows.

n r
x1 y1 r1
x2 y2 r2
.
.
.
xn yn rn

The first line of a dataset contains two positive integers, n and r, separated by a single space. n means the number of the circles in the set C and does not exceed 100. r means the radius of the encircling circle and does not exceed 1000.

Each of the n lines following the first line contains three integers separated by a single space. (xi, yi) means the center position of the i-th circle of the set C and ri means its radius.

You may assume −500≤xi ≤500, −500≤yi ≤500, and 1≤ri ≤500.

The end of the input is indicated by a line containing two zeros separated by a single space.

Output

For each dataset, output a line containing a decimal fraction which means the length of the periphery (circumferential length) of the region U.

The output should not contain an error greater than 0.01. You can assume that, when r changes by ε (|ε| < 0.0000001), the length of the periphery of the region U will not change more than 0.001.

If r is too small to cover all of the circles in C, output a line containing only 0.0.

No other characters should be contained in the output.

Example

Input

1 10
5 5 7
2 12
5 5 7
8 6 3
3 10
3 11 2
2 1 1
2 16 3
3 15
-5 2 5
9 2 9
5 8 6
3 38
-25 -10 8
30 5 7
-3 35 11
3 39
-25 -10 8
30 5 7
-3 35 11
3 800
-400 400 2
300 300 1
300 302 1
3 800
400 -400 2
300 300 1
307 300 3
8 147
130 80 12
130 -40 12
-110 80 12
-110 -40 12
70 140 12
70 -100 12
-50 140 12
-50 -100 12
3 493
345 154 10
291 111 75
-275 -301 46
4 55
54 0 1
40 30 5
27 36 10
0 48 7
3 30
0 3 3
-3 0 4
400 0 3
3 7
2 3 2
-5 -4 2
-4 3 2
3 10
-5 -4 5
2 3 5
-4 3 5
4 6
4 6 1
5 5 1
1 7 1
0 1 1
3 493
345 154 10
291 111 75
-275 -301 46
5 20
-9 12 5
0 15 5
3 -3 3
12 9 5
-12 9 5
0 0


Output

81.68140899333463
106.81415022205297
74.11215318612639
108.92086846105579
0.0
254.85616536128433
8576.936716409238
8569.462129048667
929.1977057481128
4181.124698202453
505.09134735536804
0.0
46.82023824234038
65.66979416387915
50.990642291793506
4181.124698202453
158.87951420768937

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-8;
const double pi=acos(-1);
const int maxn=111;
int sgn(double x){return (x>eps)-(x<-eps);}
int sgn(double a,double b){return sgn(a-b);}
double sqr(double x){return x*x;}
struct P{
	double x,y;
	P(){}
	P(double x,double y):x(x),y(y){}
	double len2(){
		return sqr(x)+sqr(y);
	}
	double len(){
		return sqrt(len2());
	}
	void print(){
		printf("(%.3f,%.3f)\n",x,y);
	}
	void read(){
		scanf("%lf%lf",&x,&y);
	}
	P turn90(){return P(-y,x);}
	P norm(){return P(x/len(),y/len());}
	P rot(double rad){
		return P(x*cos(rad)+y*sin(rad),x*sin(rad)-y*cos(rad));
	}
};
bool operator==(P a,P b){
	return !sgn(a.x-b.x) and !sgn(a.y-b.y);
}
P operator+(P a,P b){
	return P(a.x+b.x,a.y+b.y);
}
P operator-(P a,P b){
	return P(a.x-b.x,a.y-b.y);
}
P operator*(P a,double b){
	return P(a.x*b,a.y*b);
}
P operator/(P a,double b){
	return P(a.x/b,a.y/b);
}
double operator^(P a,P b){
	return a.x*b.x + a.y*b.y;
}
double operator*(P a,P b){
	return a.x*b.y - a.y*b.x;
}
double det(P a,P b,P c){
	return (b-a)*(c-a);
}
double dis(P a,P b){
	return (b-a).len();
}
double Area(vector<P>poly){
	double ans=0;
	for(int i=1;i<poly.size();i++)
		ans+=(poly[i]-poly[0])*(poly[(i+1)%poly.size()]-poly[0]);
	return fabs(ans)/2;
}
struct L{
	P a,b;
	L(){}
	L(P a,P b):a(a),b(b){}
	P v(){return b-a;}
};
bool onLine(P p,L l){
	return sgn((l.a-p)*(l.b-p))==0;
}
bool onSeg(P p,L s){
	return onLine(p,s) and sgn((s.b-s.a)^(p-s.a))>=0 and sgn((s.a-s.b)^(p-s.b))>=0;
}
bool parallel(L l1,L l2){
	return sgn(l1.v()*l2.v())==0;
}
P intersect(L l1,L l2){
	double s1=det(l1.a,l1.b,l2.a);
	double s2=det(l1.a,l1.b,l2.b);
	return (l2.a*s2-l2.b*s1)/(s2-s1);
}
P project(P p,L l){
	return l.a+l.v()*((p-l.a)^l.v())/l.v().len2();
}
double dis(P p,L l){
	return fabs((p-l.a)*l.v())/l.v().len();
}
struct C{
	P o;
	double r;
	C(){}
	C(P _o,double _r):o(_o),r(_r){}
	void read(){
		o.read();
		scanf("%lf",&r);
	}
}c[maxn];
bool operator<(C a,C b){
	return a.r>b.r;
}
bool operator==(C c1,C c2){
	return c1.o==c2.o && sgn(c1.r-c2.r)==0;
}
double fix(double x){return sgn(x)?x:0;}
bool intersect(C a, C b, P &p1, P &p2) { 
	double s1 = (a.o - b.o).len();
	if (sgn(s1 - a.r - b.r) > 0 || sgn(s1 - fabs(a.r - b.r)) < 0) return false;
	double s2 = (a.r * a.r - b.r * b.r) / s1;
	double aa = (s1 + s2) * 0.5, bb = (s1 - s2) * 0.5;
	P o = (b.o - a.o) * (aa / (aa + bb)) + a.o;
	P delta = (b.o - a.o).norm().turn90() * sqrt(fix(a.r * a.r - aa * aa));
	p1 = o + delta, p2 = o - delta;
	return true;
}
int n;
double r;

double calcR(P O){
	double mxr=0;
	for(int i=1;i<=n;i++){
		double ri=0;
		ri=dis(c[i].o,O)+c[i].r;
		mxr=max(mxr,ri);
	}
	return mxr;
}

bool check(P O){
	double mxr=0;
	for(int i=1;i<=n;i++){
		double ri=0;
		ri=dis(c[i].o,O)+c[i].r;
		if(sgn(ri-r)>0)
			return false;
	}
	return true;
}
P O;
vector<P>vecO;
bool in(P p){

	if(sgn(dis(p,O)-r)<=0)
		return true;

	for(int i=1;i<=n;i++){
		C c1=c[i],c2;
		c2.o=p;
		c1.r=r-c1.r;
		c2.r=r;
		P p1,p2;
		if(c1==c2||!intersect(c1,c2,p1,p2))
			continue;
		if(check(p1)||check(p2))
			return true;
	}

	return false;
}
P at(P O,P dir){
	dir=dir.norm();
	double l=::r,r=20000;
	while(r-l>1e-9){
		double mid=(l+r)/2;
		if(in(O+dir*mid))
			l=mid;
		else r=mid;
	}
	return O+dir*l;
}
double calc(P a,P b,P c){
	
	L l1,l2;
	l1.a=(a+b)/2;
	l1.b=l1.a+(b-a).turn90();
	
	l2.a=(b+c)/2;
	l2.b=l2.a+(b-c).turn90();
	
	
	
	
	if(parallel(l1,l2))
		return dis(a,c);
	
	P O=intersect(l1,l2);
	double r=dis(O,a);
	
	
	double theta;
	theta = acos(((c-O)^(a-O))/r/r);
	
	return r*theta;	
}
double calc(double l,double r){
	
	double p=0.45;

	double m=l+(r-l)*p;
	
	P pl=at(O,P(1,0).rot(l));
	P pm=at(O,P(1,0).rot(m));
	P pr=at(O,P(1,0).rot(r));
	
	return calc(pl,pm,pr);
	
}
double simpl(double l,double r){
	double mid=(l+r)/2;
	
	
	double Sl=calc(l,mid);
	double Sr=calc(mid,r);
	double S=calc(l,r);
	
	if(sgn(S-Sl-Sr)==0)
		return S;
	return simpl(l,mid)+simpl(mid,r);
}

int main(){
	while(scanf("%d%lf",&n,&r)&&n){
		vecO.clear();
		for(int i=1;i<=n;i++){
			c[i].read();
		}
		
		sort(c+1,c+1+n);
		
		int m=0;
		static C nC[maxn];
		nC[++m]=c[1];
		for(int i=2;i<=n;i++){
			int flag=0;
			for(int j=1;j<=m;j++){
				double d=dis(c[i].o,nC[j].o);
				if(sgn(d-(nC[j].r-c[i].r))<=0){
					flag=1;
					break;
				}
			}
			if(!flag){
				nC[++m]=c[i];
			}
		}
		n=m;
		for(int i=1;i<=n;i++)
			c[i]=nC[i];
			
		if(n==1){
		
			if(sgn(c[1].r-r)<=0){
				printf("%.8f\n",2*pi*(r*2-c[1].r));
			}else{
				puts("0.0");
			}
			continue;
		}
		
		int flag=0;
		for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++){
			C c1=c[i],c2=c[j];
			double d=dis(c[i].o,c[j].o);
			c1.r=r-c1.r;
			c2.r=r-c2.r;
			P p1,p2;
			if(c1==c2||!intersect(c1,c2,p1,p2))
				continue;
			
			if(sgn(calcR(p1)-r)<=0){
				vecO.push_back(p1);
			}
			if(sgn(calcR(p2)-r)<=0){
				vecO.push_back(p2);
			}
		}
		
		if(vecO.empty()){
			puts("0.0");
			continue;
		}
		//cerr<<n<<endl;
		O=vecO.front();
		
		double ans=0;
		ans+=simpl(0,pi);
		ans+=simpl(pi,pi*2);
		printf("%.8f\n",ans);
		
	}
	return 0;
}