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>
#define inf 1<<29
#define linf 1e16
#define eps (1e-4)
#define Eps (1e-15)
#define mod 1000000007
#define pi acos(-1)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ 
    return equals(x,p.x) ? y-p.y<-eps : x-p.x<-eps; }
  bool operator==(Point p)const{ 
    return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1=Point(),Point p2=Point()):p1(p1),p2(p2){}
};
typedef Segment Line;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c=Point(),double r=0.0):c(c),r(r){}
  bool operator<(Circle c)const{ return r<c.r; }
};

class Arc{
public:
  Circle c;
  Vector v1,v2;
  Arc(Circle c,Vector v1,Vector v2):c(c),v1(v1),v2(v2){}
};

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}

double arc(Arc a){
  return a.c.r*2.0*acos(abs(a.v1)*abs(a.v1)/dot(a.v1,a.v2))/2.0;
}

int intersect(Circle a,Circle b){
  double d=abs(a.c-b.c);
  if(a.r<b.r)swap(a,b);
  if(a.r+b.r+eps<=d)return 2;
  if(a.r+b.r-eps<=d)return 1;
  if(a.r-b.r+eps<=d)return 0;
  if(a.r-b.r-eps<=d)return -1;
  return -2;
}

double arg(Vector p){ return atan2(p.y,p.x);}
Vector polar(double a,double r){ return Point(cos(r)*a,sin(r)*a);}

vector<Point> arg_sort(Point p,vector<Point> v){
  vector<pair<double,Point> > tmp;
  vector<Point> res;
  FOR(i,0,v.size()){
    double a=arg(p-v[i]);
    if(a<0.0)a+=360.0;
    tmp.pb(mp(a,v[i]));
  }
  sort(all(tmp));
  FOR(i,0,tmp.size())res.pb(tmp[i].s);
  return res;
}

pair<Point,Point> getCrossPoints(Circle c1,Circle c2){
  double d=abs(c1.c-c2.c);
  double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
  double t=arg(c2.c-c1.c);
  return mp(c1.c+polar(c1.r,t+a),c1.c+polar(c1.r,t-a));
}

Point rotate(Point base,Point a,double r){
  Point b=a-base;
  a.x=b.x*cos((r/180.0)*pi)-b.y*sin((r/180.0)*pi);
  a.y=b.x*sin((r/180.0)*pi)+b.y*cos((r/180.0)*pi);
  a=a+base;
  return a;
}

double getAngle(Vector a,Vector b){
  double tmp=dot(a,b)/(abs(a)*abs(b));
  if(tmp<-1.0)tmp=-1.0;
  if(1.0<tmp)tmp=1.0;
  double r=acos(tmp)*180.0/pi;
  if(cross(a,b)<-eps)r=360.0-r;
  return r;
}

vector<Point> unique(vector<Point> v){
  vector<Point> res;
  sort(all(v));
  res.pb(v[0]);
  FOR(i,1,v.size())if(!(res.back()==v[i]))res.pb(v[i]);
  return res;
}

bool in(Circle c,Point a){ return abs(a-c.c)<c.r+eps; }
bool on(Circle c,Point a){ return equals(abs(a-c.c),c.r); }

int n;
double R;
vector<Circle> v;

double solve(){
  vector<Circle> C;
  FOR(i,0,n){
    if(R<v[i].r)return 0;
    C.pb(Circle(v[i].c,R-v[i].r));
  }
  if(n==1)return (C[0].r+R)*2.0*pi;
  sort(all(C));
  FOR(i,1,C.size()){
    if(intersect(C[0],C[i])!=-2)break;
    if(i==C.size()-1)return (C[0].r+R)*2.0*pi;
  }
  vector<Point> A,B;
  FOR(i,0,C.size()){
    FOR(j,i+1,C.size()){
     // if(abs(intersect(C[i],C[j]))==2)return 0;
      pair<Point,Point> pp=getCrossPoints(C[i],C[j]);
      A.pb(pp.f);
      A.pb(pp.s);
    }
  }
  FOR(i,0,A.size()){
    FOR(j,0,C.size()){
      if(!in(C[j],A[i]))break;
      if(j==C.size()-1)B.pb(A[i]);
    }
  }
  if(B.size()==0)return 0.0;
  FOR(i,0,C.size()){
    FOR(j,0,B.size()){
      if(in(C[i],B[j]))break;
      if(j==B.size()-1)return 0.0;
    }
  } 
  B = unique(B);
  double res = 0.0;
  FOR(i,0,C.size()){
    vector<Point> tmp;
    FOR(j,0,B.size())if(on(C[i],B[j]))tmp.pb(B[j]);
    if(tmp.size()==0)continue;
    tmp = arg_sort(C[i].c,tmp);
    FOR(j,0,tmp.size()){
      Point p1=tmp[j],p2=tmp[(j+1)%tmp.size()];
      double ang = getAngle(p1-C[i].c,p2-C[i].c);
      Point mid = rotate(C[i].c,p1,ang/2.0);
      bool f = true;
      FOR(k,0,C.size())
        if(!in(C[k],mid))f = false;
      if(!f)continue;
      res+=(C[i].r+R)*pi*ang/180.0;
    }
  }
  FOR(i,0,B.size()){
    vector<Point> tmp;
    FOR(j,0,C.size())if(on(C[j],B[i]))tmp.pb(C[j].c);
    tmp = arg_sort(B[i],tmp);
    if(tmp.size()<2)continue;
    FOR(j,0,tmp.size()){
      Point p1=tmp[j],p2=tmp[(j+1)%tmp.size()];
      double ang = getAngle(p1-B[i],p2-B[i]);
      if(ang>180)continue;
      res+=R*pi*ang/180.0;
    }
  }
  return res;
}

int main()
{
  while(cin>>n>>R && n){
    v.resize(n);
    FOR(i,0,n)cin>>v[i].c.x>>v[i].c.y>>v[i].r;
    pd(solve());
  }
  return 0;
}