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 <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

/* 基本要素 */
typedef complex<double> Point;
typedef pair<Point, Point> Line;
typedef vector<Point> VP;
const double PI = acos(-1);
const double EPS = 1e-7; // 許容誤差^2
const double INF = 1e9;
#define X real()
#define Y imag()
// #define LE(n,m) ((n) < (m) + EPS)
#define LE(n,m) ((n) - (m) < EPS)
// #define GE(n,m) ((n) + EPS > (m))
#define GE(n,m) (EPS > (m) - (n))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// 内積　dot(a,b) = |a||b|cosθ
double dot(Point a, Point b) {
  return a.X*b.X + a.Y*b.Y;
}

// 外積　cross(a,b) = |a||b|sinθ
double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

// 点の進行方向
// !!! 誤差に注意 !!! (掛け算したものとかなり小さいものを比べているので)
int ccw(Point a, Point b, Point c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}

// 2円の交点
VP crosspointCC(Point a, double ar, Point b, double br) {
  VP ps;
  Point ab = b-a;
  double d = abs(ab);
  double crL = (norm(ab) + ar*ar - br*br) / (2*d);
  if (EQ(d, 0) || ar+EPS < abs(crL)) return ps;

  // 円が接する時、こことEPSの設定をうまくしないとsqrt(sub)がnanになるので注意
  double sub = ar*ar - crL*crL;
  if(EQ(sub,0)) sub = 0;

  Point abN = ab * Point(0, sqrt(sub) / d);
  Point cp = a + crL/d * ab;
  ps.push_back(cp + abN);
  if (!EQ(norm(abN), 0)) ps.push_back(cp - abN);
  return ps;
}

// aからbへの回転角（中心(0,0)）[-pi,+pi]
double angle(Point a,Point b){
  double t = arg(b)-arg(a);
  while(t>+PI) t-=2*PI;
  while(t<-PI) t+=2*PI;
  return t;
}

double solve(int n, double r){
    VP c(n);
    vector<double> cr(n);
    rep(i,n){
        int x,y;
        scanf(" %d %d %lf", &x, &y, &cr[i]);
        c[i] = Point(x,y);
    }

    // 円iを含むために、中心が移動できる範囲
    rep(i,n){
        cr[i] = r - cr[i];
        // dbg(cr[i]);
        if( !LE(0,cr[i]) ) return 0;
    }

    // どれかを内包する円は除去
    vector<bool> inner(n);
    rep(i,n){
        rep(j,n)if(i!=j){
            double D = abs(c[i]-c[j]);
            if( LE(D+cr[i], cr[j]) ) inner[j] = true;
        }
    }

    VP tttc;
    vector<double> tttr;
    rep(i,n){
        if(!inner[i]){
            tttc.pb(c[i]);
            tttr.pb(cr[i]);
        }
    }

    c = tttc;
    cr = tttr;
    n = c.size();

    if(n==1){
        return (cr[0]+r)*2*PI;
    }

    // n >= 2
    // 円iと円jの交点を求める
    using PPI = pair<Point,int>;
    vector<vector<PPI>> cps(n);

    rep(i,n)rep(j,i){
        VP cnd = crosspointCC(c[i], cr[i], c[j], cr[j]);
        if(cnd.size() == 0){
            // 交点がない時点で、2つを同時に包含できないのでおわり
            return 0;
        }
        else if(cnd.size() == 1){
            // 接するような円が見つかった時点で、その点にしか円はおけない
            // 置けるなら半径rの円
            bool ok = true;
            Point op = cnd[0];
            rep(k,n){
                if( !LE(abs(c[k]-op), cr[k]) ) ok = false;
            }

            if(ok) return r*2*PI;
            else return 0;
        }

        for(Point cp:cnd){
            cps[i].pb({cp,j});
            cps[j].pb({cp,i});
        }
    }

    // 偏角ソート
    double ans = 0;
    VP cand_pts;
    rep(i,n){
        vector<PPI> dat = cps[i];
        int sz = dat.size();

        // (偏角, index)
        using pd = pair<double,int>;
        vector<pd> stmp(sz);
        rep(j,sz){
            double theta = atan2(dat[j].fi.Y-c[i].Y, dat[j].fi.X-c[i].X);
            if( theta < -EPS ) theta = 2*PI + theta;
            stmp[j] = {theta, j};
        }

        sort(all(stmp));

        vector<double> cand_theta(sz);
        vector<int> valid(sz,1);
        rep(j,sz){
            double add = stmp[(j+1)%sz].fi - stmp[j].fi;
            if(add < -EPS) add += 2*PI;
            add /= 2;

            cand_theta[j] = stmp[j].fi + add;

            Point cp = c[i]+polar(cr[i],cand_theta[j]);
            // dbg(cp);
            // この点がokかチェック
            rep(k,n){
                if( !LE(abs(c[k]-cp), cr[k]) ) valid[j] = 0;
            }

            if(valid[j]){
                double theta = stmp[(j+1)%sz].fi - stmp[j].fi;
                if(theta < -EPS) theta += 2*PI;

                if(EQ(theta,0)) valid[j] = false;
                else ans += theta * (r+cr[i]);
            }
        }

        // printf(" --- %d \n",i);
        // dbg(dat);
        // dbg(stmp);
        // dbg(valid);

        rep(j,sz){
            if(valid[j]^valid[(j+1)%sz]){
                int idx = stmp[(j+1)%sz].se;
                cand_pts.pb(dat[idx].fi);
            }
        }
    }

    int CPZ = cand_pts.size();
    rep(i,CPZ){
        bool ok = true;
        rep(j,i){
            double dist = abs(cand_pts[j] - cand_pts[i]);
            if(EQ(dist,0)) ok = false;
        }
        if(!ok) continue;
        // dbg(cand_pts[i]);

        double mx_angle = 0;
        rep(ci,n)rep(cj,ci){
            bool valid_pair = false;

            for(Point ppp:crosspointCC(c[ci],cr[ci],c[cj],cr[cj])){
                double ddd = abs(ppp - cand_pts[i]);
                if(EQ(ddd,0)) valid_pair = true;
            }

            if(valid_pair){
                Point center = cand_pts[i];
                Point aaa = c[ci] - center;
                Point bbb = c[cj] - center;

                mx_angle = max(mx_angle, abs(angle(aaa,bbb)));
            }
        }

        ans += mx_angle*r;
    }

    return ans;
}

int main(){
    int n;
    double r;
    while( scanf(" %d %lf", &n, &r),n ){
        printf("%.15f\n", solve(n,r));
    }
    return 0;
}