#include <set>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <cstdio>
#include <cassert>

#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

typedef complex<double> P;

const double EPS = 1e-10;
const double PI  = 3.1415926535;

class Circle{
public:
  P p;
  double r;

  Circle(){}
  Circle(P c, double rr) : p(c), r(rr) {}
};

pair<P, P> crossPoint(const Circle &c1, const Circle &c2){
  double d  = std::abs(c1.p - c2.p);
  double rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d);
  double rs = sqrt(c1.r * c1.r - rc * rc);
  P diff = (c2.p - c1.p) / d;
  return make_pair(c1.p + diff * P(rc, rs), c1.p + diff * P(rc, -rs));
}

bool isCross(const Circle &c1, const Circle &c2){
  if(abs(c1.p - c2.p) < c1.r + c2.r + EPS)
    if(abs(c1.p - c2.p) + EPS > max(c1.r, c2.r) - min(c1.r, c2.r))
      return true;
  return false;
}

bool containAll(const Circle &c, const vector<Circle> &cs){
  REP(i, cs.size()){
    if(c.r + EPS < std::abs(c.p - cs[i].p) + cs[i].r)
      return false;
  }
  return true;
}

struct Data{
  P cc;
  P ec;
  int id;

  Data (P c, P e, int i) :
    cc(c), ec(e), id(i) {}
};

struct cmp{
  P center;

  cmp(P c) : center(c){}

  bool operator() (const Data &lhs, const Data &rhs){
    return arg(lhs.ec - center) < arg(rhs.ec - center);
  }
};

int main(){
  int n, r;

  while(scanf("%d%d", &n, &r), n + r){
    vector<Circle> cs(n);
    bool imp = false;

    REP(i,n){
      int x, y, rr;
      scanf("%d%d%d", &x, &y, &rr);
      cs[i] = Circle(P(x, y), rr);
      if(r < rr) imp = true;
    }

    if(imp){
      printf("%.10f\n", 0.0);
      continue;
    }

    if(n == 1){
      printf("%.10f\n", 2 * (2 * r - cs[0].r) * PI);
    }else{
      P center;
      bool ok = false;

      vector<Data> data;

      REP(i,n){
        REP(j, i){
          double ri = r - cs[i].r;
          double rj = r - cs[j].r;
          Circle c1 = Circle(cs[i].p, ri);
          Circle c2 = Circle(cs[j].p, rj);

          if(isCross(c1, c2)){
            pair<P, P> ret = crossPoint(c1, c2);

            if(containAll(Circle(ret.first,  r), cs)){ ok = true; center = ret.first;  }
            if(containAll(Circle(ret.second, r), cs)){ ok = true; center = ret.second; }
          }
          if(ok) break;
        }
        if(ok) break;
      }

      if(!ok){
        REP(i,n) if(containAll(cs[i], cs)){
          ok = true;
          printf("%.10f\n", 2 * (2 * r - cs[i].r) * PI);
          break;
        }

        if(!ok) printf("%.10f\n", 0.0);
        continue;
      }

      REP(i,n){
        REP(j, i){
          double ri = r - cs[i].r;
          double rj = r - cs[j].r;
          Circle c1 = Circle(cs[i].p, ri);
          Circle c2 = Circle(cs[j].p, rj);

          if(isCross(c1, c2)){
            pair<P, P> ret = crossPoint(c1, c2);

            if(containAll(Circle(ret.first,  r), cs)){
              P p1 = (ret.first - cs[i].p); p1 *= r / abs(p1); p1 += ret.first;
              P p2 = (ret.first - cs[j].p); p2 *= r / abs(p2); p2 += ret.first;
              data.push_back(Data(ret.first, p1, i));
              data.push_back(Data(ret.first, p2, j));
            }

            if(containAll(Circle(ret.second, r), cs)){
              P p1 = (ret.second - cs[i].p); p1 *= r / abs(p1); p1 += ret.second;
              P p2 = (ret.second - cs[j].p); p2 *= r / abs(p2); p2 += ret.second;

              data.push_back(Data(ret.second, p1, i));
              data.push_back(Data(ret.second, p2, j));
            }
          }
        }
      }

      double ans = 0.0;
      sort(data.begin(), data.end(), cmp(center));

      /*
      REP(i, data.size()){
        cout << i << ": " << data[i].cc << " " << data[i].ec << " " << data[i].id << endl;
      }
      */

      REP(i, data.size()){
        int j = i + 1 == data.size() ? 0 : i + 1;

        if(data[i].id != data[j].id){
          double ag = std::abs(arg((data[i].ec - data[i].cc) / (data[j].ec - data[j].cc)));
          double rr = std::abs(data[i].ec - data[i].cc);

          // cout << "pattern1 ag: " << ag << " rr: " << rr << " " << rr2 << endl;
          ans += rr * ag;
        }else{
          int id = data[i].id;
          double ag = std::abs(arg((data[i].ec - cs[id].p) / (data[j].ec - cs[id].p)));
          double rr = std::abs(r + (r - cs[id].r));

          // cout << "pattern2 ag: " << ag << " rr: " << rr << endl;
          ans += rr * ag;
        }
      }

      printf("%.10f\n", ans);
    }
  }

  return 0;
}

Measured memory_bytes: 0