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<cstdio>
#include<cmath>
#include<complex>
#include<vector>
#include<algorithm>

using namespace std;

const double eps=1e-9;
const double PI=3.14159265358979323846264;

typedef complex<double> Point;
typedef complex<double> Vector;

template<class T> bool eq(T a,T b){
	return abs(a-b)<eps;
}

double normalize(double ang){
	while(ang<0) ang+=PI*2;
	while(ang>PI*2) ang-=PI*2;
	return ang;
}

struct Circle{
	Point center;
	double r;
	vector<double> angles;//intersections
	Circle(){}
	Circle(Point p,double r):center(p),r(r){}
	bool isin(Point p){
		double dis=abs(p-center);
		return r>dis||eq(r,dis);
	}
	bool isin(Circle c){
		double d=abs(c.center-center)+c.r;
		return r>d;
	}
	Point getPoint(double theta){
		return center+(Point(cos(theta),sin(theta))*r);
	}
	Point onePoint(Circle c){
		double dis=abs(c.center-center);
		if(!eq(dis,r+c.r)){
			return Point(NAN,NAN);
		}
		Vector vec=c.center-center;
		return center+vec*(r/(r+c.r));
	}
	void add(Circle c){
		double r2=c.r;
		double d=abs(c.center-center);
		if(r+r2<d) return;
		double theta=acos((r*r+d*d-r2*r2)/(2.0*r*d));
		Vector vec=c.center-center;
		double phi=atan2(vec.imag(),vec.real());
		angles.push_back(normalize(phi+theta));
		angles.push_back(normalize(phi-theta));
	}
	bool haveCommon(Circle c){
		double d=abs(center-c.center);
		return d<r+c.r||eq(d,r+c.r);
	}
};

vector<Circle> C;
vector<Circle> centerArea;
vector<Circle> circles;
int N,R;

void solve(){
	for(int i=0;i<N;i++){
		if(C[i].r>R){
			printf("0.0\n");
			return;
		}
	}
	for(int i=0;i<N;i++){
		if(C[i].r==R){
			bool flg=true;
			for(int j=0;j<N;j++){
				if(i==j) continue;
				if(C[i].isin(C[j])==false) flg=false;
			}
			if(flg){
				printf("%.f\n",PI*2*R);
			}else{
				printf("0.0\n");
			}
			return;
		}
	}
	for(int i=0;i<N;i++){
		centerArea.push_back(Circle(C[i].center,R-C[i].r));
	}
	for(int i=0;i<N;i++){
		bool flg=true;
		for(int j=0;j<N;j++){
			if(i==j) continue;
			if(centerArea[i].isin(centerArea[j])){
				flg=false;
				break;
			}
		}
		if(flg) circles.push_back(centerArea[i]);
	}
	if(circles.size()==1){
		printf("%f\n",PI*2*(circles[0].r+R));
		return;
	}
	int M=circles.size();
	for(int i=0;i<M;i++) for(int j=i+1;j<M;j++){
		Point pt=circles[i].onePoint(circles[j]);
		if(isnan(pt.real())) continue;
		bool flg=true;
		for(int k=0;k<M;k++){
			if(i==k||j==k) continue;
			if(circles[k].isin(pt)==false) flg=false;
		}
		if(flg){
			printf("%f\n",PI*2*R);
		}else{
			printf("0.0\n");
		}
		return;
	}
	for(int i=0;i<M;i++) for(int j=0;j<M;j++){
		if(circles[i].haveCommon(circles[j])==false){
			printf("0.0\n");
			return;
		}
	}
	for(int i=0;i<M;i++) for(int j=0;j<M;j++){
		if(i==j) continue;
		circles[i].add(circles[j]);
	}
	double totalAng=0;
	double ans=0;
	for(int i=0;i<M;i++){
		Circle cur=circles[i];
		sort(cur.angles.begin(),cur.angles.end());
		for(int j=0;j<cur.angles.size();j++){
			double a=cur.angles[j];
			double b;
			if(j+1==cur.angles.size()){
				b=cur.angles[0]+PI*2;
			}else{
				b=cur.angles[j+1];
			}
			double mid=(a+b)/2;
			Point pt=cur.getPoint(mid);
			bool flg=true;
			for(int k=0;k<M;k++){
				if(circles[k].isin(pt)==false) flg=false;
			}
			if(flg){
				double curAng=b-a;
				ans+=(curAng*(R+cur.r));
				totalAng+=curAng;
			}
		}
	}
	if(totalAng==0){
		printf("0.0\n");
	}else{
		ans+=(PI*2-totalAng)*R;
		printf("%f\n",ans);
	}
}

void init(){
	C.clear();
	centerArea.clear();
	circles.clear();
}

int main(){
	while(true){
		scanf("%d%d",&N,&R);
		if(N==0&&R==0) break;
		init();
		for(int i=0;i<N;i++){
			int x,y,r;
			scanf("%d%d%d",&x,&y,&r);
			C.push_back(Circle(Point(x,y),r));
		}
		solve();
	}
	return 0;
}