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<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1);
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
inline double ABS(double a){return max(a,-a);}
struct Pt {
	double x, y;
	Pt() {}
	Pt(double x, double y) : x(x), y(y) {}
	Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
	Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
	Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
	Pt operator-() const { return Pt(-x, -y); }
	Pt operator*(const double &k) const { return Pt(x * k, y * k); }
	Pt operator/(const double &k) const { return Pt(x / k, y / k); }
	double ABS() const { return sqrt(x * x + y * y); }
	double abs2() const { return x * x + y * y; }
	double arg() const { return atan2(y, x); }
	double dot(const Pt &a) const { return x * a.x + y * a.y; }
	double det(const Pt &a) const { return x * a.y - y * a.x; }
};
double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }
pair<Pt,Pt> pCC(Pt a, double r, Pt b, double s) {
	double d = (b - a).ABS();
	double x = (d * d + r * r - s * s) / (d * 2);
	Pt e = (b - a) / d, w = e * Pt(0, 1) * sqrt(max(r * r - x * x, 0.0));
	return make_pair(a + e * x - w, a + e * x + w);
}
int iCC(Pt a, double r, Pt b, double s) {
	double d = (b - a).ABS();
	if (sig(d) == 0 && sig(r - s) == 0) return -1; // correspond
	if (sig(r - s - d) > 0) return +2; // r > s
	if (sig(s - r - d) > 0) return -2; // s > r
	return (sig(r + s - d) >= 0) ? 1 : 0;
}
Pt c[110];
double r[110];
vector<Pt> p[110];
vector<pair<int,int> > tp;
int v[11100];
double ad[110][110];
int main(){
	int a;
	double b;
	while(scanf("%d%lf",&a,&b),a){
		for(int i=0;i<a;i++){
			double x,y;
			scanf("%lf%lf%lf",&x,&y,r+i);
			c[i]=Pt(x,y);
		}
		for(int i=0;i<11100;i++)v[i]=0;
		for(int i=0;i<a;i++)p[i].clear();
		tp.clear();
		bool dame=false;
		for(int i=0;i<a;i++)if(r[i]>b+EPS)dame=true;
		for(int i=0;i<a;i++){
			for(int j=i+1;j<a;j++){
				if(iCC(c[i],b-r[i],c[j],b-r[j])==0)dame=true;
			}
		}
		if(dame){printf("0.0\n");continue;}
		for(int i=0;i<a;i++)for(int j=0;j<a;j++){
			if(iCC(c[i],b-r[i],c[j],b-r[j])==1){
				pair<Pt,Pt> t=pCC(c[i],b-r[i],c[j],b-r[j]);
				p[i].push_back(t.first);
				p[i].push_back(t.second);
			}
		}
		for(int i=0;i<a;i++){
			int n=p[i].size();
			if(n==0){
				p[i].push_back(c[i]+Pt(cos(1),sin(1)));
				p[i].push_back(c[i]+Pt(cos(1),sin(1)));
			}else{
				for(int j=0;j<n;j++){
					for(int k=0;k<n-1;k++){
						if((p[i][k]-c[i]).arg()>(p[i][k+1]-c[i]).arg()){
							swap(p[i][k],p[i][k+1]);
						}
					}
				}
				p[i].push_back(p[i][0]);
			}
		}
		double ret=0;
		for(int i=0;i<a;i++)for(int j=0;j<p[i].size()-1;j++){
			if(p[i].size()>2&&(p[i][j]-p[i][j+1]).ABS()<EPS)continue;
			double th=((p[i][j]-c[i]).arg()+(p[i][j+1]-c[i]).arg()+((j==p[i].size()-2)?PI*2:0))/2;
			Pt t=c[i]+Pt(cos(th),sin(th))*(b-r[i]);
			bool ok=true;
			for(int k=0;k<a;k++){
				if((t-c[k]).ABS()>b-r[k]+EPS){ok=false;break;}
			}
			if(ok){
			//	printf("%f %f %f %f\n",p[i][j].x,p[i][j].y,p[i][j+1].x,p[i][j+1].y);
				ret+=(b*2-r[i])*(((j==p[i].size()-2)?PI*2:0)+(p[i][j+1]-c[i]).arg()-(p[i][j]-c[i]).arg());
				tp.push_back(make_pair(i,j));
			}
		}
		int sz=tp.size();
		int at=0;
		int prev=-1;
		for(int i=0;i<a;i++)for(int j=0;j<a;j++){
			if(iCC(c[i],b-r[i],c[j],b-r[j])==1){
				pair<Pt,Pt> t=pCC(c[i],b-r[i],c[j],b-r[j]);
				double th=(t.first-c[j]).arg()-(t.first-c[i]).arg();
				if(th<0)th+=2*PI;
				if(th>PI)th=2*PI-th;
				ad[i][j]=th*b;
//				printf("%d %d: %f\n",i,j,ad[i][j]);
			}
		}
		for(int i=0;i<sz;i++){
			for(int j=0;j<sz;j++){
				if(at==j||(prev==j&&sz>2))continue;
				bool ok=false;
				if((p[tp[at].first][tp[at].second]-p[tp[j].first][tp[j].second]).ABS()<EPS)ok=true;
				if((p[tp[at].first][tp[at].second+1]-p[tp[j].first][tp[j].second]).ABS()<EPS)ok=true;
				if((p[tp[at].first][tp[at].second]-p[tp[j].first][tp[j].second+1]).ABS()<EPS)ok=true;
				if((p[tp[at].first][tp[at].second+1]-p[tp[j].first][tp[j].second+1]).ABS()<EPS)ok=true;
				if(ok){
					ret+=ad[tp[at].first][tp[j].first];
				//	printf("%d %d\n",tp[at].first,tp[j].first);
			//		printf("%f\n",ret);
					prev=at;at=j;break;
				}
			}
		}
		printf("%.12f\n",ret);
	}
}