Problem: E --Disappear Drive

Story

The person in D likes basketball, but he likes shooting, so other techniques are crazy. I'm not particularly good at dribbling, and when I enter the opponent's defensive range, I always get the ball stolen. So I decided to come up with a deadly dribble that would surely pull out any opponent. After some effort, he finally completed the disappearing drive, "Disapia Drive".

This Apia Drive creates a gap by provoking the opponent to deprive him of his concentration and take his eyes off, and in that gap he goes beyond the wall of dimension and slips through the opponent's defensive range. It's a drive. However, crossing the dimensional wall puts a heavy burden on the body, so there is a limit to the number of times the dimensional wall can be crossed. Also, because he always uses his concentration, he can only change direction once, including normal movements. How do you move on the court to reach the goal in the shortest time without being robbed of the ball?

Problem

Consider a rectangle on a two-dimensional plane with (0,0) at the bottom left and (50,94) at the top right. In addition, there are N circles on this plane, the center position of the i-th circle is (x_i, y_i), and the radius is r_i. There is no overlap between the circles.

Let (25,0) be the point S and (25,94) be the point G, and consider the route from S to G. A "path" consists of (1) a line segment connecting S and G, or (2) a combination of a line segment SP and a line segment GP at any point P inside a rectangle. In the middle of the route from S to G, the period from entering the inside of a circle to exiting the inside of the circle is defined as "the section passing through the inside of the circle". However, it is assumed that the circumferences of the rectangle and the circle are not included in the rectangle and the circle, respectively.

Find the length of the shortest route among the routes where the number of sections passing through the inside of the circle is D or less. If you can't reach the goal, return -1.

Input

The input consists of the following format.


N D
x_1 y_1 r_1
...
x_N y_N r_N

The first line consists of two integers, and the number N of circles and the number of times D that can pass inside the circle are given, separated by one blank character. The following N lines are given circle information. The i + 1 line (1 \ leq i \ leq N) consists of three integers, and the x-coordinate x_i, y-coordinate y_i, and radius r_i of the center of the i-th circle are given by separating them with one blank character.

Constraints:

* 0 \ leq N \ leq 5
* 0 \ leq D \ leq 5
* 0 \ leq x_i \ leq 50
* 0 \ leq y_i \ leq 94
* 1 \ leq r_i \ leq 100
* It can be assumed that any two circles are separated by 10 ^ {-5} or more.
* It can be assumed that S and G are not included inside any circle.
* It can be assumed that S and G are separated from any circle by 10 ^ {-5} or more.
* It can be assumed that the point P in the shortest path is more than 10 ^ {-5} away from the circumference of the rectangle and any circumference.



Output

Output the length of the shortest path on one line. Be sure to start a new line at the end of the line. However, if you cannot reach the goal, return -1. Absolute error or relative error of 10 ^ {-7} or less is allowed for the correct answer.

Sample Input 1


Ten
25 47 10

Sample Output 1


96.2027355887

DisappearDrive_sample1.png

The detour route is the shortest because it cannot disappear.

Sample Input 2


1 1
25 47 10

Sample Output 2


94.0000000000

DisappearDrive_sample2.png

It can disappear, so you just have to go straight through it.

Sample Input 3


Ten
20 47 5

Sample Output 3


94.0000000000

DisappearDrive_sample3.png

Since the circumference is not included in the circle, it can pass through without disappearing.

Sample Input 4


Ten
25 47 40

Sample Output 4


-1

DisappearDrive_sample4.png

You can't reach the goal because you can't disappear or detour.

Sample Input 5


5 2
11 10 16
33 40 18
20 66 10
45 79 14
22 85 8

Sample Output 5


96.1320937224

DisappearDrive_sample5.png





Example

Input

1 0
25 47 10


Output

96.2027355887

Solution (in CPP):

Solution:
#include<cstdio>
#include<iostream>
#include<vector>
#include<complex>
#include<string>
#include<algorithm>
#include<set>
#include<cassert>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


const double EPS = 1e-8;
const double INF = 1e12;

typedef complex<double> P;

#define X real()
#define Y imag()

#define Curr(P,i) P[(i)%P.size()]
#define Next(P,i) P[(i+1)%P.size()]
#define Prev(P,i) P[(i+P.size()-1)%P.size()]


namespace std{
  bool operator<(const P a,const P b){
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}
double cross(const P a,const P b){
  return (conj(a)*b).imag();
}
double dot(const P a,const P b){
  return (conj(a)*b).real();
}
// TODO make graph (20)
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
  if(norm(b)<norm(c)) return -2;// a--b--c
                      return 0;// a--c--b(or b==c)
}

struct L : public vector<P>{
  L(const P a,const P b){
    push_back(a),push_back(b);
  }
};
typedef L S;
typedef vector<P> G;

