Problem: You are given a set of circles C of a variety of radii (radiuses) placed at a variety of positions, possibly overlapping one another. Given a circle with radius r, that circle may be placed so that it encircles all of the circles in the set C if r is large enough.

There may be more than one possible position of the circle of radius r to encircle all the member circles of C. We define the region U as the union of the areas of encircling circles at all such positions. In other words, for each point in U, there exists a circle of radius r that encircles that point and all the members of C. Your task is to calculate the length of the periphery of that region U.

Figure I.1 shows an example of the set of circles C and the region U. In the figure, three circles contained in C are expressed by circles of solid circumference, some possible positions of the encircling circles are expressed by circles of dashed circumference, and the area U is expressed by a thick dashed closed curve.

<image>



Input

The input is a sequence of datasets. The number of datasets is less than 100.

Each dataset is formatted as follows.

n r
x1 y1 r1
x2 y2 r2
.
.
.
xn yn rn

The first line of a dataset contains two positive integers, n and r, separated by a single space. n means the number of the circles in the set C and does not exceed 100. r means the radius of the encircling circle and does not exceed 1000.

Each of the n lines following the first line contains three integers separated by a single space. (xi, yi) means the center position of the i-th circle of the set C and ri means its radius.

You may assume −500≤xi ≤500, −500≤yi ≤500, and 1≤ri ≤500.

The end of the input is indicated by a line containing two zeros separated by a single space.

Output

For each dataset, output a line containing a decimal fraction which means the length of the periphery (circumferential length) of the region U.

The output should not contain an error greater than 0.01. You can assume that, when r changes by ε (|ε| < 0.0000001), the length of the periphery of the region U will not change more than 0.001.

If r is too small to cover all of the circles in C, output a line containing only 0.0.

No other characters should be contained in the output.

Example

Input

1 10
5 5 7
2 12
5 5 7
8 6 3
3 10
3 11 2
2 1 1
2 16 3
3 15
-5 2 5
9 2 9
5 8 6
3 38
-25 -10 8
30 5 7
-3 35 11
3 39
-25 -10 8
30 5 7
-3 35 11
3 800
-400 400 2
300 300 1
300 302 1
3 800
400 -400 2
300 300 1
307 300 3
8 147
130 80 12
130 -40 12
-110 80 12
-110 -40 12
70 140 12
70 -100 12
-50 140 12
-50 -100 12
3 493
345 154 10
291 111 75
-275 -301 46
4 55
54 0 1
40 30 5
27 36 10
0 48 7
3 30
0 3 3
-3 0 4
400 0 3
3 7
2 3 2
-5 -4 2
-4 3 2
3 10
-5 -4 5
2 3 5
-4 3 5
4 6
4 6 1
5 5 1
1 7 1
0 1 1
3 493
345 154 10
291 111 75
-275 -301 46
5 20
-9 12 5
0 15 5
3 -3 3
12 9 5
-12 9 5
0 0


Output

81.68140899333463
106.81415022205297
74.11215318612639
108.92086846105579
0.0
254.85616536128433
8576.936716409238
8569.462129048667
929.1977057481128
4181.124698202453
505.09134735536804
0.0
46.82023824234038
65.66979416387915
50.990642291793506
4181.124698202453
158.87951420768937

Solution (in CPP):

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