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 <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;
}