struct C{
  P p;double r;
  C(const P p,double r): p(p),r(r){}
};

P projection(L a,P p){
  double t = dot(p-a[0],a[0]-a[1])/norm(a[0]-a[1]+EPS);
  return a[0] + t*(a[0]-a[1]);
}
P reflection(L a,P p){
  return p + 2.0 * (projection(a,p)-p);
}

bool isCrossLL(L a,L b){
  return
    abs(cross(a[1]-a[0],b[1]-b[0])) > EPS
    || abs(cross(a[1]-a[0],b[0]-a[0])) < EPS ;
}
P crossP_LL(L a,L b){
  double A = cross(a[1]-a[0],b[1]-b[0]);
  double B = cross(a[1]-a[0],a[1]-b[0]);
  if(abs(A)<EPS && abs(B)<EPS)return b[0];
  if(abs(A)<EPS)assert(false);
  return b[0]+B/A*(b[1]-b[0]);
}

vector<L> TLine_CP(C c,P p){
  P v = c.p - p;
  double t = asin(abs(c.r)/(abs(v)));
  P e = v/abs(v) * exp(P(.0,t));
  P n1 = sqrt(abs(v)*abs(v) - c.r*c.r)*e + p;
  P n2 = reflection(L(p,c.p),n1);
  
  vector<L> ret;
  ret.push_back(L(p,n1));
  ret.push_back(L(p,n2));
  return ret;
}

bool isCrossSP(S a,P p){
  return abs(a[0]-p)+abs(a[1]-p)-abs(a[0]-a[1]) < EPS;
}
double distSP(S a,P p){
  const P r = projection(a,p);
  bool f = isCrossSP(a,r);
  return f ? abs(p-r) : min(abs(a[0]-p),abs(a[1]-p));
}
double distPP(P a,P b){
  return abs(a-b);
}


int n,m;
vector<C> cir;

void input(){
	cin>>n>>m;
	rep(i,n){
		int a,b,c;
		cin>>a>>b>>c;
		cir.push_back(C(P(a,b),c));
	}
}


class Path : public vector<L>{
	public:
	Path(L a){push_back(a);}
	Path(L a, L b){push_back(a);push_back(b);}
};

vector<Path> path;

void makeLines(){
	P st(25,0);
	P en(25,94);
	
	path.push_back(Path(L(st,en)));
	rep(i,cir.size()){
		rep(j,cir.size()){
			vector<L> ps = TLine_CP(cir[i], st);
			vector<L> pe = TLine_CP(cir[j], en);
			rep(k,ps.size()){
				rep(p,pe.size()){
					path.push_back(Path(ps[k],pe[p]));
				}
			}
		}
	}
}

void printLines(){
	rep(i,path.size()){
		rep(j,path[i].size()){
			printf("(%lf,%lf)-(%lf,%lf) ",path[i][j][0].X,path[i][j][0].Y,path[i][j][1].X,path[i][j][1].Y);
		}puts("");
	}
}

bool boxin(P p){
	return p.X>-EPS && p.X<50+EPS && p.Y>-EPS && p.Y<94+EPS; 
}

void removeOut(){
	rep(i,path.size()){
		bool flg = true;
		rep(j,path[i].size()-1){
			if(isCrossLL(path[i][j], path[i][j+1])){
				P p = crossP_LL(path[i][j], path[i][j+1]);
				path[i][j][1] = p;
				path[i][j+1][1] = p;
				if(!boxin(p))flg=false;
			}else{
				flg=false;
			}
		}
		if(!flg){
			path.erase(path.begin()+i);
			i--;
		}
	}
}

void removeCircleOn(){
	rep(i,path.size()){
		int count = 0;
		
		rep(k,cir.size()){
			rep(j,path[i].size()){
				double dist = distSP(path[i][j], cir[k].p);
				if(dist+EPS<cir[k].r)count++;
			}
			if(distPP(cir[k].p, path[i][0][1])+EPS<cir[k].r)count--;
		}
		//printf("%d %d\n",i,count);
		if(count>m){
			path.erase(path.begin()+i);
			i--;
		}
	}
}

/*
1 0
25 47 100

*/
double minLength(){
	double mini = INF;
	rep(i,path.size()){
		double sum = 0;
		rep(j,path[i].size()){
			sum += distPP(path[i][j][0], path[i][j][1]);
		}
		mini = min(sum, mini);
	}
	if(mini==INF)return -1;
	return mini;
}
double solve(){
	
	makeLines();
	removeOut();
	
	//printLines();
	
	removeCircleOn();
	
	
	return minLength();
}


int main(){
	input();
	printf("%.12lf\n",solve());
}