#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

double normalize(double a) {
  assert(a <= 4*PI && a >= -2*PI);
  if (a > 2*PI) return a-2*PI;
  if (a < 0) return a+2*PI;
  return a;
}

typedef complex<double> P;
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

double angle(const P &a, const P &b) {        // ベクトルａからみたベクトルｂの角度の計算[0,2pi)
  double ret = arg(b)-arg(a);
  return (ret>=0) ? ret : ret + 2*PI;
}

P p[100];
double r[100];
double R;


vector<pdd> seg_union(const vector<pdd> &v1, const vector<pdd> &v2) {
  vector<pdd> res;
  FOR(it, v1) {
    FOR(jt, v2) {
      double a = max(it->first, jt->first);
      double b = min(it->second, jt->second);
      if (a-EPS < b)
        res.push_back(pdd(a,b));
    }
  }
  return res;
}

void add_seg(vector<pdd> &v, double a, double b) {
  a = normalize(a);
  b = normalize(b);
  // cout << a << " -> " << b << endl;
  vector<pdd> t;
  if (a-EPS<=b) {
    t.push_back(pdd(a,b));
  } else {
    t.push_back(pdd(a,2*PI));
    t.push_back(pdd(0,b));
  }
  v = seg_union(v,t);
}

double yogen(double a, double b, double c) {
  double cosA = (b*b+c*c-a*a) / (2*b*c);
  // cout << a << " " << b << " " << c << " " << cosA << endl;
  if (cosA < -1 || cosA > 1) return 0;
  assert(cosA>=-1 && cosA<=1);
  return acos(cosA);
}

bool contain(int i, int j) {
  double d = abs(p[i]-p[j]);
  if (d == r[i]-r[j]) return i<j;
  return d < r[i]-r[j];
}

map<pii,int> mp;
int n;

double func(int i, double ang) {
  P center = p[i] + P(cos(ang),sin(ang)) * P(R-r[i],0);
  int id = -1;
  REP(j,n) {
    if (i==j) continue;
    if (abs(abs(center-p[j]) - (R-r[j])) < EPS) {
      if (angle(p[i]-center,p[j]-center) > PI) continue;
      // cout << j << ", " ;
      if (id == -1 || angle(p[i]-center,p[id]-center) > angle(p[i]-center,p[j]-center)) {
        id = j;
      }
    }
  }
  //  cout << endl;
  // cout << " * " << id << endl;
  if (id == -1) return 0;
  // if (i > id) swap(i,id);
  pii tmp = pii(i,id);
  if (mp.count(tmp) == 0) {
    mp[tmp] = 1;
    return R * yogen(abs(p[i]-p[id]), R-r[i], R-r[id]);
  }
  return 0;
}

double solve(int i) {
  vector<pdd> segs;
  segs.push_back(pdd(0,2*PI));
  bool dame = 0;
  REP(j,n) {
    if (i == j) continue;
    if (contain(j,i)) {
      dame = 1;
      break;
    }
    if (contain(i,j)) continue;
    double th = yogen(R-r[j], R-r[i], abs(p[i]-p[j]));
    double ang = arg(p[j]-p[i]);
    // cout << ang << " " << th << endl;
    add_seg(segs, ang-th, ang+th);
  }
  if (dame) return 0;
  double res = 0;
  double res2 = 0;
  // cout << i << endl;
  FOR(it, segs) {
    res2 += func(i,it->first);
    res2 += func(i,it->second);
    res += it->second-it->first;
    // cout << it->first << " - " << it->second << endl;
  }
  return res * (2*R-r[i]) + res2;
}

int main() {
  while(cin>>n>>R,n||R) {
    bool f = 0;
    REP(i,n) {
      cin >> p[i].real() >> p[i].imag() >> r[i];
      if (r[i] > R) f = 1;
    }
    if (f) {
      puts("0.0");
      continue;
    }
    double ans = 0;
    mp.clear();
    REP(i,n) {
      ans += solve(i);
    }
    printf("%.12f\n", ans);
  }
}

Measured memory_bytes: 1392