#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;
}




Measured memory_bytes: 3960