#pragma GCC optimize "O3"

#define F first
#define S second

#include <bits/stdc++.h>

using namespace std;

typedef long double T;

constexpr T eps = 1e-12, pi = acos(-1);
constexpr int N = 100;

struct pt {
  T x, y, r;
  pt(T _x = 0, T _y = 0, T _r = 0) : x(_x), y(_y), r(_r) {}
  void read() { cin >> x >> y >> r; }
  void print() { cerr << x << " " << y << " " << r << endl; }
};
T sq(T x) { return x * x; }
T dist(pt &p0, pt &p1) { return sqrt(sq(p0.x-p1.x)+sq(p0.y-p1.y)); }
T calc_deg(T c, T a, T b) { return acos((a*a+b*b-c*c)/2/a/b); }

int n;
T r, val[N][N];
vector<pt> pts;
vector<T> degs[N];
vector<pair<T, int>> ords;

bool check(pt &res) {
  for(size_t i = 0; i<pts.size(); ++i)
    if(dist(res, pts[i]) > r - pts[i].r + eps)
      return false;
  return true;
}
void tangent(size_t i0, size_t i1) {
  pt res(0, 0, r);
  pt &p0 = pts[i0], &p1 = pts[i1];
  T s0 = r - p0.r, s1 = r - p1.r, d = dist(p0, p1);
  T deg = atan2(p1.y - p0.y, p1.x - p0.x) + calc_deg(s1, s0, d);
  res.x = p0.x + s0 * cos(deg);
  res.y = p0.y + s0 * sin(deg);
  if(check(res)) {
    T deg0 = atan2(p0.y - res.y, p0.x - res.x);
    T deg1 = atan2(p1.y - res.y, p1.x - res.x);
    degs[i0].push_back(deg0);
    degs[i1].push_back(deg1);
    val[i0][i1] = r * calc_deg(d, s0, s1);
  }
}
void init() {
  ords.clear();
  pts.resize(n);
  for(int i = 0; i<n; ++i) {
    fill(val[i], val[i]+n, 0.0);
    pts[i].read();
    degs[i].clear();
  }
  vector<size_t> rems;
  for(size_t i = 0; i<pts.size(); ++i)
    for(size_t j = i+1; j<pts.size(); ++j) {
      pt &p0 = pts[i], &p1 = pts[j];
      T d = dist(p0, p1);
      if(d < p1.r - p0.r + eps)
        rems.push_back(i);
      if(d < p0.r - p1.r + eps)
        rems.push_back(j);
    }
  sort(rems.begin(), rems.end());
  rems.resize(unique(rems.begin(), rems.end()) - rems.begin());
  for(int i = rems.size()-1; i>=0; --i)
    pts.erase(pts.begin() + rems[i]);
  n = pts.size();
}
T calc_rot(T r0, T deg1, T deg2) {
  if(deg1 < deg2)
    swap(deg1, deg2);
  if(deg1 - deg2 > pi) {
    deg1 -= 2 * pi;
    swap(deg1, deg2);
  }
  return (2*r - r0) * (deg1 - deg2);
}
bool too_big() {
  for(size_t i = 0; i<pts.size(); ++i)
    for(size_t j = i+1; j<pts.size(); ++j)
      if(dist(pts[i], pts[j]) + pts[i].r + pts[j].r > 2*r + eps)
        return true;
  return false;
}
int main() {
  while(cin >> n >> r && n) {
    init();
    if(n == 1) {
      printf("%.3Lf\n", 2 * pi * (2*r - pts[0].r));
      continue;
    }
    if(too_big()) {
      puts("0.0");
      continue;
    }
    for(size_t i = 0; i<pts.size(); ++i)
      for(size_t j = i+1; j<pts.size(); ++j) {
        tangent(j, i);
        tangent(i, j);
      }
    for(int i = 0; i<n; ++i) {
      //assert(degs[i].size() >= 2 || degs[i].empty());
      sort(degs[i].begin(), degs[i].end());
      auto it = unique(degs[i].begin(), degs[i].end(),
                      [](const T &t0, const T &t1) { 
                        return abs(t0-t1)<eps || abs(t0+2*pi-t1)<eps ||
                               abs(t0-2*pi-t1)<eps; });
      degs[i].resize(it - degs[i].begin());
      if(degs[i].size() < 2)
        continue;
      for(T &deg : degs[i])
        ords.emplace_back(deg, i);
    }
    if(ords.empty())
      puts("0.0");
    else {
      sort(ords.begin(), ords.end());
      ords.push_back(ords[0]);
      ords.push_back(ords[1]);
      T ans = 0;
      for(size_t i = 1; i+1<ords.size(); ++i) {
        int id0 = ords[i-1].S, id1 = ords[i].S, id2 = ords[i+1].S;
        T deg0 = ords[i-1].F, deg1 = ords[i].F;
        if(i%2)
          ans += val[id0][id2];
        if(id0 == id1)
          ans += calc_rot(pts[id0].r, deg0, deg1);
      }
      printf("%.3Lf\n", ans);
    }
  }
}

Measured memory_bytes: 3680