#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <utility>
#include <vector>
namespace lc {
static const double EPS = 1e-9;
inline double abs(double x){ return std::abs(x); }
inline bool tolerant_eq(double a, double b){ return abs(a - b) < EPS; }
}
namespace lc {
struct Point {
	double x;
	double y;
	explicit Point(const double &x = 0.0, const double &y = 0.0) :
		x(x), y(y)
	{ }
	Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }
	Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }
	Point operator*(const Point &p) const {
		return Point(x * p.x - y * p.y, x * p.y + y * p.x);
	}
	Point operator/(double s) const { return Point(x / s, y / s); }
	double abs() const { return sqrt(x * x + y * y); }
	double arg() const { return atan2(y, x); }
};
inline bool tolerant_eq(const Point &a, const Point &b){
	return tolerant_eq(a.x, b.x) && tolerant_eq(a.y, b.y);
}
}
namespace lc {
struct Circle {
	Point c;
	double r;
	explicit Circle(const Point &c = Point(), double r = 0.0) :
		c(c), r(r)
	{ }
};
inline bool tolerant_eq(const Circle &a, const Circle &b){
	return tolerant_eq(a.c, b.c) && tolerant_eq(a.r, b.r);
}
}
namespace lc {
inline bool intersect(const Circle &a, const Circle &b){
	const double d = (a.c - b.c).abs();
	return d <= a.r + b.r && a.r + d >= b.r && b.r + d >= a.r;
}
}
namespace lc {
inline std::vector<Point> crossing_points(const Circle &a, const Circle &b){
	std::vector<Point> ret;
	if(!intersect(a, b)){ return ret; }
	if(tolerant_eq(a, b)){
		ret.push_back(a.c + Point(a.r, 0.0));
		ret.push_back(a.c + Point(-a.r, 0.0));
		ret.push_back(a.c + Point(0.0, a.r));
	}else{
		const double d = (a.c - b.c).abs();
		const double rc = (d * d + a.r * a.r - b.r * b.r) / (2.0 * d);
		const double rs = sqrt(a.r * a.r - rc * rc);
		const Point diff = (b.c - a.c) / d;
		const Point x = a.c + diff * Point(rc, rs);
		const Point y = a.c + diff * Point(rc, -rs);
		ret.push_back(x);
		if(!tolerant_eq(x, y)){ ret.push_back(y); }
	}
	return ret;
}
}
using namespace std;
inline bool contains_all(const lc::Circle &c, const vector<lc::Circle> &cs){
	for(const auto &t : cs){
		const double d = (c.c - t.c).abs();
		if(d + t.r > c.r + lc::EPS){ return false; }
	}
	return true;
}
int main(){
	ios_base::sync_with_stdio(false);
	cout << setiosflags(ios::fixed) << setprecision(10);
	while(true){
		int n;
		double r;
		cin >> n >> r;
		if(n == 0){ break; }
		std::vector<lc::Circle> circles(n);
		for(int i = 0; i < n; ++i){
			cin >> circles[i].c.x >> circles[i].c.y >> circles[i].r;
		}
		vector<lc::Point> corners;
		vector<vector<double>> args(n);
		for(int i = 0; i < n; ++i){
			for(int j = i + 1; j < n; ++j){
				const lc::Circle a(circles[i].c, r - circles[i].r);
				const lc::Circle b(circles[j].c, r - circles[j].r);
				const auto cps = lc::crossing_points(a, b);
				for(const auto &p : cps){
					if(contains_all(lc::Circle(p, r), circles)){
						corners.push_back(p);
						args[i].push_back((p - a.c).arg());
						args[j].push_back((p - b.c).arg());
					}
				}
			}
		}
		int m = 0;
		for(const auto &p : corners){
			bool accept = true;
			for(int i = 0; accept && i < m; ++i){
				if(!lc::tolerant_eq(p, corners[i])){ continue; }
				accept = false;
			}
			if(accept){ corners[m++] = p; }
		}
		corners.resize(m);
		double answer = 0.0;
		if(m == 0){
			for(const auto &c : circles){
				if(!contains_all(c, circles)){ continue; }
				const double s = r * 2.0 - c.r;
				answer = s * 2.0 * M_PI;
				break;
			}
		}else if(m == 1){
			const lc::Circle c(corners[0], r);
			if(contains_all(c, circles)){
				answer = r * 2.0 * M_PI;
			}
		}else{
			double remains = 2.0 * M_PI;
			for(int i = 0; i < n; ++i){
				sort(args[i].begin(), args[i].end());
				int k = 0;
				for(size_t j = 0; j < args[i].size(); ++j){
					if(k == 0 || !lc::tolerant_eq(args[i][j], args[i][k - 1])){
						args[i][k++] = args[i][j];
					}
				}
				args[i].resize(k);
				double sum = 0.0;
				for(size_t j = 0; j + 1 < args[i].size(); j += 2){
					sum += args[i][j + 1] - args[i][j];
				}
				sum = min(sum, 2.0 * M_PI - sum);
				const double s = r * 2.0 - circles[i].r;
				answer += s * sum;
				remains -= sum;
			}
			answer += r * remains;
		}
		cout << answer << endl;
	}
	return 0;
}