Problem:
Problem D:
Lowest Pyramid
You are constructing a triangular pyramid with a sheet of craft paper with grid lines. Its base
and sides are all of triangular shape. You draw the base triangle and the three sides connected
to the base on the paper, cut along the outer six edges, fold the edges of the base, and assemble
them up as a pyramid.
You are given the coordinates of the base's three vertices, and are to determine the coordinates
of the other three. All the vertices must have integral X- and Y-coordinate values between -100 and +100 inclusive. Your goal is to minimize the height of the pyramid satisfying these
conditions. Figure 3 shows some examples.
Figure 3: Some craft paper drawings and side views of the assembled pyramids
Input
The input consists of multiple datasets, each in the following format.
X
0
Y
0
X
1
Y
1
X
2
Y
2
They are all integral numbers between -100 and +100 inclusive. (
X
0
,
Y
0
), (
X
1
,
Y
1
), (
X
2
,
Y
2
) are the coordinates of three vertices of the triangular base in counterclockwise order.
The end of the input is indicated by a line containing six zeros separated by a single space.
Output
For each dataset, answer a single number in a separate line. If you can choose three vertices (
X
a
,
Y
a
), (
X
b
,
Y
b
) and (
X
c
,
Y
c
) whose coordinates are all integral values between -100 and +100 inclusive, and triangles (
X
0
,
Y
0
)-(
X
1
,
Y
1
)-(
X
a
,
Y
a
), (
X
1
,
Y
1
)-(
X
2
,
Y
2
)-(
X
b
,
Y
b
), (
X
2
,
Y
2
)-(
X
0
,
Y
0
)-(
X
c
,
Y
c
) and (
X
0
,
Y
0
)-(
X
1
,
Y
1
)-(
X
2
,
Y
2
) do not overlap each other (in the XY-plane), and can be assembled as a triangular pyramid of positive (non-zero) height, output the minimum height among such pyramids. Otherwise, output -1.
You may assume that the height is, if positive (non-zero), not less than 0.00001. The output should not contain an error greater than 0.00001.
Sample Input
0 0 1 0 0 1
0 0 5 0 2 5
-100 -100 100 -100 0 100
-72 -72 72 -72 0 72
0 0 0 0 0 0
Output for the Sample Input
2
1.49666
-1
8.52936

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,t) for(int i=s;i<t;i++)

ll sqrtz(ll x){
    if(x<0)return -201;
    ll z=sqrt(x)+2;
    while(z*z>x){
        z--;
    }
    return z;
}
bool is_sq(ll x){
    ll z=sqrtz(x);
    return (z*z==x);
}

using Point=array<ll,2>;

ll cross(Point a, Point b) {
  return a[0] * b[1] - a[1] * b[0];
}

int ccw(Point a, Point b, Point c) {
  Point p = {b[0] - a[0],b[1]-a[1]};
  Point q = {c[0] - a[0],c[1]-a[1]};

  if(cross(p, q) > 0) return 1;
  if(cross(p, q) < 0) return -1;
  return 0;
}

using Real = double;
using Pointd = complex<Real>;
Real eps = 1e-6;

int Round(Real x) { return static_cast<int>(round(x)); }

bool equal(Pointd a, Pointd b) { return abs(a - b) < eps; }

struct Line {
  Pointd a, b;
  Line() = default;
  Line(Pointd a, Pointd b) : a(a), b(b) {}
};

using Segment = Line;

Real norm(Pointd p) { return pow(p.real(), 2) + pow(p.imag(), 2); }

Real dot(Pointd a, Pointd b) { return a.real() * b.real() + a.imag() * b.imag(); }
Real crossd(Pointd a, Pointd b) {
  return a.real() * b.imag() - a.imag() * b.real();
}

Pointd projection(Line L, Pointd p) {
  Real t = dot(p - L.a, L.a - L.b) / norm(L.a - L.b);
  return L.a + (L.a - L.b) * t;
}

Pointd crossPoint(Line s, Line t) {
  Real d1 = crossd(s.b - s.a, t.b - t.a);
  Real d2 = crossd(s.b - s.a, s.b - t.a);
  if(equal(abs(d1), 0.0) && equal(abs(d2), 0.0)) return t.a;
  return t.a + (t.b - t.a) * (d2 / d1);
}

double height(array<Point,3> V,array<Point,3> U){
    array<Pointd,3> Vd,Ud;
    rep(i,3)Vd[i]=Pointd(V[i][0],V[i][1]); 
    rep(i,3)Ud[i]=Pointd(U[i][0],U[i][1]);
    array<Line,3> L,LD;
    rep(i,3)L[i]=Line(Vd[i],Vd[(i+1)%3]);
    rep(i,3)LD[i]=Line(Ud[i],projection(L[i],Ud[i]));
    
    array<Pointd,3> PD={
        crossPoint(LD[0],LD[1]),
        crossPoint(LD[1],LD[2]),
        crossPoint(LD[2],LD[0])
    };

    if((equal(PD[0],PD[1])&&equal(PD[1],PD[2])&&equal(PD[2],PD[0]))){
        
        array<Real,3> D={
            norm(PD[0]-Vd[0]),
            norm(PD[0]-Vd[1]),
            norm(PD[0]-Vd[2])
        };
        array<Real,3> E={
            norm(Ud[0]-Vd[0]),
            norm(Ud[1]-Vd[1]),
            norm(Ud[2]-Vd[2])
        };
        array<Real,3> H;
        rep(k,3){
            if(D[k]>E[k]-(1e-12))return -1;
            H[k]=sqrt(E[k]-D[k]);
        }
        if(abs(H[0]-H[1])>1e-6||abs(H[2]-H[1])>1e-6)return -1;
        if(H[0]<1e-4)return -1;
        return H[0];
    }
    else{
        return -1;
    }
}

double solve(array<Point,3> V){
    
    ll cnt=0;
    double an=1e18;
    ll NM=100;
    for(ll x=-NM;x<=NM;x++){
        for(ll y=-NM;y<=NM;y++){
            ll dx=x-V[1][0];
            ll dy=y-V[1][1];
            ll rr=dx*dx+dy*dy;
            if(ccw({x,y},V[1],V[0])<=0)continue;
            for(ll a=-NM;a<=NM;a++){
                ll da=a-V[1][0];
                if(!is_sq(rr-da*da))continue;
                ll db=sqrtz(rr-da*da);
                for(ll b:{V[1][1]-db,V[1][1]+db}){
                    if(b<-NM||b>NM)continue;
                    if(ccw({a,b},V[2],V[1])<=0)continue;

                    ll ss=(a-V[2][0])*(a-V[2][0])+(b-V[2][1])*(b-V[2][1]);
                    ll tt=(x-V[0][0])*(x-V[0][0])+(y-V[0][1])*(y-V[0][1]);
                    
                    ll dvx=2*(V[2][0]-V[0][0]);
                    ll dvy=2*(V[2][1]-V[0][1]);

                    ll dvd=tt-ss-V[0][0]*V[0][0]+V[2][0]*V[2][0]-V[0][1]*V[0][1]+V[2][1]*V[2][1];
                    dvd*=-1;
                    ll D=abs(dvx*V[0][0]+dvy*V[0][1]+dvd);
                    ll nm=dvx*dvx+dvy*dvy;
                    if(is_sq(nm*tt-D*D)){
                        ll u=sqrtz(nm*tt-D*D);

                        ll px=-dvy*u;
                        ll py=dvx*u;
                        rep(_,2){
                            px*=-1;
                            py*=-1;
                            if((dvx*D+px)%nm==0&&(dvy*D+py)%nm==0){
                                ll p=(dvx*D+px)/nm+V[0][0];
                                ll q=(dvy*D+py)/nm+V[0][1];
                                if(ccw({p,q},V[0],V[2])<=0)continue;
                                if(p<-NM||p>NM||q<-NM||q>NM)continue;
                                
                                double res=height(V,{Point({x,y}),Point({a,b}),Point({p,q})});
                                if(res<0.0)continue;
                                if(res>eps)an=min(an,res);
                            }
                        }
                    }
                }
            }
        }
    }
    return an;
}

void solsol(array<Point,3> V){
    double an=1e18;
    rep(i,3){
        V={V[1],V[2],V[0]};
        an=min(an,solve(V));   
    }
    if(an>1e17)cout<<-1<<endl;
    else cout<<an<<endl;
}

int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    std::cout<<fixed<<setprecision(7);
    array<Point,3> V;
    while(cin>>V[0][0]>>V[0][1]>>V[1][0]>>V[1][1]>>V[2][0]>>V[2][1],(V[0]!=V[1]))solsol(V);
}
accuracy: 1
time_ms: 4680
memory_kb: 3492
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,t) for(int i=s;i<t;i++)

ll sqrtz(ll x){
    if(x<0)return -201;
    ll z=sqrt(x)+2;
    while(z*z>x){
        z--;
    }
    return z;
}
bool is_sq(ll x){
    ll z=sqrtz(x);
    return (z*z==x);
}

using Point=array<ll,2>;

ll cross(Point a, Point b) {
  return a[0] * b[1] - a[1] * b[0];
}

int ccw(Point a, Point b, Point c) {
  Point p = {b[0] - a[0],b[1]-a[1]};
  Point q = {c[0] - a[0],c[1]-a[1]};

  if(cross(p, q) > 0) return 1;
  if(cross(p, q) < 0) return -1;
  return 0;
}






/*
- `Point p(x, y)` で座標/ベクトルを宣言できる
- `cout << fixed << setprecision(10);` で小数出力の桁数を指定できる
*/
using Real = double;
using Pointd = complex<Real>;
using Poly = vector<Pointd>;
Real eps = 1e-6;

int Round(Real x) { return static_cast<int>(round(x)); }

// 同じか判定
bool equal(Pointd a, Pointd b) { return abs(a - b) < eps; }

struct Line {
  // 点 a, b を通る直線
  Pointd a, b;
  Line() = default;
  Line(Pointd a, Pointd b) : a(a), b(b) {}
  Line(Real A, Real B, Real C) {
    // 直線の方程式 Ax + By = C;
    if(equal(A, 0)) a = Pointd(0, C / B), b = Pointd(1, C / B);
    else if(equal(B, 0)) a = Pointd(C / A, 0), b = Pointd(C / A, 1);
    else a = Pointd(0, C / B), b = Pointd(C / A, 0);
  }
};

using Segment = Line;

Real norm(Pointd p) { return pow(p.real(), 2) + pow(p.imag(), 2); }
// 単位ベクトル
Pointd unitVector(Pointd p) { return p / abs(p); }
// 内積(dot product): a・b=|a||b|cosΘ
Real dot(Pointd a, Pointd b) { return a.real() * b.real() + a.imag() * b.imag(); }
// 外積(cross product): a×b=|a||b|sinΘ
Real crossd(Pointd a, Pointd b) {
  return a.real() * b.imag() - a.imag() * b.real();
}

// 射影(projection): 直線 L に点 p から引いた垂線の足を求める
Pointd projection(Line L, Pointd p) {
  Real t = dot(p - L.a, L.a - L.b) / norm(L.a - L.b);
  return L.a + (L.a - L.b) * t;
}

// 2 直線の交点
Pointd crossPoint(Line s, Line t) {
  Real d1 = crossd(s.b - s.a, t.b - t.a);
  Real d2 = crossd(s.b - s.a, s.b - t.a);
  if(equal(abs(d1), 0.0) && equal(abs(d2), 0.0)) return t.a;
  return t.a + (t.b - t.a) * (d2 / d1);
}



double height(array<Point,3> V,array<Point,3> U){
    array<Pointd,3> Vd,Ud;
    rep(i,3)Vd[i]=Pointd(V[i][0],V[i][1]); 
    rep(i,3)Ud[i]=Pointd(U[i][0],U[i][1]); 
    array<Line,3> L={
        Line(Vd[0],Vd[1]),
        Line(Vd[1],Vd[2]),
        Line(Vd[2],Vd[0])
    };

    array<Line,3> LD={
        Line(Ud[0],projection(L[0],Ud[0])),
        Line(Ud[1],projection(L[1],Ud[1])),
        Line(Ud[2],projection(L[2],Ud[2]))
    };

    array<Pointd,3> PD={
        crossPoint(LD[0],LD[1]),
        crossPoint(LD[1],LD[2]),
        crossPoint(LD[2],LD[0])
    };

    if((equal(PD[0],PD[1])&&equal(PD[1],PD[2])&&equal(PD[2],PD[0]))){
        
        array<Real,3> D={
            norm(PD[0]-Vd[0]),
            norm(PD[0]-Vd[1]),
            norm(PD[0]-Vd[2])
        };
        array<Real,3> E={
            norm(Ud[0]-Vd[0]),
            norm(Ud[1]-Vd[1]),
            norm(Ud[2]-Vd[2])
        };
        array<Real,3> H;
        rep(k,3){
            if(D[k]>E[k]-(1e-12))return -1;
            H[k]=sqrt(E[k]-D[k]);
        }
        if(abs(H[0]-H[1])>1e-6||abs(H[2]-H[1])>1e-6)return -1;
        if(H[0]<1e-4)return -1;
        return H[0];
    }
    else{
        return -1;
    }
}

double solve(array<Point,3> V){
    
    
    ll cnt=0;
    double an=1e18;
    ll NM=100;
    for(ll x=-NM;x<=NM;x++){
        for(ll y=-NM;y<=NM;y++){
            ll dx=x-V[1][0];
            ll dy=y-V[1][1];
            ll rr=dx*dx+dy*dy;
            if(ccw({x,y},V[1],V[0])<=0)continue;
            for(ll a=-NM;a<=NM;a++){
                ll da=a-V[1][0];
                if(!is_sq(rr-da*da))continue;
                ll db=sqrtz(rr-da*da);
                for(ll b:{V[1][1]-db,V[1][1]+db}){
                    if(b<-NM||b>NM)continue;
                    if(ccw({a,b},V[2],V[1])<=0)continue;

                    ll ss=(a-V[2][0])*(a-V[2][0])+(b-V[2][1])*(b-V[2][1]);
                    ll tt=(x-V[0][0])*(x-V[0][0])+(y-V[0][1])*(y-V[0][1]);
                    
                    ll dvx=2*(V[2][0]-V[0][0]);
                    ll dvy=2*(V[2][1]-V[0][1]);

                    ll dvd=tt-ss-V[0][0]*V[0][0]+V[2][0]*V[2][0]-V[0][1]*V[0][1]+V[2][1]*V[2][1];
                    dvd*=-1;
                    //p*dvx+q*dvy-dvd=0;

                    ll D=abs(dvx*V[0][0]+dvy*V[0][1]+dvd);
                    ll nm=dvx*dvx+dvy*dvy;
                    if(is_sq(nm*tt-D*D)){
                        ll u=sqrtz(nm*tt-D*D);

                        ll px=-dvy*u;
                        ll py=dvx*u;
                        rep(_,2){
                            px*=-1;
                            py*=-1;
                            if((dvx*D+px)%nm==0&&(dvy*D+py)%nm==0){
                                ll p=(dvx*D+px)/nm+V[0][0];
                                ll q=(dvy*D+py)/nm+V[0][1];
                                if(ccw({p,q},V[0],V[2])<=0)continue;
                                if(p<-NM||p>NM||q<-NM||q>NM)continue;
                                
                                double res=height(V,{Point({x,y}),Point({a,b}),Point({p,q})});
                                if(res<0.0)continue;
                                if(res>eps)an=min(an,res);
                                
                                
                                // std::cout<<x<<" "<<y<<" "<<a<<" "<<b<<" "<<p<<" "<<q<<" "<<res<<endl;
                                // return;
                                cnt++;
                            }
                        }

                        // cnt++;
                    }
                }
            }
        }
    }
    return an;
}

void solsol(array<Point,3> V){
    double an=1e18;
    rep(i,3){
        V={V[1],V[2],V[0]};
        an=min(an,solve(V));   
    }
    if(an>1e17)cout<<-1<<endl;
    else cout<<an<<endl;
}

int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    std::cout<<fixed<<setprecision(7);
    array<Point,3> V;
    while(cin>>V[0][0]>>V[0][1]>>V[1][0]>>V[1][1]>>V[2][0]>>V[2][1],(V[0]!=V[1]))solsol(V);
}
accuracy: 1
time_ms: 4590
memory_kb: 3596
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
const LD INF = 1e18;
const LD eps = 1e-10;

inline int sgn(LD x) {
    return x > eps? 1 : x < -eps? -1 : 0;
}

struct Point {
    LD x, y;
    Point(LD _x = 0, LD _y = 0): x(_x), y(_y) {}
    bool operator == (const Point &rhs) const {
        return sgn(x - rhs.x) == 0 && sgn(y - rhs.y) == 0;
    }
    Point operator + (const Point &rhs) const {
        return Point(x + rhs.x, y + rhs.y);
    }
    Point operator - (const Point &rhs) const {
        return Point(x - rhs.x, y - rhs.y);
    }
    Point operator * (const LD &rhs) const {
        return Point(x * rhs, y * rhs);
    }
    Point operator / (const LD &rhs) const {
        return Point(x / rhs, y / rhs);
    }
    LD operator * (const Point &rhs) const {
        return x * rhs.x + y * rhs.y;
    }
    LD operator ^ (const Point &rhs) const {
        return x * rhs.y - y * rhs.x;
    }
    LD len2() {
        return x * x + y * y;
    }
    LD len() {
        return sqrtl(len2());
    }
    Point unit() {
        return (*this) / len();
    }
} A, B, C;
vector<Point> vec[80005];
vector<int> valid;

inline Point Proj(Point p, Point u, Point v) {
    Point dir = (v - u).unit();
    return u + dir * (dir * (p - u));
}

Point LineInter(Point u1, Point v1, Point u2, Point v2) {
    LD a1 = (v2 - u2) ^ (u1 - u2), a2 = (v2 - u2) ^ (v1 - u2);
    return (u1 * a2 - v1 * a1) / (a2 - a1);
}

inline bool In(Point p) {
    return (abs(p.x) <= 100 && abs(p.y) <= 100);
}

inline bool Intri(Point p, Point a, Point b, Point c) {
    return sgn((b - a) ^ (p - a)) > 0
        && sgn((c - b) ^ (p - b)) > 0
        && sgn((a - c) ^ (p - c)) > 0;
}

LD Try(Point D, Point E) {
    if (!In(D)) return INF;
    if (sgn((B - A) ^ (D - A)) >= 0) return INF;
    if (!In(E)) return INF;
    if (sgn((C - A) ^ (E - A)) <= 0) return INF;
    Point Dp = Proj(D, A, B), Ep = Proj(E, A, C);
    Point Tp = LineInter(D, Dp, E, Ep);
    if (sgn((Tp - Dp).len2() - (D - Dp).len2()) >= 0) return INF;
    if (sgn((Tp - Ep).len2() - (E - Ep).len2()) >= 0) return INF;
    LD h = sqrt((D - A).len2() - (Tp - A).len2());
    for (auto e : vec[(int)(D - B).len2()]) {
        Point F = B + e;
        for (auto f : vec[(int)(E - C).len2()]) {
            if (C + f == F) {
                if (In(F) && sgn((B - C) ^ (F - C)) > 0  && !Intri(F, A, D, B) && !Intri(F, A, C, E)) {
                    return h;
                }
            }
        }
    }
    return INF;
}

void prework() {
    for (int i = 0; i <= 200; ++i) {
        for (int j = 0; j <= 200; ++j) {
            int l2 = i * i + j * j;
            vec[l2].push_back(Point(i, j));
            if (i != 0) {
                vec[l2].push_back(Point(-i, j));
            }
            if (j != 0) {
                vec[l2].push_back(Point(i, -j));
            }
            if (i != 0 && j != 0) {
                vec[l2].push_back(Point(-i, -j));
            }
        }
    }
    for (int i = 0; i <= 80000; ++i) {
        if (vec[i].size()) {
            valid.push_back(i);
        }
    }
}

void solve() {
    LD ans = INF;
    for (auto l2 : valid) {
        for (auto a : vec[l2]) {
            for (auto b : vec[l2]) {
                ans = min(ans, Try(A + a, A + b));
            }
        }
    }
    if (ans > 1e17) {
        puts("-1");
    } else {
        printf("%.10Lf\n", ans);
    }
}

int main() {
    prework();
    int a, b, c, d, e, f;
    while (scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f)) {
        if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0 && f == 0) {
            break;
        }
        A = Point(a, b);
        B = Point(c, d);
        C = Point(e, f);
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 4220
memory_kb: 11160
final_rank: 20

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define MAX 80005
#define SIZE 3

struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}


	void debug(){

		printf("(%.3lf,%.3lf)\n",x,y);
	}

	double x,y;
};

typedef Point Vector;
typedef vector<Point> Polygon;

double calc_dist(Point A,Point B){

	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
struct Line{
	Line(){

	}
	Line(Point a,Point b){
		p[0] = a;
		p[1] = b;
	}
	/*void outPut(){

		printf("(%.3lf,%.3lf)-(%.3lf,%.3lf)\n",p[0].x,p[0].y,p[1].x,p[1].y);
	}*/
	Point p[2];
};

struct LOC{
	LOC(){

		int_x = int_y = 0;
	}
	LOC(int arg_int_x,int arg_int_y){
		int_x = arg_int_x;
		int_y = arg_int_y;
	}
	int int_x,int_y;
};

LOC base_loc[SIZE];
Point base_point[3],p_A,p_B,p_C;
vector<LOC> V[SIZE][MAX];

double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0,Point p1,Point p2){

	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
	if(cross(a,b) < -EPS)return CLOCKWISE;
	if(dot(a,b) < -EPS)return ONLINE_BACK;
	if(a.norm() < b.norm())return ONLINE_FRONT;

	return ON_SEGMENT;
}


int func(double x1,double y1,double x2, double y2, double xp, double yp){
	double naiseki,norm1,norm2,gaiseki;
	norm1 = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	norm2 = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
	naiseki = (xp-x1)*(x2-x1)+(yp-y1)*(y2-y1);
	gaiseki = (x2-x1)*(yp-y1)-(xp-x1)*(y2-y1);
	if(gaiseki > EPS){
		return 1;
	}else if(gaiseki < -EPS){
		return -1;
	}
	if(naiseki < -EPS){
		return 2;
	}

	if(norm1 < norm2){
		return -2;
	}
	return 0;
}


//★★直線ではなく、線分の交差判定★★
bool is_Cross(Line a,Line b){

	if(func(a.p[0].x,a.p[0].y,a.p[1].x,a.p[1].y,b.p[0].x,b.p[0].y)*
			func(a.p[0].x,a.p[0].y,a.p[1].x,a.p[1].y,b.p[1].x,b.p[1].y) <= 0 &&
			func(b.p[0].x,b.p[0].y,b.p[1].x,b.p[1].y,a.p[0].x,a.p[0].y)*
			func(b.p[0].x,b.p[0].y,b.p[1].x,b.p[1].y,a.p[1].x,a.p[1].y) <= 0){
		return true;
	}
	return false;
}


Point calc_minus(Point a,Point b){
    Point ret;

    ret.x = a.x-b.x;
    ret.y = a.y-b.y;

    return ret;
}

double calc_len(Vector a){
    return sqrt(a.x*a.x+a.y*a.y);
}

//線分ではなく直線と点の距離
double getDistanceLP(Line l,Point p){
    return fabs(cross(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0]))/calc_len(calc_minus(l.p[1],l.p[0])));
}

//点と線分の距離
double getDistanceSP(Line l,Point p){
	if(dot(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0])) < 0.0)return calc_len(calc_minus(p,l.p[0]));
	if(dot(calc_minus(l.p[0],l.p[1]),calc_minus(p,l.p[1])) < 0.0)return calc_len(calc_minus(p,l.p[1]));
	return getDistanceLP(l,p);
}

//線分と線分の距離
double getDistance(Line A,Line B){
	if(is_Cross(A,B))return 0.0;
	return min(min(getDistanceSP(A,B.p[0]),getDistanceSP(A,B.p[1])),
			min(getDistanceSP(B,A.p[0]),getDistanceSP(B,A.p[1])));
}


//交点を求める関数
Point calc_Cross_Point(double x1,double x2,double x3,double x4,double y1,double y2,double y3,double y4){
	Point ret;
	ret.x = ((x2-x1)*(y3*(x4-x3)+x3*(y3-y4))-(x4-x3)*(y1*(x2-x1)+x1*(y1-y2)))/((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1));
	if(fabs(x1-x2) > EPS){
		ret.y = ((y2-y1)*ret.x+y1*(x2-x1)+x1*(y1-y2))/(x2-x1);
	}else{
		ret.y = ((y4-y3)*ret.x+y3*(x4-x3)+x3*(y3-y4))/(x4-x3);
	}
	return ret;
}

//インタフェース関数
Point calc_Cross_Point(Point a,Point b,Point c,Point d){
	return calc_Cross_Point(a.x,b.x,c.x,d.x,a.y,b.y,c.y,d.y);
}


Point calc_Cross_Point(Line A,Line B){

	if(getDistanceSP(B,A.p[0]) < EPS){

		return A.p[0];

	}else if(getDistanceSP(B,A.p[1]) < EPS){

		return A.p[1];

	}else if(getDistanceSP(A,B.p[0]) < EPS){

		return B.p[0];

	}else if(getDistanceSP(A,B.p[1]) < EPS){

		return B.p[1];
	}

	return calc_Cross_Point(A.p[0],A.p[1],B.p[0],B.p[1]);
}


Point project(Line l,Point p){

	Vector base = l.p[1]-l.p[0];
	double r = dot(p-l.p[0],base)/norm(base);
	return l.p[0]+base*r;
}

double calc_slope(Line A){

	if(fabs(A.p[0].x-A.p[1].x) < EPS){

		return DBL_MAX;

	}else if(fabs(A.p[0].y-A.p[1].y) < EPS){

		return 0;

	}else{

		return (A.p[1].y-A.p[0].y)/(A.p[1].x-A.p[0].x);
	}
}

//2つのvectorがなすラジアンを求める関数
double calc_rad(Vector vec1,Vector vec2){

	double tmp = dot(vec1,vec2)/(abs(vec1)*abs(vec2));

	if(fabs(tmp+1.0) < EPS){

		return M_PI;
	}

	if(fabs(tmp-1.0) < EPS){

		return  0.0;
	}

	return acos(dot(vec1,vec2)/(abs(vec1)*abs(vec2)));
}

Point calc_Reflection_Point(double x1,double y1,double x2,double y2,double xp,double yp){

	Point ret;

	bool X_FLG = false,Y_FLG = false;
	double slope;

	if(y1 == y2){
		X_FLG = true;
	}else if(x1 == x2){
		Y_FLG = true;
	}else{
		slope = (y2-y1)/(x2-x1);
	}

	if(X_FLG){
		ret.x = xp,ret.y=y1;
	}else if(Y_FLG){
		ret.x = x1,ret.y = yp;
	}else{
		ret.x = (yp*(x2-x1)*(y2-y1)+xp*(x2-x1)*(x2-x1)-y1*(y2-y1)*(x2-x1)+x1*(y2-y1)*(y2-y1))/((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
		ret.y = ((x1-x2)*ret.x+yp*(y2-y1)+xp*(x2-x1))/(y2-y1);
	}
	ret.x = 2*ret.x-xp;
	ret.y = 2*ret.y-yp;

	return ret;
}

Point calc_Reflection_Point(Line line,Point point){

	return calc_Reflection_Point(line.p[0].x,line.p[0].y,line.p[1].x,line.p[1].y,point.x,point.y);
}



void func(){

	for(int i = 0; i < MAX; i++){
		V[1][i].clear();
		V[2][i].clear();
	}

	Line line_01,line_12,line_20;

	line_01.p[0] = base_point[0];
	line_01.p[1] = base_point[1];

	line_12.p[0] = base_point[1];
	line_12.p[1] = base_point[2];

	line_20.p[0] = base_point[2];
	line_20.p[1] = base_point[0];


	//点1,点2から、範囲内の格子点の距離を求めておく
	for(int i = 1; i <= 2; i++){
		for(int X = -100; X <= 100; X++){
			for(int Y = -100; Y <= 100; Y++){
				Point tmp_p = Point(X,Y);

				double tmp_rad;

				if(i == 1){
					if(ccw(base_point[1],tmp_p,base_point[2]) != COUNTER_CLOCKWISE){
						continue;
					}

					tmp_rad = calc_rad(tmp_p-base_point[1],base_point[2]-base_point[1]);

				}else{
					if(ccw(base_point[2],tmp_p,base_point[0]) != COUNTER_CLOCKWISE){
						continue;
					}
					tmp_rad = calc_rad(tmp_p-base_point[2],base_point[0]-base_point[2]);
				}

				if(fabs(tmp_rad-M_PI) < EPS || fabs(tmp_rad) < EPS)continue;//面積0は不可

				int tmp_index = (base_loc[i].int_x-X)*(base_loc[i].int_x-X)+(base_loc[i].int_y-Y)*(base_loc[i].int_y-Y);

				V[i][tmp_index].push_back(LOC(X,Y));
			}
		}
	}

	double ans = BIG_NUM;

	int len_0A,len_1A,len_2B,len_0C;

	Line proj_A,proj_B,proj_C;
	Line line_0A,line_1A,line_1B,line_2B,line_2C,line_0C;
	Point cross_AB,cross_BC,cross_CA;

	line_0A.p[0] = base_point[0];
	line_1A.p[0] = base_point[1];
	line_1B.p[0] = base_point[1];
	line_2B.p[0] = base_point[2];
	line_2C.p[0] = base_point[2];
	line_0C.p[0] = base_point[0];

	for(int a_x = -100; a_x <= 100; a_x++){
		for(int a_y = -100; a_y <= 100; a_y++){

			p_A = Point(a_x,a_y);
			if(ccw(base_point[0],p_A,base_point[1]) != COUNTER_CLOCKWISE){
				continue;
			}
			double tmp_rad = calc_rad(p_A-base_point[0],base_point[1]-base_point[0]);
			if(fabs(tmp_rad-M_PI) < EPS || fabs(tmp_rad) < EPS)continue; //面積0は不可

			len_0A = (base_loc[0].int_x-a_x)*(base_loc[0].int_x-a_x)+(base_loc[0].int_y-a_y)*(base_loc[0].int_y-a_y);
			len_1A = (base_loc[1].int_x-a_x)*(base_loc[1].int_x-a_x)+(base_loc[1].int_y-a_y)*(base_loc[1].int_y-a_y);

			proj_A.p[0] = p_A;
			proj_A.p[1] = calc_Reflection_Point(line_01,p_A);

			line_0A.p[1] = p_A;
			line_1A.p[1] = p_A;

			//点Bの検索
			for(int i = 0; i < V[1][len_1A].size(); i++){

				int b_x = V[1][len_1A][i].int_x;
				int b_y = V[1][len_1A][i].int_y;

				len_2B = (base_loc[2].int_x-b_x)*(base_loc[2].int_x-b_x)+(base_loc[2].int_y-b_y)*(base_loc[2].int_y-b_y);

				p_B = Point(b_x,b_y);
				if(p_B == p_A)continue;

				proj_B.p[0] = p_B;
				proj_B.p[1] = calc_Reflection_Point(line_12,p_B);

				if(!is_Cross(proj_A,proj_B))continue;

				cross_AB = calc_Cross_Point(proj_A,proj_B);

				line_1B.p[1] = p_B;
				line_2B.p[1] = p_B;

				if(is_Cross(line_0A,line_1B))continue;
				if(is_Cross(line_0A,line_2B))continue;
				if(is_Cross(line_1A,line_2B))continue;

				//点Cの検索
				for(int k = 0; k < V[2][len_2B].size(); k++){

					int c_x = V[2][len_2B][k].int_x;
					int c_y = V[2][len_2B][k].int_y;

					len_0C = (base_loc[0].int_x-c_x)*(base_loc[0].int_x-c_x)+(base_loc[0].int_y-c_y)*(base_loc[0].int_y-c_y);
					if(len_0C != len_0A)continue;

					p_C = Point(c_x,c_y);
					if(p_C == p_A || p_C == p_B)continue;

					proj_C.p[0] = p_C;
					proj_C.p[1] = calc_Reflection_Point(line_20,p_C);

					if(!is_Cross(proj_A,proj_C)||!is_Cross(proj_B,proj_C))continue;

					line_2C.p[1] = p_C;
					line_0C.p[1] = p_C;

					if(is_Cross(line_0A,line_2C))continue;
					if(is_Cross(line_1A,line_2C))continue;
					if(is_Cross(line_1A,line_0C))continue;
					if(is_Cross(line_1B,line_2C))continue;
					if(is_Cross(line_1B,line_0C))continue;
					if(is_Cross(line_2B,line_0C))continue;

					cross_BC = calc_Cross_Point(proj_B,proj_C);
					cross_CA = calc_Cross_Point(proj_C,proj_A);

					if(cross_AB == cross_BC && cross_AB == cross_CA){

						if((cross_AB == p_A)||(cross_AB == p_B)||(cross_AB==p_C))continue;

						//面が底面の三角形に張り付く(高さ0)場合は不可
						if(fabs(getDistanceLP(line_01,p_A)-getDistanceLP(line_01,cross_AB)) < EPS)continue;
						if(fabs(getDistanceLP(line_12,p_B)-getDistanceLP(line_12,cross_AB)) < EPS)continue;
						if(fabs(getDistanceLP(line_20,p_C)-getDistanceLP(line_20,cross_AB)) < EPS)continue;


						double tmp_len = len_0A;
						double tmp_dist = norm(base_point[0]-cross_AB);

						ans = min(ans,sqrt(tmp_len-tmp_dist));
					}
				}
			}
		}
	}

	if(fabs(ans-BIG_NUM) < EPS){

		printf("-1\n");
	}else{

		printf("%.10lf\n",ans);
	}
}

int main(){

	bool FLG;

	while(true){

		FLG = false;

		for(int i = 0; i < 3; i++){

			scanf("%d %d",&base_loc[i].int_x,&base_loc[i].int_y);

			base_point[i].x = base_loc[i].int_x;
			base_point[i].y = base_loc[i].int_y;

			if(base_loc[i].int_x != 0 || base_loc[i].int_y != 0){

				FLG = true;
			}
		}
		if(!FLG)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 580
memory_kb: 10496
final_rank: 13

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define MAX 80005
#define SIZE 3

struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}


	void debug(){

		printf("(%.3lf,%.3lf)\n",x,y);
	}

	double x,y;
};

typedef Point Vector;
typedef vector<Point> Polygon;

double calc_dist(Point A,Point B){

	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
struct Line{
	Line(){

	}
	Line(Point a,Point b){
		p[0] = a;
		p[1] = b;
	}
	/*void outPut(){

		printf("(%.3lf,%.3lf)-(%.3lf,%.3lf)\n",p[0].x,p[0].y,p[1].x,p[1].y);
	}*/
	Point p[2];
};

struct LOC{
	LOC(){

		int_x = int_y = 0;
	}
	LOC(int arg_int_x,int arg_int_y){
		int_x = arg_int_x;
		int_y = arg_int_y;
	}
	int int_x,int_y;
};

LOC base_loc[SIZE];
Point base_point[3],p_A,p_B,p_C;
vector<LOC> V[SIZE][MAX];

double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0,Point p1,Point p2){

	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
	if(cross(a,b) < -EPS)return CLOCKWISE;
	if(dot(a,b) < -EPS)return ONLINE_BACK;
	if(a.norm() < b.norm())return ONLINE_FRONT;

	return ON_SEGMENT;
}


int func(double x1,double y1,double x2, double y2, double xp, double yp){
	double naiseki,norm1,norm2,gaiseki;
	norm1 = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	norm2 = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
	naiseki = (xp-x1)*(x2-x1)+(yp-y1)*(y2-y1);
	gaiseki = (x2-x1)*(yp-y1)-(xp-x1)*(y2-y1);
	if(gaiseki > EPS){
		return 1;
	}else if(gaiseki < -EPS){
		return -1;
	}
	if(naiseki < -EPS){
		return 2;
	}

	if(norm1 < norm2){
		return -2;
	}
	return 0;
}


//★★直線ではなく、線分の交差判定★★
bool is_Cross(Line a,Line b){

	if(func(a.p[0].x,a.p[0].y,a.p[1].x,a.p[1].y,b.p[0].x,b.p[0].y)*
			func(a.p[0].x,a.p[0].y,a.p[1].x,a.p[1].y,b.p[1].x,b.p[1].y) <= 0 &&
			func(b.p[0].x,b.p[0].y,b.p[1].x,b.p[1].y,a.p[0].x,a.p[0].y)*
			func(b.p[0].x,b.p[0].y,b.p[1].x,b.p[1].y,a.p[1].x,a.p[1].y) <= 0){
		return true;
	}
	return false;
}


Point calc_minus(Point a,Point b){
    Point ret;

    ret.x = a.x-b.x;
    ret.y = a.y-b.y;

    return ret;
}

double calc_len(Vector a){
    return sqrt(a.x*a.x+a.y*a.y);
}

//線分ではなく直線と点の距離
double getDistanceLP(Line l,Point p){
    return fabs(cross(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0]))/calc_len(calc_minus(l.p[1],l.p[0])));
}

//点と線分の距離
double getDistanceSP(Line l,Point p){
	if(dot(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0])) < 0.0)return calc_len(calc_minus(p,l.p[0]));
	if(dot(calc_minus(l.p[0],l.p[1]),calc_minus(p,l.p[1])) < 0.0)return calc_len(calc_minus(p,l.p[1]));
	return getDistanceLP(l,p);
}

//線分と線分の距離
double getDistance(Line A,Line B){
	if(is_Cross(A,B))return 0.0;
	return min(min(getDistanceSP(A,B.p[0]),getDistanceSP(A,B.p[1])),
			min(getDistanceSP(B,A.p[0]),getDistanceSP(B,A.p[1])));
}


//交点を求める関数
Point calc_Cross_Point(double x1,double x2,double x3,double x4,double y1,double y2,double y3,double y4){
	Point ret;
	ret.x = ((x2-x1)*(y3*(x4-x3)+x3*(y3-y4))-(x4-x3)*(y1*(x2-x1)+x1*(y1-y2)))/((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1));
	if(fabs(x1-x2) > EPS){
		ret.y = ((y2-y1)*ret.x+y1*(x2-x1)+x1*(y1-y2))/(x2-x1);
	}else{
		ret.y = ((y4-y3)*ret.x+y3*(x4-x3)+x3*(y3-y4))/(x4-x3);
	}
	return ret;
}

//インタフェース関数
Point calc_Cross_Point(Point a,Point b,Point c,Point d){
	return calc_Cross_Point(a.x,b.x,c.x,d.x,a.y,b.y,c.y,d.y);
}


Point calc_Cross_Point(Line A,Line B){

	if(getDistanceSP(B,A.p[0]) < EPS){

		return A.p[0];

	}else if(getDistanceSP(B,A.p[1]) < EPS){

		return A.p[1];

	}else if(getDistanceSP(A,B.p[0]) < EPS){

		return B.p[0];

	}else if(getDistanceSP(A,B.p[1]) < EPS){

		return B.p[1];
	}

	return calc_Cross_Point(A.p[0],A.p[1],B.p[0],B.p[1]);
}


Point project(Line l,Point p){

	Vector base = l.p[1]-l.p[0];
	double r = dot(p-l.p[0],base)/norm(base);
	return l.p[0]+base*r;
}

double calc_slope(Line A){

	if(fabs(A.p[0].x-A.p[1].x) < EPS){

		return DBL_MAX;

	}else if(fabs(A.p[0].y-A.p[1].y) < EPS){

		return 0;

	}else{

		return (A.p[1].y-A.p[0].y)/(A.p[1].x-A.p[0].x);
	}
}

//2つのvectorがなすラジアンを求める関数
double calc_rad(Vector vec1,Vector vec2){

	double tmp = dot(vec1,vec2)/(abs(vec1)*abs(vec2));

	if(fabs(tmp+1.0) < EPS){

		return M_PI;
	}

	if(fabs(tmp-1.0) < EPS){

		return  0.0;
	}

	return acos(dot(vec1,vec2)/(abs(vec1)*abs(vec2)));
}

Point calc_Reflection_Point(double x1,double y1,double x2,double y2,double xp,double yp){

	Point ret;

	bool X_FLG = false,Y_FLG = false;
	double slope;

	if(y1 == y2){
		X_FLG = true;
	}else if(x1 == x2){
		Y_FLG = true;
	}else{
		slope = (y2-y1)/(x2-x1);
	}

	if(X_FLG){
		ret.x = xp,ret.y=y1;
	}else if(Y_FLG){
		ret.x = x1,ret.y = yp;
	}else{
		ret.x = (yp*(x2-x1)*(y2-y1)+xp*(x2-x1)*(x2-x1)-y1*(y2-y1)*(x2-x1)+x1*(y2-y1)*(y2-y1))/((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
		ret.y = ((x1-x2)*ret.x+yp*(y2-y1)+xp*(x2-x1))/(y2-y1);
	}
	ret.x = 2*ret.x-xp;
	ret.y = 2*ret.y-yp;

	return ret;
}

Point calc_Reflection_Point(Line line,Point point){

	return calc_Reflection_Point(line.p[0].x,line.p[0].y,line.p[1].x,line.p[1].y,point.x,point.y);
}



void func(){

	for(int i = 0; i < MAX; i++){
		V[1][i].clear();
		V[2][i].clear();
	}

	Line line_01,line_12,line_20;

	line_01.p[0] = base_point[0];
	line_01.p[1] = base_point[1];

	line_12.p[0] = base_point[1];
	line_12.p[1] = base_point[2];

	line_20.p[0] = base_point[2];
	line_20.p[1] = base_point[0];


	//点1,点2から、範囲内の格子点の距離を求めておく
	for(int i = 1; i <= 2; i++){
		for(int X = -100; X <= 100; X++){
			for(int Y = -100; Y <= 100; Y++){
				Point tmp_p = Point(X,Y);

				double tmp_rad;

				if(i == 1){
					if(ccw(base_point[1],tmp_p,base_point[2]) != COUNTER_CLOCKWISE){
						continue;
					}

					tmp_rad = calc_rad(tmp_p-base_point[1],base_point[2]-base_point[1]);

				}else{
					if(ccw(base_point[2],tmp_p,base_point[0]) != COUNTER_CLOCKWISE){
						continue;
					}
					tmp_rad = calc_rad(tmp_p-base_point[2],base_point[0]-base_point[2]);
				}

				if(fabs(tmp_rad-M_PI) < EPS || fabs(tmp_rad) < EPS)continue;//面積0は不可

				int tmp_index = (base_loc[i].int_x-X)*(base_loc[i].int_x-X)+(base_loc[i].int_y-Y)*(base_loc[i].int_y-Y);

				V[i][tmp_index].push_back(LOC(X,Y));
			}
		}
	}

	double ans = BIG_NUM;

	int len_0A,len_1A,len_2B,len_0C;

	Line proj_A,proj_B,proj_C;
	Line line_0A,line_1A,line_1B,line_2B,line_2C,line_0C;
	Point cross_AB,cross_BC,cross_CA;

	line_0A.p[0] = base_point[0];
	line_1A.p[0] = base_point[1];
	line_1B.p[0] = base_point[1];
	line_2B.p[0] = base_point[2];
	line_2C.p[0] = base_point[2];
	line_0C.p[0] = base_point[0];

	for(int a_x = -100; a_x <= 100; a_x++){
		for(int a_y = -100; a_y <= 100; a_y++){

			p_A = Point(a_x,a_y);
			if(ccw(base_point[0],p_A,base_point[1]) != COUNTER_CLOCKWISE){
				continue;
			}
			double tmp_rad = calc_rad(p_A-base_point[0],base_point[1]-base_point[0]);
			if(fabs(tmp_rad-M_PI) < EPS || fabs(tmp_rad) < EPS)continue; //面積0は不可

			len_0A = (base_loc[0].int_x-a_x)*(base_loc[0].int_x-a_x)+(base_loc[0].int_y-a_y)*(base_loc[0].int_y-a_y);
			len_1A = (base_loc[1].int_x-a_x)*(base_loc[1].int_x-a_x)+(base_loc[1].int_y-a_y)*(base_loc[1].int_y-a_y);

			proj_A.p[0] = p_A;
			proj_A.p[1] = calc_Reflection_Point(line_01,p_A);

			line_0A.p[1] = p_A;
			line_1A.p[1] = p_A;

			//点Bの検索
			for(int i = 0; i < V[1][len_1A].size(); i++){

				int b_x = V[1][len_1A][i].int_x;
				int b_y = V[1][len_1A][i].int_y;

				len_2B = (base_loc[2].int_x-b_x)*(base_loc[2].int_x-b_x)+(base_loc[2].int_y-b_y)*(base_loc[2].int_y-b_y);

				p_B = Point(b_x,b_y);
				if(p_B == p_A)continue;

				proj_B.p[0] = p_B;
				proj_B.p[1] = calc_Reflection_Point(line_12,p_B);

				if(!is_Cross(proj_A,proj_B))continue;

				cross_AB = calc_Cross_Point(proj_A,proj_B);

				line_1B.p[1] = p_B;
				line_2B.p[1] = p_B;

				if(is_Cross(line_0A,line_1B))continue;
				if(is_Cross(line_0A,line_2B))continue;
				if(is_Cross(line_1A,line_2B))continue;

				//点Cの検索
				for(int k = 0; k < V[2][len_2B].size(); k++){

					int c_x = V[2][len_2B][k].int_x;
					int c_y = V[2][len_2B][k].int_y;

					len_0C = (base_loc[0].int_x-c_x)*(base_loc[0].int_x-c_x)+(base_loc[0].int_y-c_y)*(base_loc[0].int_y-c_y);
					if(len_0C != len_0A)continue;

					p_C = Point(c_x,c_y);
					if(p_C == p_A || p_C == p_B)continue;

					proj_C.p[0] = p_C;
					proj_C.p[1] = calc_Reflection_Point(line_20,p_C);

					if(!is_Cross(proj_A,proj_C)||!is_Cross(proj_B,proj_C))continue;

					line_2C.p[1] = p_C;
					line_0C.p[1] = p_C;

					if(is_Cross(line_0A,line_2C))continue;
					if(is_Cross(line_1A,line_2C))continue;
					if(is_Cross(line_1A,line_0C))continue;
					if(is_Cross(line_1B,line_2C))continue;
					if(is_Cross(line_1B,line_0C))continue;
					if(is_Cross(line_2B,line_0C))continue;

					cross_BC = calc_Cross_Point(proj_B,proj_C);
					cross_CA = calc_Cross_Point(proj_C,proj_A);

					if(cross_AB == cross_BC && cross_AB == cross_CA){

						if((cross_AB == p_A)||(cross_AB == p_B)||(cross_AB==p_C))continue;

						double tmp_len = len_0A;
						double tmp_dist = norm(base_point[0]-cross_AB);

						if(fabs(tmp_len-tmp_dist) < EPS){

							ans = min(ans,sqrt(tmp_len+tmp_dist));
						}else{

							ans = min(ans,sqrt(tmp_len-tmp_dist));
						}
					}
				}
			}
		}
	}

	if(fabs(ans-BIG_NUM) < EPS){

		printf("-1\n");
	}else{

		printf("%.10lf\n",ans);
	}
}

int main(){

	bool FLG;

	while(true){

		FLG = false;

		for(int i = 0; i < 3; i++){

			scanf("%d %d",&base_loc[i].int_x,&base_loc[i].int_y);

			base_point[i].x = base_loc[i].int_x;
			base_point[i].y = base_loc[i].int_y;

			if(base_loc[i].int_x != 0 || base_loc[i].int_y != 0){

				FLG = true;
			}
		}
		if(!FLG)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 580
memory_kb: 10396
final_rank: 11

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define MAX 80005
#define SIZE 3

struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}


	void debug(){

		printf("(%.3lf,%.3lf)\n",x,y);
	}

	double x,y;
};

typedef Point Vector;
typedef vector<Point> Polygon;

double calc_dist(Point A,Point B){

	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
struct Line{
	Line(){

	}
	Line(Point a,Point b){
		p[0] = a;
		p[1] = b;
	}
	/*void outPut(){

		printf("(%.3lf,%.3lf)-(%.3lf,%.3lf)\n",p[0].x,p[0].y,p[1].x,p[1].y);
	}*/
	Point p[2];
};

struct LOC{
	LOC(){

		int_x = int_y = 0;
	}
	LOC(int arg_int_x,int arg_int_y){
		int_x = arg_int_x;
		int_y = arg_int_y;
	}
	int int_x,int_y;
};

LOC base_loc[SIZE];
Point base_point[3],p_A,p_B,p_C;
vector<LOC> V[SIZE][MAX];

double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0,Point p1,Point p2){

	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
	if(cross(a,b) < -EPS)return CLOCKWISE;
	if(dot(a,b) < -EPS)return ONLINE_BACK;
	if(a.norm() < b.norm())return ONLINE_FRONT;

	return ON_SEGMENT;
}


int func(double x1,double y1,double x2, double y2, double xp, double yp){
	double naiseki,norm1,norm2,gaiseki;
	norm1 = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	norm2 = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
	naiseki = (xp-x1)*(x2-x1)+(yp-y1)*(y2-y1);
	gaiseki = (x2-x1)*(yp-y1)-(xp-x1)*(y2-y1);
	if(gaiseki > EPS){
		return 1;
	}else if(gaiseki < -EPS){
		return -1;
	}
	if(naiseki < -EPS){
		return 2;
	}

	if(norm1 < norm2){
		return -2;
	}
	return 0;
}


//★★直線ではなく、線分の交差判定★★
bool is_Cross(Line a,Line b){

	if(func(a.p[0].x,a.p[0].y,a.p[1].x,a.p[1].y,b.p[0].x,b.p[0].y)*
			func(a.p[0].x,a.p[0].y,a.p[1].x,a.p[1].y,b.p[1].x,b.p[1].y) <= 0 &&
			func(b.p[0].x,b.p[0].y,b.p[1].x,b.p[1].y,a.p[0].x,a.p[0].y)*
			func(b.p[0].x,b.p[0].y,b.p[1].x,b.p[1].y,a.p[1].x,a.p[1].y) <= 0){
		return true;
	}
	return false;
}


Point calc_minus(Point a,Point b){
    Point ret;

    ret.x = a.x-b.x;
    ret.y = a.y-b.y;

    return ret;
}

double calc_len(Vector a){
    return sqrt(a.x*a.x+a.y*a.y);
}

//線分ではなく直線と点の距離
double getDistanceLP(Line l,Point p){
    return fabs(cross(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0]))/calc_len(calc_minus(l.p[1],l.p[0])));
}

//点と線分の距離
double getDistanceSP(Line l,Point p){
	if(dot(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0])) < 0.0)return calc_len(calc_minus(p,l.p[0]));
	if(dot(calc_minus(l.p[0],l.p[1]),calc_minus(p,l.p[1])) < 0.0)return calc_len(calc_minus(p,l.p[1]));
	return getDistanceLP(l,p);
}

//線分と線分の距離
double getDistance(Line A,Line B){
	if(is_Cross(A,B))return 0.0;
	return min(min(getDistanceSP(A,B.p[0]),getDistanceSP(A,B.p[1])),
			min(getDistanceSP(B,A.p[0]),getDistanceSP(B,A.p[1])));
}


//交点を求める関数
Point calc_Cross_Point(double x1,double x2,double x3,double x4,double y1,double y2,double y3,double y4){
	Point ret;
	ret.x = ((x2-x1)*(y3*(x4-x3)+x3*(y3-y4))-(x4-x3)*(y1*(x2-x1)+x1*(y1-y2)))/((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1));
	if(fabs(x1-x2) > EPS){
		ret.y = ((y2-y1)*ret.x+y1*(x2-x1)+x1*(y1-y2))/(x2-x1);
	}else{
		ret.y = ((y4-y3)*ret.x+y3*(x4-x3)+x3*(y3-y4))/(x4-x3);
	}
	return ret;
}

//インタフェース関数
Point calc_Cross_Point(Point a,Point b,Point c,Point d){
	return calc_Cross_Point(a.x,b.x,c.x,d.x,a.y,b.y,c.y,d.y);
}


Point calc_Cross_Point(Line A,Line B){

	if(getDistanceSP(B,A.p[0]) < EPS){

		return A.p[0];

	}else if(getDistanceSP(B,A.p[1]) < EPS){

		return A.p[1];

	}else if(getDistanceSP(A,B.p[0]) < EPS){

		return B.p[0];

	}else if(getDistanceSP(A,B.p[1]) < EPS){

		return B.p[1];
	}

	return calc_Cross_Point(A.p[0],A.p[1],B.p[0],B.p[1]);
}


Point project(Line l,Point p){

	Vector base = l.p[1]-l.p[0];
	double r = dot(p-l.p[0],base)/norm(base);
	return l.p[0]+base*r;
}

double calc_slope(Line A){

	if(fabs(A.p[0].x-A.p[1].x) < EPS){

		return DBL_MAX;

	}else if(fabs(A.p[0].y-A.p[1].y) < EPS){

		return 0;

	}else{

		return (A.p[1].y-A.p[0].y)/(A.p[1].x-A.p[0].x);
	}
}

//線分をp1方向に伸ばす
Line calc_longer(Line tmp_line){

	double slope = calc_slope(tmp_line);
	double NUM = 200000;

	Line ret;
	ret.p[0] = tmp_line.p[0];

	if(fabs(slope-DBL_MAX) < EPS){ //垂直

		if(tmp_line.p[0].y > tmp_line.p[1].y){

			ret.p[1] = Point(tmp_line.p[0].x,-NUM);

		}else{

			ret.p[1] = Point(tmp_line.p[0].x,NUM);
		}

	}else if(fabs(slope) < EPS){ //水平

		if(tmp_line.p[0].x > tmp_line.p[1].x){

			ret.p[1] = Point(-NUM,tmp_line.p[0].y);

		}else{

			ret.p[1] = Point(NUM,tmp_line.p[0].y);
		}

	}else{

		if(tmp_line.p[0].x > tmp_line.p[1].x){

			ret.p[1] = Point(tmp_line.p[0].x-NUM,tmp_line.p[0].y-NUM*slope);

		}else{

			ret.p[1] = Point(tmp_line.p[0].x+NUM,tmp_line.p[0].y+NUM*slope);
		}

	}
	return ret;
}

//2つのvectorがなすラジアンを求める関数
double calc_rad(Vector vec1,Vector vec2){

	double tmp = dot(vec1,vec2)/(abs(vec1)*abs(vec2));

	if(fabs(tmp+1.0) < EPS){

		return M_PI;
	}

	if(fabs(tmp-1.0) < EPS){

		return  0.0;
	}

	return acos(dot(vec1,vec2)/(abs(vec1)*abs(vec2)));
}

Point calc_Reflection_Point(double x1,double y1,double x2,double y2,double xp,double yp){

	Point ret;

	bool X_FLG = false,Y_FLG = false;
	double slope;

	if(y1 == y2){
		X_FLG = true;
	}else if(x1 == x2){
		Y_FLG = true;
	}else{
		slope = (y2-y1)/(x2-x1);
	}

	if(X_FLG){
		ret.x = xp,ret.y=y1;
	}else if(Y_FLG){
		ret.x = x1,ret.y = yp;
	}else{
		ret.x = (yp*(x2-x1)*(y2-y1)+xp*(x2-x1)*(x2-x1)-y1*(y2-y1)*(x2-x1)+x1*(y2-y1)*(y2-y1))/((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
		ret.y = ((x1-x2)*ret.x+yp*(y2-y1)+xp*(x2-x1))/(y2-y1);
	}
	ret.x = 2*ret.x-xp;
	ret.y = 2*ret.y-yp;

	return ret;
}

Point calc_Reflection_Point(Line line,Point point){

	return calc_Reflection_Point(line.p[0].x,line.p[0].y,line.p[1].x,line.p[1].y,point.x,point.y);
}



void func(){

	for(int i = 0; i < MAX; i++){
		V[1][i].clear();
		V[2][i].clear();
	}

	Line line_01,line_12,line_20;

	line_01.p[0] = base_point[0];
	line_01.p[1] = base_point[1];

	line_12.p[0] = base_point[1];
	line_12.p[1] = base_point[2];

	line_20.p[0] = base_point[2];
	line_20.p[1] = base_point[0];


	//点1,点2から、範囲内の格子点の距離を求めておく
	for(int i = 1; i <= 2; i++){
		for(int X = -100; X <= 100; X++){
			for(int Y = -100; Y <= 100; Y++){
				Point tmp_p = Point(X,Y);

				double tmp_rad;

				if(i == 1){
					if(ccw(base_point[1],tmp_p,base_point[2]) != COUNTER_CLOCKWISE){
						continue;
					}

					tmp_rad = calc_rad(tmp_p-base_point[1],base_point[2]-base_point[1]);

				}else{
					if(ccw(base_point[2],tmp_p,base_point[0]) != COUNTER_CLOCKWISE){
						continue;
					}
					tmp_rad = calc_rad(tmp_p-base_point[2],base_point[0]-base_point[2]);
				}

				if(fabs(tmp_rad-M_PI) < EPS || fabs(tmp_rad) < EPS)continue;//面積0は不可

				int tmp_index = (base_loc[i].int_x-X)*(base_loc[i].int_x-X)+(base_loc[i].int_y-Y)*(base_loc[i].int_y-Y);

				V[i][tmp_index].push_back(LOC(X,Y));
			}
		}
	}

	double ans = BIG_NUM;

	int len_0A,len_1A,len_2B,len_0C;

	Line proj_A,proj_B,proj_C;
	Line line_0A,line_1A,line_1B,line_2B,line_2C,line_0C;
	Point cross_AB,cross_BC,cross_CA;

	line_0A.p[0] = base_point[0];
	line_1A.p[0] = base_point[1];
	line_1B.p[0] = base_point[1];
	line_2B.p[0] = base_point[2];
	line_2C.p[0] = base_point[2];
	line_0C.p[0] = base_point[0];

	for(int a_x = -100; a_x <= 100; a_x++){
		for(int a_y = -100; a_y <= 100; a_y++){

			p_A = Point(a_x,a_y);
			if(ccw(base_point[0],p_A,base_point[1]) != COUNTER_CLOCKWISE){
				continue;
			}
			double tmp_rad = calc_rad(p_A-base_point[0],base_point[1]-base_point[0]);
			if(fabs(tmp_rad-M_PI) < EPS || fabs(tmp_rad) < EPS)continue; //面積0は不可

			len_0A = (base_loc[0].int_x-a_x)*(base_loc[0].int_x-a_x)+(base_loc[0].int_y-a_y)*(base_loc[0].int_y-a_y);
			len_1A = (base_loc[1].int_x-a_x)*(base_loc[1].int_x-a_x)+(base_loc[1].int_y-a_y)*(base_loc[1].int_y-a_y);

			proj_A.p[0] = p_A;
			proj_A.p[1] = calc_Reflection_Point(line_01,p_A);

			proj_A = calc_longer(proj_A);

			line_0A.p[1] = p_A;
			line_1A.p[1] = p_A;

			//点Bの検索
			for(int i = 0; i < V[1][len_1A].size(); i++){

				int b_x = V[1][len_1A][i].int_x;
				int b_y = V[1][len_1A][i].int_y;

				len_2B = (base_loc[2].int_x-b_x)*(base_loc[2].int_x-b_x)+(base_loc[2].int_y-b_y)*(base_loc[2].int_y-b_y);

				p_B = Point(b_x,b_y);
				if(p_B == p_A)continue;

				proj_B.p[0] = p_B;
				proj_B.p[1] = calc_Reflection_Point(line_12,p_B);

				proj_B = calc_longer(proj_B);

				if(!is_Cross(proj_A,proj_B))continue;

				cross_AB = calc_Cross_Point(proj_A,proj_B);

				line_1B.p[1] = p_B;
				line_2B.p[1] = p_B;

				if(is_Cross(line_0A,line_1B))continue;
				if(is_Cross(line_0A,line_2B))continue;
				if(is_Cross(line_1A,line_2B))continue;

				//点Cの検索
				for(int k = 0; k < V[2][len_2B].size(); k++){

					int c_x = V[2][len_2B][k].int_x;
					int c_y = V[2][len_2B][k].int_y;

					len_0C = (base_loc[0].int_x-c_x)*(base_loc[0].int_x-c_x)+(base_loc[0].int_y-c_y)*(base_loc[0].int_y-c_y);
					if(len_0C != len_0A)continue;

					p_C = Point(c_x,c_y);
					if(p_C == p_A || p_C == p_B)continue;

					proj_C.p[0] = p_C;
					proj_C.p[1] = calc_Reflection_Point(line_20,p_C);

					proj_C = calc_longer(proj_C);

					if(!is_Cross(proj_A,proj_C)||!is_Cross(proj_B,proj_C))continue;

					line_2C.p[1] = p_C;
					line_0C.p[1] = p_C;

					if(is_Cross(line_0A,line_2C))continue;
					if(is_Cross(line_1A,line_2C))continue;
					if(is_Cross(line_1A,line_0C))continue;
					if(is_Cross(line_1B,line_2C))continue;
					if(is_Cross(line_1B,line_0C))continue;
					if(is_Cross(line_2B,line_0C))continue;

					cross_BC = calc_Cross_Point(proj_B,proj_C);
					cross_CA = calc_Cross_Point(proj_C,proj_A);

					if(cross_AB == cross_BC && cross_AB == cross_CA){

						if((cross_AB == p_A)||(cross_AB == p_B)||(cross_AB==p_C))continue;

						double tmp_len = len_0A;
						double tmp_dist = norm(base_point[0]-cross_AB);

						if(fabs(tmp_len-tmp_dist) < EPS){

							ans = min(ans,sqrt(tmp_len+tmp_dist));
						}else{

							ans = min(ans,sqrt(tmp_len-tmp_dist));
						}
					}
				}
			}
		}
	}

	if(fabs(ans-BIG_NUM) < EPS){

		printf("-1\n");
	}else{

		printf("%.10lf\n",ans);
	}
}

int main(){

	bool FLG;

	while(true){

		FLG = false;

		for(int i = 0; i < 3; i++){

			scanf("%d %d",&base_loc[i].int_x,&base_loc[i].int_y);

			base_point[i].x = base_loc[i].int_x;
			base_point[i].y = base_loc[i].int_y;

			if(base_loc[i].int_x != 0 || base_loc[i].int_y != 0){

				FLG = true;
			}
		}
		if(!FLG)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 740
memory_kb: 10472
final_rank: 14

code_snippet: #include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};
struct C{
    P p;
    double r;
    C(const P& p, const double& r) : p(p), r(r) {}
    C(){}
};

namespace std{
    bool operator < (const P& a, const P& b){
        return !EQ(a.X,b.X) ? a.X<b.X : a.Y+EPS<b.Y;
    }
    bool operator == (const P& a, const P& b){
        return abs(a-b) < EPS;
    }
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    if(dot(b,c) < -EPS) return +2; //c-a-b
    if(abs(c)-abs(b) > EPS) return -2; //a-b-c
    return 0; //a-c-b
}
P unit(const P &p){
    return p/abs(p);
}
P rotate(const P &p, double rad){
    return p *P(cos(rad), sin(rad));
}

bool intersectSS(const L& a, const L& b){
    return ( ccw(a[0],a[1],b[0]) *ccw(a[0],a[1],b[1]) <= 0 ) &&
        ( ccw(b[0],b[1],a[0]) *ccw(b[0],b[1],a[1]) <= 0 );
}

P projection(const L& l, const P& p) {
    double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
    return l[0] + t*(l[0]-l[1]);
}
double distanceLP(const L &l, const P &p) {
    return abs(cross(l[1]-l[0], p-l[0])) /abs(l[1]-l[0]);
}

P crosspointLL(const L &l, const L &m) {
  double A = cross(l[1]-l[0], m[1]-m[0]);
  double B = cross(l[1]-l[0], l[1]-m[0]);
  return m[0] + B/A *(m[1]-m[0]);
}

VP crosspointCC(C a, C b){
    VP ret;
    if(a.p == b.p && a.r == b.r){
        return ret;
    }
    if(a.r < b.r) swap(a,b);
    double dist = abs(b.p-a.p);
    P dir = a.r*unit(b.p-a.p);
    if(EQ(dist, a.r+b.r) || EQ(dist, a.r-b.r)){
        ret.push_back(a.p +dir);
    }else if(a.r-b.r < dist && dist < a.r+b.r){
        double cos = (a.r*a.r +dist*dist -b.r*b.r)/(2*a.r*dist);
        double sin = sqrt(1 -cos*cos);
        ret.push_back(a.p +dir*P(cos, sin));
        ret.push_back(a.p +dir*P(cos, -sin));
    }
    return ret;
}

bool isValid(const P &p){
	return -100 < p.X +EPS && p.X < 100 +EPS &&
		-100 < p.Y +EPS && p.Y < 100 +EPS &&
		EQ(p.X, round(p.X)) && EQ(p.Y, round(p.Y));			
}

double solve(const VP &tri, const P &p, const P &q){
	//p,qを置く位置が不正
	if(!isValid(p) || !isValid(q)) return INF;
	if(cross(tri[0] -tri[1], p -tri[1]) < EPS) return INF*2;
	if(cross(tri[2] -tri[0], q -tri[0]) < EPS) return INF*3;
	if(intersectSS(L(tri[1], p), L(tri[0], q))) return INF*4;
	if(intersectSS(L(tri[0], p), L(tri[2], q))) return INF*5;

	//もう1つの点rの位置
	VP cp = crosspointCC(C(tri[1], abs(tri[1] -p)), C(tri[2], abs(tri[2] -q)));
	if((int)cp.size()!=2) return INF;
	P r = (cross(tri[1] -tri[2], cp[0] -tri[2]) > EPS)? cp[0]: cp[1];
	if(!isValid(r)) return INF;

	//四面体の高さを計算
	P cpll = crosspointLL(L(p, projection(L(tri[0], tri[1]), p)), 
		L(q, projection(L(tri[2], tri[0]), q)));
	double d = distanceLP(L(tri[0], tri[1]), p);
	double a = distanceLP(L(tri[0], tri[1]), cpll);
    if(EQ(d, a)) return INF;
	return sqrt(d*d -a*a);
}

int main(){
	vector<VP> ltoxy(80001);
	for(int x=0; x<=200; x++){
		for(int y=0; y<=200; y++){
			int lsq = x*x +y*y;
			ltoxy[lsq].emplace_back(x, y);
            if(x != 0){
                ltoxy[lsq].emplace_back(-x, y);
            }
			if(y != 0){
                ltoxy[lsq].emplace_back(x, -y);
            }
			if(x != 0 && y != 0){
                ltoxy[lsq].emplace_back(-x, -y);
            }
		}
	}

    while(1){
    	VP tri(3);
    	P ori(0, 0);
    	for(int i=0; i<3; i++){
    		int x,y;
    		cin >> x >> y;
    		tri[i] = P(x, y);
    	}
    	if(tri[0]==ori && tri[1]==ori && tri[2]==ori){
    		break;
    	}

    	double ans = INF;
    	for(int l=1; l<(int)ltoxy.size(); l++){
    		for(const P &p: ltoxy[l]){
    			for(const P &q: ltoxy[l]){
    				ans = min(ans, solve(tri, tri[0]+p, tri[0]+q));
    			}
    		}
    	}
    	if(ans == INF){
    		cout << -1 << endl;
    	}else{
	    	cout << fixed << setprecision(10);
    		cout << ans << endl;
    	}
    }
    return 0;
}
accuracy: 1
time_ms: 2790
memory_kb: 7428
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }

const double INF = 1e18;
constexpr double EPS = 1e-8;

using Point = complex<double>;
#define X(a) real(a)
#define Y(a) imag(a)
struct Segment { Point a, b; };
struct Circle{ Point c; double r; };

template<class T> bool eq(const T &a, const T &b) { return abs(a - b) < EPS; }
namespace std {
  bool operator == (Point a, Point b) { return eq(X(a), X(b)) and eq(Y(a), Y(b)); }
  bool operator <  (Point a, Point b) { return X(a) == X(b) ? Y(a) < Y(b) : X(a) < X(b); }
  istream& operator >> (istream &is, Point &a) { double x, y; is >> x >> y; a.X(x); a.Y(y); return is; }
  double norm(Point p) { assert(0); } // complex ??? norm ?????????
}
double dot     (Point a, Point b) { return a.X() * b.X() + a.Y() * b.Y(); }
double cross   (Point a, Point b) { return a.X() * b.Y() - a.Y() * b.X(); }
double length2 (Point p         ) { return p.X() * p.X() + p.Y() * p.Y(); }
double length  (Point p         ) { return sqrt(length2(p)); }
double distance(Point a, Point b) { return length(a - b); }
Point  unit    (Point p         ) { return p / length(p); }
Point orthonormal(Point &p) { // ??£?????´???????????????
    Point p2 = Point(-1 * p.Y(), p.X()); // = rotate(p, 90);
    return p2 / length(p2);
}
enum ccw_t { // ??????????????¢??¨????????§ ccw_t ??? int ??§??????????????????????????¨???
    COUNTER_CLOCK_WISE = 1,
    CLOCK_WISE = -1,
    STRAIGHT_C_A_B = 2,
    STRAIGHT_A_B_C = -2,
    STRAIGHT_A_C_B = 0
};
ccw_t ccw(Point a, Point b, Point c){
    Point ab = b - a, ac = c - a;
    if( cross(ab,ac) > EPS ) return COUNTER_CLOCK_WISE; // +1 a-b-c ???????¨???????
    if( cross(ab,ac) < -EPS ) return CLOCK_WISE;        // -1 a-b-c ????¨???????
    if( dot(ab,ac) < -EPS ) return STRAIGHT_C_A_B;      // +2 c-a-b
    if( length2(ab) < length2(ac) )return STRAIGHT_A_B_C;     // -2 a-b-c or a==b
    return STRAIGHT_A_C_B;                              //  0 a-c-b or b==c or a==c
}
bool does_intersect(Segment a, Segment b){
    return (int)ccw(a.a, a.b, b.a) * (int)ccw(a.a, a.b, b.b) <= 0 &&
           (int)ccw(b.a, b.b, a.a) * (int)ccw(b.a, b.b, a.b) <= 0;
}

Point intersection(Segment a, Segment b) {
    assert(does_intersect(a, b));
    double p = cross(a.b - a.a, b.b - b.a);
    double q = cross(a.b - a.a, a.b - b.a);
    if(abs(p) < EPS and abs(q) < EPS) return a.a;
    if(abs(p) < EPS) assert(0);
    return q / p * (b.b - b.a) + b.a;
}
Point projection(Segment l, Point p) {
    double t = dot(p-l.a, l.a-l.b) / length2(l.a - l.b);
    Point ret = (l.a-l.b);
    return ret * t + l.a;
}

vector<Point> cross_points(Circle c1, Circle c2) {
    double d = distance(c1.c, c2.c);
    assert(d > 0);
    // c1.c ?????????c1,c2????????????????????´?????¨c1.c->c2.c ??????????????§????????¢
    double x = (pow(c1.r, 2) - pow(c2.r, 2) + pow(d, 2)) / (2 * d);
    if(c1.r < x) return {};
    double h = sqrt(pow(c1.r, 2) - pow(x, 2));    
    Point mid = unit(c2.c - c1.c) * x;
    if(eq(h, 0.0)) return { c1.c + mid };
    Point vertical = unit(Point(-Y(mid), X(mid))) * h; // ???????????????????????????
    return { c1.c + mid + vertical, c1.c + mid - vertical };
}

Point nearest_grid_point(Point p) {
    return Point{round(p.X()), round(p.Y())};
}


class Solver {
  public:
    bool solve() {
        Point a, b, c; cin >> a >> b >> c;
        if(a.X() == 0 and a.Y() == 0 and
           b.X() == 0 and b.Y() == 0 and
           c.X() == 0 and c.Y() == 0) return 0;

        auto in_range = [] (Point p) {
            return abs(p.X()) < 100 + EPS and abs(p.Y()) < 100 + EPS;
        };
        auto left_side = [](Point p, Point a, Point b) {
            return ccw(a, b, p) == COUNTER_CLOCK_WISE;
        };
        
        auto calc_height = [&] (Point p1, Point p2, Point p3) {
            Point p1p = projection(Segment{a, c}, p1);
            Point p2p = projection(Segment{a, b}, p2);
            Segment p1_ac = Segment{p1, p1 + (p1p - p1) * 1e3};
            Segment p2_ab = Segment{p2, p2 + (p2p - p2) * 1e3};
            if(not does_intersect(p1_ac, p2_ab)) return INF;
            Point p = intersection(p1_ac, p2_ab);
            if(p == p1 or p == p2 or p == p3) return INF;
            double l_ah = distance(a, p1);
            double l_ap = distance(a, p);
            if(p == a) return l_ah;
            if(l_ah <= l_ap) return INF;
            return sqrt(l_ah * l_ah - l_ap * l_ap);
        };
        
        double ans = INF;
        repeat(x1, -100, 100 + 1) {
            repeat(y1, -100, 100 + 1) {
                Point p1 = Point(x1, y1);
                if(ccw(a, c, p1) != COUNTER_CLOCK_WISE) continue;
                double l1 = distance(a, p1);
                int y2_mx = min<int>(100, a.Y() + l1 + 0.5);
                int y2_mn = max<int>(-100, a.Y() - l1 - 0.5);               
                repeat(y2, y2_mn, y2_mx + 1) {
                    double dy = abs(a.Y() - y2);
                    double dx = sqrt(l1 * l1 - dy * dy);
                    for(Point p2_cand : {Point{a.X() + dx, (double)y2}, Point{a.X() - dx, (double)y2}}) {
                        Point p2 = nearest_grid_point(p2_cand);

                        if(not in_range(p2) or
                           not eq(distance(a, p2), l1) or
                           not left_side(p2, b, a) or 
                           p1 == p2 or 
                           (left_side(p1, b, a) and not left_side(p1, p2, a))) continue;                              
                        
                        double l2 = distance(p1, c);
                        double l3 = distance(p2, b);

                        Point p3;

                        bool ok = false;
                        for(Point p3_cand : cross_points(Circle{c, l2}, Circle{b, l3})) {
                            p3 = nearest_grid_point(p3_cand);

                            if(not in_range(p3) or
                               not left_side(p3, c, b) or
                               p1 == p3 or
                               p2 == p3 or
                               (left_side(p2, c, b) and not left_side(p2, p3, b)) or
                               (left_side(p3, a, c) and not left_side(p3, p1, c))) continue;

                            if(eq(distance(c, p3), l2) and eq(distance(b, p3), l3)) {
                                ok = true;
                                break;
                            }
                        }
                        if(not ok) continue;
                        set_min(ans, calc_height(p1, p2, p3));
                    }
                }
            }
        }
        printf("%.10lf\n", (ans == INF ? -1 : ans));
        return 1;
    }
};

int main() {
    while(Solver().solve());
    return 0;
}
accuracy: 1
time_ms: 4850
memory_kb: 3368
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }

const double INF = 1e18;
constexpr double EPS = 1e-8;

using Point = complex<double>;
#define X(a) real(a)
#define Y(a) imag(a)
struct Segment { Point a, b; };
struct Circle{ Point c; double r; };

template<class T> bool eq(const T &a, const T &b) { return abs(a - b) < EPS; }
namespace std {
  bool operator == (Point a, Point b) { return eq(X(a), X(b)) and eq(Y(a), Y(b)); }
  bool operator <  (Point a, Point b) { return X(a) == X(b) ? Y(a) < Y(b) : X(a) < X(b); }
  istream& operator >> (istream &is, Point &a) { double x, y; is >> x >> y; a.X(x); a.Y(y); return is; }
  double norm(Point p) { assert(0); } // complex ??? norm ?????????
}
double dot     (Point a, Point b) { return a.X() * b.X() + a.Y() * b.Y(); }
double cross   (Point a, Point b) { return a.X() * b.Y() - a.Y() * b.X(); }
double length2 (Point p         ) { return p.X() * p.X() + p.Y() * p.Y(); }
double length  (Point p         ) { return sqrt(length2(p)); }
double distance(Point a, Point b) { return length(a - b); }
Point  unit    (Point p         ) { return p / length(p); }
Point orthonormal(Point &p) { // ??£?????´???????????????
    Point p2 = Point(-1 * p.Y(), p.X()); // = rotate(p, 90);
    return p2 / length(p2);
}
enum ccw_t { // ??????????????¢??¨????????§ ccw_t ??? int ??§??????????????????????????¨???
    COUNTER_CLOCK_WISE = 1,
    CLOCK_WISE = -1,
    STRAIGHT_C_A_B = 2,
    STRAIGHT_A_B_C = -2,
    STRAIGHT_A_C_B = 0
};
ccw_t ccw(Point a, Point b, Point c){
    Point ab = b - a, ac = c - a;
    if( cross(ab,ac) > EPS ) return COUNTER_CLOCK_WISE; // +1 a-b-c ???????¨???????
    if( cross(ab,ac) < -EPS ) return CLOCK_WISE;        // -1 a-b-c ????¨???????
    if( dot(ab,ac) < -EPS ) return STRAIGHT_C_A_B;      // +2 c-a-b
    if( length2(ab) < length2(ac) )return STRAIGHT_A_B_C;     // -2 a-b-c or a==b
    return STRAIGHT_A_C_B;                              //  0 a-c-b or b==c or a==c
}
bool does_intersect(Segment a, Segment b){
    return (int)ccw(a.a, a.b, b.a) * (int)ccw(a.a, a.b, b.b) <= 0 &&
           (int)ccw(b.a, b.b, a.a) * (int)ccw(b.a, b.b, a.b) <= 0;
}

Point intersection(Segment a, Segment b) {
    assert(does_intersect(a, b));
    double p = cross(a.b - a.a, b.b - b.a);
    double q = cross(a.b - a.a, a.b - b.a);
    if(abs(p) < EPS and abs(q) < EPS) return a.a;
    if(abs(p) < EPS) assert(0);
    return q / p * (b.b - b.a) + b.a;
}
Point projection(Segment l, Point p) {
    double t = dot(p-l.a, l.a-l.b) / length2(l.a - l.b);
    Point ret = (l.a-l.b);
    return ret * t + l.a;
}

vector<Point> cross_points(Circle c1, Circle c2) {
    double d = distance(c1.c, c2.c);
    assert(d > 0);
    // c1.c ?????????c1,c2????????????????????´?????¨c1.c->c2.c ??????????????§????????¢
    double x = (pow(c1.r, 2) - pow(c2.r, 2) + pow(d, 2)) / (2 * d);
    if(c1.r < x) return {};
    double h = sqrt(pow(c1.r, 2) - pow(x, 2));    
    Point mid = unit(c2.c - c1.c) * x;
    if(eq(h, 0.0)) return { c1.c + mid };
    Point vertical = unit(Point(-Y(mid), X(mid))) * h; // ???????????????????????????
    return { c1.c + mid + vertical, c1.c + mid - vertical };
}

Point nearest_grid_point(Point p) {
    return Point{round(p.X()), round(p.Y())};
}


class Solver {
  public:
    bool solve() {
        Point a, b, c; cin >> a >> b >> c;
        if(a.X() == 0 and a.Y() == 0 and
           b.X() == 0 and b.Y() == 0 and
           c.X() == 0 and c.Y() == 0) return 0;
        
        auto calc_height = [&] (Point p1, Point p2, Point p3) {
            Point p1p = projection(Segment{a, c}, p1);
            Point p2p = projection(Segment{a, b}, p2);
            Segment p1_ac = Segment{p1, p1 + (p1p - p1) * 1e3};
            Segment p2_ab = Segment{p2, p2 + (p2p - p2) * 1e3};
            if(not does_intersect(p1_ac, p2_ab)) return INF;
            Point p = intersection(p1_ac, p2_ab);
            if(p == p1 or p == p2 or p == p3) return INF;
            double l_ah = distance(a, p1);
            double l_ap = distance(a, p);
            if(p == a) return l_ah;
            if(l_ah <= l_ap) return INF;
            return sqrt(l_ah * l_ah - l_ap * l_ap);
        };
        
        double ans = INF;
        repeat(x1, -100, 100 + 1) {
            repeat(y1, -100, 100 + 1) {
                Point p1 = Point(x1, y1);
                if(ccw(a, c, p1) != COUNTER_CLOCK_WISE) continue;
                double l1 = distance(a, p1);
                int y2_mx = min<int>(100, a.Y() + l1 + 0.5);
                int y2_mn = max<int>(-100, a.Y() - l1 - 0.5);               
                repeat(y2, y2_mn, y2_mx + 1) {
                    double dy = abs(a.Y() - y2);
                    double dx = sqrt(l1 * l1 - dy * dy);
                    for(Point p2_cand : {Point{a.X() + dx, (double)y2}, Point{a.X() - dx, (double)y2}}) {
                        Point p2 = nearest_grid_point(p2_cand);
                        
                        if(abs(p2.X()) > 100 or abs(p2.Y()) > 100) continue;
                        if(not eq(distance(a, p2), l1)) continue;
                        if(ccw(b, a, p2) != COUNTER_CLOCK_WISE) continue;
                        if(p1 == p2) continue;
                        if(ccw(b, a, p1) == COUNTER_CLOCK_WISE and ccw(p2, a, p1) != COUNTER_CLOCK_WISE) continue;
                        
                        double l2 = distance(p1, c);
                        double l3 = distance(p2, b);

                        Point p3;

                        bool ok = false;
                        for(Point p3_cand : cross_points(Circle{c, l2}, Circle{b, l3})) {
                            p3 = nearest_grid_point(p3_cand);
                            
                            if(abs(p3.X()) > 100 or abs(p3.Y()) > 100) continue;
                            if(ccw(c, b, p3) != COUNTER_CLOCK_WISE) continue;                            
                            if(p1 == p3 or p2 == p3) continue;
                            if(ccw(c, b, p2) == COUNTER_CLOCK_WISE and ccw(p3, b, p2) != COUNTER_CLOCK_WISE) continue;
                            if(ccw(a, c, p3) == COUNTER_CLOCK_WISE and ccw(p1, c, p3) != COUNTER_CLOCK_WISE) continue;
                            
                            if(eq(distance(c, p3), l2) and eq(distance(b, p3), l3)) {
                                ok = true;
                                break;
                            }
                        }
                        if(not ok) continue;
                        set_min(ans, calc_height(p1, p2, p3));
                    }
                }
            }
        }
        printf("%.10lf\n", (ans == INF ? -1 : ans));
        return 1;
    }
};

int main() {
    while(Solver().solve());
    return 0;
}
accuracy: 1
time_ms: 4680
memory_kb: 3204
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const double INF = 1e18;
constexpr double EPS = 1e-8;

using Point = complex<double>;
#define X(a) real(a)
#define Y(a) imag(a)
struct Segment { Point a, b; };
struct Circle{ Point c; double r; };

template<class T> bool eq(const T &a, const T &b) { return abs(a - b) < EPS; }
namespace std {
bool operator == (const Point &a, const Point &b) { return eq(X(a), X(b)) and eq(Y(a), Y(b)); }
bool operator <  (const Point &a, const Point &b) { return X(a) == X(b) ? Y(a) < Y(b) : X(a) < X(b); }
istream& operator >> (istream &is, Point &a) { double x, y; is >> x >> y; a.X(x); a.Y(y); return is; }
double norm(const Point &p) { assert(0); } // complex ??? norm ?????????
}
double dot     (const Point &a, const Point &b) { return a.X() * b.X() + a.Y() * b.Y(); }
double cross   (const Point &a, const Point &b) { return a.X() * b.Y() - a.Y() * b.X(); }
double length2 (const Point &p         ) { return p.X() * p.X() + p.Y() * p.Y(); }
double length  (const Point &p         ) { return sqrt(length2(p)); }
double distance(const Point &a, const Point &b) { return length(a - b); }
double arg     (const Point &a)          { return atan2(Y(a), X(a)); } // -> [-pi, pi],  (0, 0) is invalid!
Point  unit    (const Point &p         ) { return p / length(p); }
Point orthonormal(Point &p) { // ??£?????´???????????????
    Point p2 = Point(-1 * p.Y(), p.X()); // = rotate(p, 90);
    return p2 / length(p2);
}
enum ccw_t { // ??????????????¢??¨????????§ ccw_t ??? int ??§??????????????????????????¨???
    COUNTER_CLOCK_WISE = 1,
    CLOCK_WISE = -1,
    STRAIGHT_C_A_B = 2,
    STRAIGHT_A_B_C = -2,
    STRAIGHT_A_C_B = 0
};
ccw_t ccw(const Point &a, const Point &b, const Point &c){
    Point ab = b - a, ac = c - a;
    if( cross(ab,ac) > EPS ) return COUNTER_CLOCK_WISE; // +1 a-b-c ???????¨???????
    if( cross(ab,ac) < -EPS ) return CLOCK_WISE;        // -1 a-b-c ????¨???????
    if( dot(ab,ac) < -EPS ) return STRAIGHT_C_A_B;      // +2 c-a-b
    if( length2(ab) < length2(ac) )return STRAIGHT_A_B_C;     // -2 a-b-c or a==b
    return STRAIGHT_A_C_B;                              //  0 a-c-b or b==c or a==c
}
// Segment
bool operator == (Segment a, Segment b) { return a.a == b.a and a.b == b.b; }
bool operator != (Segment a, Segment b) { return a.a == b.a and a.b == b.b; }
istream &operator >> (istream& is, Segment& s){ return is >> s.a >> s.b;}
ostream &operator << (ostream& os, const Segment& s){ return os << s.a << "->" << s.b;}

double length(Segment s) { return distance(s.a, s.b); }
double distance( Segment s ,const Point &p) {
    if( dot( s.b - s.a , p - s.a ) < EPS ) return distance(p, s.a);
    if( dot( s.a - s.b , p - s.b ) < EPS ) return distance(p, s.b);
    return abs(cross( s.b - s.a , p - s.a ) / distance(s.b, s.a));
}
bool does_intersect(Segment a, Segment b){
    return (int)ccw(a.a, a.b, b.a) * (int)ccw(a.a, a.b, b.b) <= 0 &&
           (int)ccw(b.a, b.b, a.a) * (int)ccw(b.a, b.b, a.b) <= 0;
}

bool does_include(Segment s, const Point &p){
    Point a = p - s.a , b = s.b - s.a;
    return ( abs(cross(a,b)) < EPS and dot(a,b) > -EPS and length(s)  > dot(a,b) / length(s) - EPS);
}
Point intersection(Segment a, Segment b) {
    assert(does_intersect(a, b));
    double p = cross(a.b - a.a, b.b - b.a);
    double q = cross(a.b - a.a, a.b - b.a);
    if(abs(p) < EPS and abs(q) < EPS) return a.a;
    if(abs(p) < EPS) assert(0);
    return q / p * (b.b - b.a) + b.a;
}
Point projection(Segment l, const Point &p) {
    double t = dot(p-l.a, l.a-l.b) / length2(l.a - l.b);
    Point ret = (l.a-l.b);
    return ret * t + l.a;
}

vector<Point> cross_points(Circle c1, Circle c2) {
    double d = distance(c1.c, c2.c);
    assert(d > 0);
    // c1.c ?????????c1,c2????????????????????´?????¨c1.c->c2.c ??????????????§????????¢
    double x = (pow(c1.r, 2) - pow(c2.r, 2) + pow(d, 2)) / (2 * d);
    if(c1.r < x) return {};
    double h = sqrt(pow(c1.r, 2) - pow(x, 2));    
    Point mid = unit(c2.c - c1.c) * x;
    if(eq(h, 0.0)) return { c1.c + mid };
    Point vertical = unit(Point(-Y(mid), X(mid))) * h; // ???????????????????????????
    return { c1.c + mid + vertical, c1.c + mid - vertical };
}

Point nearest_grid_point(const Point &p) {
    return Point{round(p.X()), round(p.Y())};
}

class Solver {
  public:
    bool solve() {
        Point a, b, c; cin >> a >> b >> c;
        if(a.X() == 0 and a.Y() == 0 and
           b.X() == 0 and b.Y() == 0 and
           c.X() == 0 and c.Y() == 0) return 0;
        // if(ccw(a, b, c) != COUNTER_CLOCK_WISE) swap(b, c);
        // assert(ccw(a, b, c) == COUNTER_CLOCK_WISE);
        // assert(ccw(b, c, a) == COUNTER_CLOCK_WISE);
        // assert(ccw(c, a, b) == COUNTER_CLOCK_WISE);
        // a, b, c is ccw
        
        auto calc_height = [&] (const Point &p1, const Point &p2, const Point &p3) -> double {
            Point p1p = projection(Segment{a, c}, p1);
            Point p2p = projection(Segment{a, b}, p2);
            Segment p1_ac = Segment{p1, p1 + (p1p - p1) * 1e3};
            Segment p2_ab = Segment{p2, p2 + (p2p - p2) * 1e3};
            if(not does_intersect(p1_ac, p2_ab)) return INF;
            Point p = intersection(p1_ac, p2_ab);
            if(p == p1 or p == p2 or p == p3) return INF;
            auto calc = [&] (Point aa, Point pp) {
                double l_ah = distance(aa, pp);
                double l_ap = distance(aa, p);
                if(p == aa) return l_ah;
                if(l_ah <= l_ap) return INF;
                return sqrt(l_ah * l_ah - l_ap * l_ap);
            };
            double res = calc(a, p1);
            // if(not eq(res, calc(a, p2))) return INF;
            // if(not eq(res, calc(b, p2))) return INF;
            // if(not eq(res, calc(b, p3))) return INF;
            // if(not eq(res, calc(c, p3))) return INF;
            // if(not eq(res, calc(c, p1))) return INF;
            return res;
        };        
        double ans = INF;
        repeat(x1, -100, 100 + 1) {
            repeat(y1, -100, 100 + 1) {
                Point p1 = Point(x1, y1);
                if(ccw(a, c, p1) != COUNTER_CLOCK_WISE) continue;
                double l12 = length2(a - p1);
                double l1 = sqrt(l12);
                int y2_mx = min<int>(100, a.Y() + l1 + 0.5);
                int y2_mn = max<int>(-100, a.Y() - l1 - 0.5);               
                repeat(y2, y2_mn, y2_mx + 1) {
                    double dy = abs(a.Y() - y2);
                    double dx = sqrt(l12 - dy * dy);                    
                    for(Point p2_cand : {Point{a.X() + dx, (double)y2}, Point{a.X() - dx, (double)y2}}) {
                        Point p2 = nearest_grid_point(p2_cand);
                        if(abs(p2.X()) > 100 or abs(p2.Y()) > 100) continue;

                        if(not eq(length2(a - p2), l12)) continue;
                        if(ccw(b, a, p2) != COUNTER_CLOCK_WISE) continue;

                        if(p1 == p2) continue;
                        if(ccw(b, a, p1) == COUNTER_CLOCK_WISE and ccw(p2, a, p1) != COUNTER_CLOCK_WISE) continue;
                        
                        double l2 = distance(p1, c);
                        double l3 = distance(p2, b);

                        Point p3;

                        bool ok = false;
                        for(Point p3_cand : cross_points(Circle{c, l2}, Circle{b, l3})) {
                            p3 = nearest_grid_point(p3_cand);
                            if(abs(p3.X()) > 100 or abs(p3.Y()) > 100) continue;
                            if(ccw(c, b, p3) != COUNTER_CLOCK_WISE) continue;                            
                            if(p1 == p3 or p2 == p3) continue;
                            if(ccw(c, b, p2) == COUNTER_CLOCK_WISE and ccw(p3, b, p2) != COUNTER_CLOCK_WISE) continue;
                            if(ccw(a, c, p3) == COUNTER_CLOCK_WISE and ccw(p1, c, p3) != COUNTER_CLOCK_WISE) continue;
                            
                            if(eq(distance(c, p3), l2) and eq(distance(b, p3), l3)) {
                                ok = true;
                                break;
                            }
                        }
                        if(not ok) continue;
                        // assert(not does_include({a, c}, p1));
                        // assert(not does_include({b, c}, p2));
                        // assert(not does_include({c, a}, p3));
                        // assert(eq(distance(c, p3), l2) and eq(distance(b, p3), l3));
                        // assert(eq(distance(a, p1), l1) and eq(distance(c, p1), l2));
                        // assert(eq(distance(a, p2), l1) and eq(distance(b, p2), l3));
                        set_min(ans, calc_height(p1, p2, p3));
                    }
                }
            }
        }
        printf("%.10lf\n", (ans == INF ? -1 : ans));
        return 1;
    }
};

int main() {
    while(Solver().solve());
    return 0;
}
accuracy: 1
time_ms: 4620
memory_kb: 3324
final_rank: 5

code_snippet: #include<bits/stdc++.h>
   
#define EPS (1e-7)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1 
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
   
using namespace std;
   
class Point{
public:
  double x,y;
   
  Point(double x = 0,double y = 0): x(x),y(y){}
   
  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  Point operator * (Point a){ return Point(x * a.x - y * a.y, x * a.y + y * a.x); }
  bool operator < (const Point& p) const{ return !equals(x,p.x)?x<p.x:(!equals(y,p.y)&&y<p.y); }
  bool operator == (const Point& p)const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; }

};
   
struct Segment{
  Point p1,p2;
  Segment(Point p1 = Point(),Point p2 = Point()):p1(p1),p2(p2){}
  bool operator <  (const Segment& s) const { return ( p2 == s.p2 ) ? p1 < s.p1 : p2 < s.p2; }
  bool operator == (const Segment& s) const { return ( s.p1 == p1 && s.p2 == p2 ) || ( s.p1 == p2 && s.p2 == p1 ); }
   
};
   
typedef Point Vector;
typedef Segment Line;
typedef vector<Point> Polygon;
   
double dot(Point a,Point b){ return a.x*b.x + a.y*b.y; }
double cross(Point a,Point b){ return a.x*b.y - a.y*b.x; }
double norm(Point a){ return a.x*a.x+a.y*a.y; }
double abs(Point a){ return sqrt(norm(a)); }
Point rotate(Point a,double rad){ return Point(cos(rad)*a.x - sin(rad)*a.y,sin(rad)*a.x + cos(rad)*a.y); }
double toRad(double agl){ return agl*M_PI/180.0; }
   
int ccw(Point p0,Point p1,Point p2){
  Point a = p1-p0;
  Point b = p2-p0;
  if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
  if(cross(a,b) < -EPS)return CLOCKWISE;
  if(dot(a,b) < -EPS)return ONLINE_BACK;
  if(norm(a) < norm(b))return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool intersectSS(Line s, Line t) {
  return ccw(s.p1,s.p2,t.p1)*ccw(s.p1,s.p2,t.p2) <= 0 &&
         ccw(t.p1,t.p2,s.p1)*ccw(t.p1,t.p2,s.p2) <= 0;
}
   
Point projection(Line l,Point p) {
  double t = dot(p-l.p1, l.p1-l.p2) / norm(l.p1-l.p2);
  return l.p1 + (l.p1-l.p2)*t;
}

Point reflection(Line l,Point p) { return p + (projection(l, p) - p) * 2; }

Point crosspoint(Line l,Line m){
  double A = cross(l.p2-l.p1,m.p2-m.p1);
  double B = cross(l.p2-l.p1,l.p2-m.p1);
  if(abs(A) < EPS && abs(B) < EPS) return m.p1;
  if(abs(A) < EPS)assert(false);
  return m.p1 + (m.p2-m.p1)*(B/A);
}

double cross3p(Point p,Point q,Point r) { return (r.x-q.x) * (p.y -q.y) - (r.y - q.y) * (p.x - q.x); }
bool collinear(Point p,Point q,Point r) { return fabs(cross3p(p,q,r)) < EPS; }
bool onSegment(Point p,Point q,Point r){
  return collinear(p,q,r) && equals(sqrt(pow(p.x-r.x,2)+pow(p.y-r.y,2)) + sqrt(pow(r.x-q.x,2) + pow(r.y-q.y,2) ),sqrt(pow(p.x-q.x,2)+pow(p.y-q.y,2)) ) ;
}
   
double angle(Point a,Point b,Point c) {
  double ux = b.x - a.x, uy = b.y - a.y;
  double vx = c.x - a.x, vy = c.y - a.y;
  return acos((ux*vx + uy*vy)/sqrt((ux*ux + uy*uy) * (vx*vx + vy*vy)));
}  

bool inPolygon(Polygon &poly,Point p,bool onseg = true){
  if((int)poly.size() == 0)return false;
  if( onseg ) rep(i,(int)poly.size()) if(onSegment(poly[i],poly[(i+1)%(int)poly.size()],p))return true;
  double sum = 0;
  for(int i=0; i < (int)poly.size() ;i++) {
    if( equals(cross(poly[i]-p,poly[(i+1)%poly.size()]-p),0.0) ) continue;
    if( cross3p(p,poly[i],poly[(i+1)%poly.size()]) < 0 ) sum -= angle(p,poly[i],poly[(i+1)%poly.size()]);
    else                                                 sum += angle(p,poly[i],poly[(i+1)%poly.size()]);
  }
  const double eps = 1e-5;
  return (fabs(sum - 2*M_PI) < eps || fabs(sum + 2*M_PI) < eps);
}  
   
pair<Point, Point> crosspointCC( Point C1, double r1, Point C2, double r2) {
  complex<double> c1(C1.x,C1.y);
  complex<double> c2(C2.x,C2.y);
  complex<double> A = conj(c2-c1), B = (r2*r2-r1*r1-(c2-c1)*conj(c2-c1)), C = r1*r1*(c2-c1);
  complex<double> D = B*B-4.0*A*C;
  complex<double> z1 = (-B+sqrt(D))/(2.0*A)+c1, z2 = (-B-sqrt(D))/(2.0*A)+c1;
  return pair<Point, Point>(Point(z1.real(),z1.imag()),Point(z2.real(),z2.imag()));
}
   
// ------
   
bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }
   
bool isValid(Point p) { return LTE(-100.0,p.x) && LTE(p.x,100.0) && LTE(-100.0,p.y) && LTE(p.y,100.0); }

vector<Point> base(3),ps(3);

bool checkIntersect(Point p,Segment seg1,Segment seg2){

  rep(i,3) {
    Segment baseSeg = Segment(base[i],base[(i+1)%3]);
    if( equals(cross(baseSeg.p1-baseSeg.p2,seg1.p1-seg1.p2),0) &&
	equals(cross(baseSeg.p1-baseSeg.p2,seg2.p1-seg2.p2),0) ) return false;
  }

  Segment segs[2] = {seg1,seg2};
  rep(i,2){
    Segment seg = segs[i];
    rep(j,3){
      Segment baseSeg = Segment(base[j],base[(j+1)%3]);
      if( intersectSS(seg,baseSeg) ) {
	if( equals(cross(seg.p1-seg.p2,baseSeg.p1-baseSeg.p2),0) ) {
   
	  vector<Point> vec;
	  vec.push_back(seg.p1), vec.push_back(seg.p2), vec.push_back(baseSeg.p1), vec.push_back(baseSeg.p2);
	  sort(vec.begin(),vec.end());
	  vec.erase(unique(vec.begin(),vec.end()),vec.end());
	  rep(i,(int)vec.size()-1) {
	    Point mp = ( vec[i] + vec[i+1] ) / 2.0;
	    if( onSegment(seg.p1,seg.p2,mp) && onSegment(baseSeg.p1,baseSeg.p2,mp) ) return false;
	  }
	  continue;
	}
	Point cp = crosspoint(seg,baseSeg);
	if( !( cp == seg.p1 ) ) return false;
      }
    }
  }
  return true;
}
   
inline bool check(Point p,int j){
  if( !isValid(p) ) return false;
  double cs[3];
  rep(i,3) {
    if( onSegment(base[i],base[(i+1)%3],p) ) return false;
    Point a = base[(i+1)%3] - base[i];
    Point b = p - base[i];
    cs[i] = cross(a,b);
  }
  if( LT(cs[0],0) && LT(cs[1],0) && LT(cs[2],0) ) return false;
  if( LT(0,cs[0]) && LT(0,cs[1]) && LT(0,cs[2]) ) return false;
  if(!checkIntersect(p,Segment(base[j],p),Segment(base[(j+1)%3],p))) return false;
  return true;
}
   
bool FinalCheck(int limit = 3){
  Line lines[3][2];
  rep(i,limit) lines[i][0] = Line(base[i],ps[i]), lines[i][1] = Line(base[(i+1)%3],ps[i]);
  rep(i,limit) {
    REP(j,i+1,limit) {
      if( ps[i] == ps[j] ) return false;
      rep(k,2) {
    Segment ururu_beam1 = lines[i][k];
    rep(l,2){
      Segment ururu_beam2 = lines[j][l];
      if( intersectSS(ururu_beam1,ururu_beam2) ) {
        Point cp = crosspoint(ururu_beam1,ururu_beam2);
        if( cp == ururu_beam1.p1 && cp == ururu_beam2.p1 ) continue;
        return false;
      }
    }
      }
    }
  }
  return true;
}
   
double getH(){
  Line lines[3];
  for(short i=0;i<3;i++){
    Vector e = ( base[i] - base[(i+1)%3] ) / abs( base[i] - base[(i+1)%3] );
    e = rotate(e,toRad(90.0));
    lines[i] = Line(ps[i],ps[i]+e*1000);
  }

  Point cp = crosspoint(lines[0],lines[1]);
  for(short i=0;i<3;i++) if( cp == ps[i] ) return 1e30;
  Point onBaseP0 = crosspoint(lines[0],Line(base[0],base[1]));
  double a = abs(cp-onBaseP0);
  double b = abs(onBaseP0-ps[0]);
  if( equals(a,b) ) return 1e30;
  if( LTE(b,a) ) return 1e30;
  return sqrt(b*b-a*a);
}
   
void compute() {
  double mini = 1e30;
  REP(x1,-100,101){
    REP(y1,-100,101){
      ps[0] = Point(x1,y1); 
      if( !check(ps[0],0) ) continue;
      double lengthOfPs0ToBase1 = abs(ps[0]-base[1]);      
      for(int x2 = max(-100,(int)(base[1].x-lengthOfPs0ToBase1)); x2<=min(100,(int)(base[1].x+lengthOfPs0ToBase1));x2++ ) {
	double diff_x = abs(x2-base[1].x);
	if( LT(lengthOfPs0ToBase1,diff_x) ) continue;
	double diff_y = sqrt( lengthOfPs0ToBase1*lengthOfPs0ToBase1 - diff_x*diff_x );
   
	if( !equals(diff_y,(int)(diff_y+EPS)) ) continue;
	for(short coef=-1;coef<=1;coef+=2){ 
	  double y2 = base[1].y + diff_y * (double)coef;
	  if( !( equals(y2,(int)(y2+EPS)) || equals(y2,(int)(y2-EPS)) ) ) continue;
	  if( !check(Point(x2,y2),1) ) continue;
	  ps[1] = Point(x2,y2);
	  if( !FinalCheck(2) ) continue;
	  pair<Point,Point> tmp = crosspointCC(base[0],abs(ps[0]-base[0]),base[2],abs(ps[1]-base[2]));
	  Point tps[2] = {tmp.first,tmp.second};
	  for(short i=0;i<2;i++){
	    ps[2] = tps[i];
	    if( !( equals(ps[2].x,(int)(ps[2].x+EPS)) || equals(ps[2].x,(int)(ps[2].x-EPS)) ) || !( equals(ps[2].y,(int)(ps[2].y+EPS)) || equals(ps[2].y,(int)(ps[2].y-EPS)) ) ) continue;
	    if( !check(tps[i],2) ) continue;
	    if( !FinalCheck() ) continue;
	    double h = getH();
	    if( LT(h,mini) ) mini = h;
	  }
	}
      }
    }
  }
  if( equals(mini,1e30) ) puts("-1");
  else printf("%.10f\n",mini);
}
   
int main() {
  while( 1 ){
    bool fin = true;
    rep(i,3) {
      scanf("%lf %lf",&base[i].x,&base[i].y);
      if( !( base[i] == Point(0,0) ) ) fin = false;
    }
    if( fin ) break;
    compute();
  }
  return 0;
}
accuracy: 1
time_ms: 7090
memory_kb: 1276
final_rank: 9

code_snippet: #include<bits/stdc++.h>
  
#define EPS (1e-7)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1 
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
  
using namespace std;
  
class Point{
public:
  double x,y;
  
  Point(double x = 0,double y = 0): x(x),y(y){}
  
  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  Point operator * (Point a){ return Point(x * a.x - y * a.y, x * a.y + y * a.x); }
  
  bool operator < (const Point& p) const{ return !equals(x,p.x)?x<p.x:(!equals(y,p.y)&&y<p.y); }
  
  bool operator == (const Point& p)const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; }
  
};
  
struct Segment{
  Point p1,p2;
  Segment(Point p1 = Point(),Point p2 = Point()):p1(p1),p2(p2){}
  bool operator <  (const Segment& s) const { return ( p2 == s.p2 ) ? p1 < s.p1 : p2 < s.p2; }
  bool operator == (const Segment& s) const { return ( s.p1 == p1 && s.p2 == p2 ) || ( s.p1 == p2 && s.p2 == p1 ); }
  
};
  
typedef Point Vector;
typedef Segment Line;
typedef vector<Point> Polygon;
  
ostream& operator << (ostream& os,const Point& a){ os << "(" << a.x << "," << a.y << ")"; }
  
ostream& operator << (ostream& os,const Segment& a){ os << "( " << a.p1 << " , " << a.p2 << " )"; }
  
double dot(Point a,Point b){ return a.x*b.x + a.y*b.y; }
  
double cross(Point a,Point b){ return a.x*b.y - a.y*b.x; }
  
double norm(Point a){ return a.x*a.x+a.y*a.y; }
  
double abs(Point a){ return sqrt(norm(a)); }
  
//rad ??????§?????????????????¢???????§???????????????????¨
Point rotate(Point a,double rad){ return Point(cos(rad)*a.x - sin(rad)*a.y,sin(rad)*a.x + cos(rad)*a.y); }
  
// ????????????????¢????????????
double toRad(double agl){ return agl*M_PI/180.0; }
  
  
int ccw(Point p0,Point p1,Point p2){
  Point a = p1-p0;
  Point b = p2-p0;
  if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
  if(cross(a,b) < -EPS)return CLOCKWISE;
  if(dot(a,b) < -EPS)return ONLINE_BACK;
  if(norm(a) < norm(b))return ONLINE_FRONT;
  return ON_SEGMENT;
}
  
bool intersectLL(Line l, Line m) {
  return abs(cross(l.p2-l.p1, m.p2-m.p1)) > EPS || // non-parallel
         abs(cross(l.p2-l.p1, m.p1-l.p1)) < EPS;   // same line
}
bool intersectLS(Line l, Line s) {
  return cross(l.p2-l.p1, s.p1-l.p1)*       // s[0] is left of l
         cross(l.p2-l.p1, s.p2-l.p1) < EPS; // s[1] is right of l
}
bool intersectLP(Line l,Point p) {
  return abs(cross(l.p2-p, l.p1-p)) < EPS;
}
bool intersectSS(Line s, Line t) {
  return ccw(s.p1,s.p2,t.p1)*ccw(s.p1,s.p2,t.p2) <= 0 &&
         ccw(t.p1,t.p2,s.p1)*ccw(t.p1,t.p2,s.p2) <= 0;
}
bool intersectSP(Line s, Point p) {
  return abs(s.p1-p)+abs(s.p2-p)-abs(s.p2-s.p1) < EPS; // triangle inequality
}
  
Point projection(Line l,Point p) {
  double t = dot(p-l.p1, l.p1-l.p2) / norm(l.p1-l.p2);
  return l.p1 + (l.p1-l.p2)*t;
}
Point reflection(Line l,Point p) {
  return p + (projection(l, p) - p) * 2;
}
double distanceLP(Line l, Point p) {
  return abs(p - projection(l, p));
}
double distanceLL(Line l, Line m) {
  return intersectLL(l, m) ? 0 : distanceLP(l, m.p1);
}
  
double distanceLS(Line l, Line s) {
  if (intersectLS(l, s)) return 0;
  return min(distanceLP(l, s.p1), distanceLP(l, s.p2));
}
double distanceSP(Line s, Point p) {
  Point r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s.p1 - p), abs(s.p2 - p));
}
  
double distanceSS(Line s, Line t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t.p1), distanceSP(s, t.p2)),
             min(distanceSP(t, s.p1), distanceSP(t, s.p2)));
}
  
Point crosspoint(Line l,Line m){
  double A = cross(l.p2-l.p1,m.p2-m.p1);
  double B = cross(l.p2-l.p1,l.p2-m.p1);
  if(abs(A) < EPS && abs(B) < EPS){
    //vector<Point> vec;
    //vec.push_back(l.p1),vec.push_back(l.p2),vec.push_back(m.p1),vec.push_back(m.p2);
    //sort(vec.begin(),vec.end());
    //assert(vec[1] == vec[2]); //?????????????°??????????????????
    //return vec[1];
    //return m.p1;
    return m.p1;
  }
  if(abs(A) < EPS)assert(false);
  return m.p1 + (m.p2-m.p1)*(B/A);
}
  
  
//cross product of pq and pr
double cross3p(Point p,Point q,Point r) { return (r.x-q.x) * (p.y -q.y) - (r.y - q.y) * (p.x - q.x); }
    
//returns true if point r is on the same line as the line pq
bool collinear(Point p,Point q,Point r) { return fabs(cross3p(p,q,r)) < EPS; }
    
//returns true if point t is on the left side of line pq
bool ccwtest(Point p,Point q,Point r){
  return cross3p(p,q,r) > 0; //can be modified to accept collinear points
}
   
bool onSegment(Point p,Point q,Point r){
  return collinear(p,q,r) && equals(sqrt(pow(p.x-r.x,2)+pow(p.y-r.y,2)) + sqrt(pow(r.x-q.x,2) + pow(r.y-q.y,2) ),sqrt(pow(p.x-q.x,2)+pow(p.y-q.y,2)) ) ;
}
  
  
double angle(Point a,Point b,Point c) {
  double ux = b.x - a.x, uy = b.y - a.y;
  double vx = c.x - a.x, vy = c.y - a.y;
  return acos((ux*vx + uy*vy)/sqrt((ux*ux + uy*uy) * (vx*vx + vy*vy)));
}  
    
//??????§?????¢poly?????????????????????????????????p??????????¨??????????????????????????????  
bool inPolygon(Polygon &poly,Point p,bool onseg = true){
  if((int)poly.size() == 0)return false;
  if( onseg ) rep(i,(int)poly.size()) if(onSegment(poly[i],poly[(i+1)%(int)poly.size()],p))return true;
  double sum = 0;
  for(int i=0; i < (int)poly.size() ;i++) {
    if( equals(cross(poly[i]-p,poly[(i+1)%poly.size()]-p),0.0) ) continue; // ??????????????????????¨angle???nan?????????sum???nan????????????????¬
    if( cross3p(p,poly[i],poly[(i+1)%poly.size()]) < 0 ) sum -= angle(p,poly[i],poly[(i+1)%poly.size()]);
    else                                                 sum += angle(p,poly[i],poly[(i+1)%poly.size()]);
  }
  // ???????????????????????????????????????????¨???????????????????§??\????????????????????? 
  const double eps = 1e-5;
  return (fabs(sum - 2*M_PI) < eps || fabs(sum + 2*M_PI) < eps);
}  
  
pair<Point, Point> crosspointCC( Point C1, double r1, Point C2, double r2) {
  complex<double> c1(C1.x,C1.y);
  complex<double> c2(C2.x,C2.y);
  complex<double> A = conj(c2-c1), B = (r2*r2-r1*r1-(c2-c1)*conj(c2-c1)), C = r1*r1*(c2-c1);
  complex<double> D = B*B-4.0*A*C;
  complex<double> z1 = (-B+sqrt(D))/(2.0*A)+c1, z2 = (-B-sqrt(D))/(2.0*A)+c1;
  return pair<Point, Point>(Point(z1.real(),z1.imag()),Point(z2.real(),z2.imag()));
}
  
  
// ------
  
bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }
  
bool isValid(Point p) { return LTE(-100.0,p.x) && LTE(p.x,100.0) && LTE(-100.0,p.y) && LTE(p.y,100.0); }
  
vector<Point> base(3),ps(3);
  
Point vir;
bool cmp_dist(const Point &p1,const Point &p2) {
  return LT(abs(vir-p1),abs(vir-p2));
}
  
// seg.p1 ??? base ???????????????????§?????????????¨
// * 6
bool checkIntersect(Point p,Segment seg1,Segment seg2){
  
  // baseSeg ????¨ seg1 ????????? seg2 ????????????????¨???????°?????????????????????§?????¢???????????????
  rep(i,3) {
    Segment baseSeg = Segment(base[i],base[(i+1)%3]);
    if( equals(cross(baseSeg.p1-baseSeg.p2,seg1.p1-seg1.p2),0) &&
    equals(cross(baseSeg.p1-baseSeg.p2,seg2.p1-seg2.p2),0) ) return false;
  }
  
  // ???????§?????????????´?????????????§???????????????????§?????????????§??????????????????????????????§?????¢????¨????????????????????????????§????????????
  Segment segs[2] = {seg1,seg2};
  rep(i,2){
    Segment seg = segs[i];
    rep(j,3){
      Segment baseSeg = Segment(base[j],base[(j+1)%3]);
      if( intersectSS(seg,baseSeg) ) {
    if( equals(cross(seg.p1-seg.p2,baseSeg.p1-baseSeg.p2),0) ) {
    //if( equals(cross(seg.p1-seg.p2,baseSeg.p1-baseSeg.p2),0) && seg.p1 == baseSeg.p1 ) {
    //int res = ccw(seg.p1,seg.p2,baseSeg.p2);
    //if( res == ONLINE_FRONT || res == ON_SEGMENT ) return false;
  
      vector<Point> vec;
      vec.push_back(seg.p1);
      vec.push_back(seg.p2);
      vec.push_back(baseSeg.p1);
      vec.push_back(baseSeg.p2);
      sort(vec.begin(),vec.end());
      //vir = vec[0];
      //sort(vec.begin(),vec.end(),cmp_dist);
      vec.erase(unique(vec.begin(),vec.end()),vec.end());
      rep(i,(int)vec.size()-1) {
        Point mp = ( vec[i] + vec[i+1] ) / 2.0;
        if( onSegment(seg.p1,seg.p2,mp) && onSegment(baseSeg.p1,baseSeg.p2,mp) ) return false;
      }
  
  
      continue;
    }
    Point cp = crosspoint(seg,baseSeg);
    if( !( cp == seg.p1 ) ) return false;
      }
    }
  }
  
 
 
  return true;
}
  
inline bool check(Point p,int j){
  // ??????????????????????????????p??????????¨?????????
  if( !isValid(p) ) return false;
  
  // ??????????????????§?????¢????¨???????????????????????????§???????????°????????????
  
  // ??????????????????§?????¢???????????\???§????????????????????????????
  //if( inPolygon(base,p,true) ) return false;
  //return !inPolygon(base,p,true);
  double cs[3];
  
  rep(i,3) {
    if( onSegment(base[i],base[(i+1)%3],p) ) return false;
    Point a = base[(i+1)%3] - base[i];
    Point b = p - base[i];
    cs[i] = cross(a,b);
  }
  if( LT(cs[0],0) && LT(cs[1],0) && LT(cs[2],0) ) return false;
  if( LT(0,cs[0]) && LT(0,cs[1]) && LT(0,cs[2]) ) return false;
  
  if(!checkIntersect(p,Segment(base[j],p),Segment(base[(j+1)%3],p))) return false;
  
  return true;
  //return checkIntersect(p,Segment(base[i],p),Segment(base[(i+1)%3],p));
}
  
//?????????????????????????????????????????????????????????????????????????§??????
bool FinalCheck(int limit = 3){
  Line lines[3][2];
  rep(i,limit) lines[i][0] = Line(base[i],ps[i]), lines[i][1] = Line(base[(i+1)%3],ps[i]);
  rep(i,limit) {
    REP(j,i+1,limit) {
      if( ps[i] == ps[j] ) return false;
      rep(k,2) {
    Segment ururu_beam1 = lines[i][k];
    rep(l,2){
      Segment ururu_beam2 = lines[j][l];
      if( intersectSS(ururu_beam1,ururu_beam2) ) {
        Point cp = crosspoint(ururu_beam1,ururu_beam2);
        if( cp == ururu_beam1.p1 && cp == ururu_beam2.p1 ) continue;
        return false;
      }
    }
      }
    }
  }
  return true;
}
  
double getH(){
  
  Line lines[3];
  //rep(i,3){
  for(short i=0;i<3;i++){
    Vector e = ( base[i] - base[(i+1)%3] ) / abs( base[i] - base[(i+1)%3] );
    e = rotate(e,toRad(90.0));
    lines[i] = Line(ps[i],ps[i]+e*1000);
  }
  
  Point cp = crosspoint(lines[0],lines[1]);
  //rep(i,3) if( cp == ps[i] ) return 1e30;
  for(short i=0;i<3;i++) if( cp == ps[i] ) return 1e30;
    
  Point onBaseP0 = crosspoint(lines[0],Line(base[0],base[1]));
  
  double a = abs(cp-onBaseP0);
  double b = abs(onBaseP0-ps[0]);
  if( equals(a,b) ) return 1e30;
  if( LTE(b,a) ) return 1e30;
  
  return sqrt(b*b-a*a);
}
  
void compute() {
  double mini = 1e30;
    REP(x1,-100,101){
      REP(y1,-100,101){
      ps[0] = Point(x1,y1); 
      if( !check(ps[0],0) ) continue;
 
      double lengthOfPs0ToBase1 = abs(ps[0]-base[1]);      
      for(int x2 = max(-100,(int)(base[1].x-lengthOfPs0ToBase1)); x2<=min(100,(int)(base[1].x+lengthOfPs0ToBase1));x2++ ) {
    double diff_x = abs(x2-base[1].x);
    if( LT(lengthOfPs0ToBase1,diff_x) ) continue;
    double diff_y = sqrt( lengthOfPs0ToBase1*lengthOfPs0ToBase1 - diff_x*diff_x );
  
    if( !equals(diff_y,(int)(diff_y+EPS)) ) continue;
    for(short coef=-1;coef<=1;coef+=2){ // ??????£????????????????
      double y2 = base[1].y + diff_y * (double)coef;
      if( !( equals(y2,(int)(y2+EPS)) || equals(y2,(int)(y2-EPS)) ) ) continue;
      if( !check(Point(x2,y2),1) ) continue;
      ps[1] = Point(x2,y2);
      if( !FinalCheck(2) ) continue;
      pair<Point,Point> tmp = crosspointCC(base[0],abs(ps[0]-base[0]),base[2],abs(ps[1]-base[2]));
      Point tps[2] = {tmp.first,tmp.second};
      //bool succ = false;
      for(short i=0;i<2;i++){
        ps[2] = tps[i];
        if( !( equals(ps[2].x,(int)(ps[2].x+EPS)) || equals(ps[2].x,(int)(ps[2].x-EPS)) ) || !( equals(ps[2].y,(int)(ps[2].y+EPS)) || equals(ps[2].y,(int)(ps[2].y-EPS)) ) ) continue;
        if( !check(tps[i],2) ) continue;

  

        if( !FinalCheck() ) continue;
        double h = getH();
        if( LT(h,mini) ) mini = h;
        //if( !equals(h,1e30) ) { succ = true; break; }
      }
      //if( succ ) break;
    }
      }
    }
  }
  if( equals(mini,1e30) ) puts("-1");
  else printf("%.10f\n",mini);
}
  
int main() {
  while( 1 ){
    bool fin = true;
    //rep(i,3) {
    for(short i=0;i<3;i++){
      scanf("%lf %lf",&base[i].x,&base[i].y);
      if( !( base[i] == Point(0,0) ) ) fin = false;
    }
    if( fin ) break;
    compute();
  }
  return 0;
}
accuracy: 1
time_ms: 7160
memory_kb: 1276
final_rank: 10

code_snippet: #include<bits/stdc++.h>

#define EPS (1e-7)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1 
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

class Point{
public:
  double x,y;

  Point(double x = 0,double y = 0): x(x),y(y){}

  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  Point operator * (Point a){ return Point(x * a.x - y * a.y, x * a.y + y * a.x); }

  bool operator < (const Point& p) const{ return !equals(x,p.x)?x<p.x:(!equals(y,p.y)&&y<p.y); }

  bool operator == (const Point& p)const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; }

};

struct Segment{
  Point p1,p2;
  Segment(Point p1 = Point(),Point p2 = Point()):p1(p1),p2(p2){}
  bool operator <  (const Segment& s) const { return ( p2 == s.p2 ) ? p1 < s.p1 : p2 < s.p2; }
  bool operator == (const Segment& s) const { return ( s.p1 == p1 && s.p2 == p2 ) || ( s.p1 == p2 && s.p2 == p1 ); }

};

typedef Point Vector;
typedef Segment Line;
typedef vector<Point> Polygon;

ostream& operator << (ostream& os,const Point& a){ os << "(" << a.x << "," << a.y << ")"; }

ostream& operator << (ostream& os,const Segment& a){ os << "( " << a.p1 << " , " << a.p2 << " )"; }

double dot(Point a,Point b){ return a.x*b.x + a.y*b.y; }

double cross(Point a,Point b){ return a.x*b.y - a.y*b.x; }

double norm(Point a){ return a.x*a.x+a.y*a.y; }

double abs(Point a){ return sqrt(norm(a)); }

//rad ????§???????????????¢?????§?????????????????¨
Point rotate(Point a,double rad){ return Point(cos(rad)*a.x - sin(rad)*a.y,sin(rad)*a.x + cos(rad)*a.y); }

// ??????????????¢????????????
double toRad(double agl){ return agl*M_PI/180.0; }


int ccw(Point p0,Point p1,Point p2){
  Point a = p1-p0;
  Point b = p2-p0;
  if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
  if(cross(a,b) < -EPS)return CLOCKWISE;
  if(dot(a,b) < -EPS)return ONLINE_BACK;
  if(norm(a) < norm(b))return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool intersectLL(Line l, Line m) {
  return abs(cross(l.p2-l.p1, m.p2-m.p1)) > EPS || // non-parallel
         abs(cross(l.p2-l.p1, m.p1-l.p1)) < EPS;   // same line
}
bool intersectLS(Line l, Line s) {
  return cross(l.p2-l.p1, s.p1-l.p1)*       // s[0] is left of l
         cross(l.p2-l.p1, s.p2-l.p1) < EPS; // s[1] is right of l
}
bool intersectLP(Line l,Point p) {
  return abs(cross(l.p2-p, l.p1-p)) < EPS;
}
bool intersectSS(Line s, Line t) {
  return ccw(s.p1,s.p2,t.p1)*ccw(s.p1,s.p2,t.p2) <= 0 &&
         ccw(t.p1,t.p2,s.p1)*ccw(t.p1,t.p2,s.p2) <= 0;
}
bool intersectSP(Line s, Point p) {
  return abs(s.p1-p)+abs(s.p2-p)-abs(s.p2-s.p1) < EPS; // triangle inequality
}

Point projection(Line l,Point p) {
  double t = dot(p-l.p1, l.p1-l.p2) / norm(l.p1-l.p2);
  return l.p1 + (l.p1-l.p2)*t;
}
Point reflection(Line l,Point p) {
  return p + (projection(l, p) - p) * 2;
}
double distanceLP(Line l, Point p) {
  return abs(p - projection(l, p));
}
double distanceLL(Line l, Line m) {
  return intersectLL(l, m) ? 0 : distanceLP(l, m.p1);
}

double distanceLS(Line l, Line s) {
  if (intersectLS(l, s)) return 0;
  return min(distanceLP(l, s.p1), distanceLP(l, s.p2));
}
double distanceSP(Line s, Point p) {
  Point r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s.p1 - p), abs(s.p2 - p));
}

double distanceSS(Line s, Line t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t.p1), distanceSP(s, t.p2)),
             min(distanceSP(t, s.p1), distanceSP(t, s.p2)));
}

Point crosspoint(Line l,Line m){
  double A = cross(l.p2-l.p1,m.p2-m.p1);
  double B = cross(l.p2-l.p1,l.p2-m.p1);
  if(abs(A) < EPS && abs(B) < EPS){
    vector<Point> vec;
    vec.push_back(l.p1),vec.push_back(l.p2),vec.push_back(m.p1),vec.push_back(m.p2);
    sort(vec.begin(),vec.end());
    assert(vec[1] == vec[2]); //???????????°??????????????????
    return vec[1];
    //return m.p1;
  }
  if(abs(A) < EPS)assert(false);
  return m.p1 + (m.p2-m.p1)*(B/A);
}


//cross product of pq and pr
double cross3p(Point p,Point q,Point r) { return (r.x-q.x) * (p.y -q.y) - (r.y - q.y) * (p.x - q.x); }
  
//returns true if point r is on the same line as the line pq
bool collinear(Point p,Point q,Point r) { return fabs(cross3p(p,q,r)) < EPS; }
  
//returns true if point t is on the left side of line pq
bool ccwtest(Point p,Point q,Point r){
  return cross3p(p,q,r) > 0; //can be modified to accept collinear points
}
 
bool onSegment(Point p,Point q,Point r){
  return collinear(p,q,r) && equals(sqrt(pow(p.x-r.x,2)+pow(p.y-r.y,2)) + sqrt(pow(r.x-q.x,2) + pow(r.y-q.y,2) ),sqrt(pow(p.x-q.x,2)+pow(p.y-q.y,2)) ) ;
}


double angle(Point a,Point b,Point c) {
  double ux = b.x - a.x, uy = b.y - a.y;
  double vx = c.x - a.x, vy = c.y - a.y;
  return acos((ux*vx + uy*vy)/sqrt((ux*ux + uy*uy) * (vx*vx + vy*vy)));
}  
  
//????§???¢poly?????????????????????????????????p????????¨??????????????????????????????  
bool inPolygon(Polygon &poly,Point p,bool onseg = true){
  if((int)poly.size() == 0)return false;
  if( onseg ) rep(i,(int)poly.size()) if(onSegment(poly[i],poly[(i+1)%(int)poly.size()],p))return true;
  double sum = 0;
  for(int i=0; i < (int)poly.size() ;i++) {
    if( equals(cross(poly[i]-p,poly[(i+1)%poly.size()]-p),0.0) ) continue; // ????????????????????¨angle???nan?????????sum???nan??????????????¬
    if( cross3p(p,poly[i],poly[(i+1)%poly.size()]) < 0 ) sum -= angle(p,poly[i],poly[(i+1)%poly.size()]);
    else                                                 sum += angle(p,poly[i],poly[(i+1)%poly.size()]);
  }
  // ?????????????????????????????????????????¨?????????????????§??\????????????????????? 
  const double eps = 1e-5;
  return (fabs(sum - 2*M_PI) < eps || fabs(sum + 2*M_PI) < eps);
}  

pair<Point, Point> crosspointCC( Point C1, double r1, Point C2, double r2) {
  complex<double> c1(C1.x,C1.y);
  complex<double> c2(C2.x,C2.y);
  complex<double> A = conj(c2-c1), B = (r2*r2-r1*r1-(c2-c1)*conj(c2-c1)), C = r1*r1*(c2-c1);
  complex<double> D = B*B-4.0*A*C;
  complex<double> z1 = (-B+sqrt(D))/(2.0*A)+c1, z2 = (-B-sqrt(D))/(2.0*A)+c1;
  return pair<Point, Point>(Point(z1.real(),z1.imag()),Point(z2.real(),z2.imag()));
}


// ------

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

bool isValid(Point p) { return LTE(-100.0,p.x) && LTE(p.x,100.0) && LTE(-100.0,p.y) && LTE(p.y,100.0); }

vector<Point> base(3),ps(3);

Point vir;
bool cmp_dist(const Point &p1,const Point &p2) {
  return LT(abs(vir-p1),abs(vir-p2));
}

// seg.p1 ??? base ?????????????????§???????????¨
// * 6
bool checkIntersect(Point p,Segment seg1,Segment seg2){

  // baseSeg ??¨ seg1 ????????? seg2 ??????????????¨?????°???????????????????§???¢???????????????
  rep(i,3) {
    Segment baseSeg = Segment(base[i],base[(i+1)%3]);
    if( equals(cross(baseSeg.p1-baseSeg.p2,seg1.p1-seg1.p2),0) &&
	equals(cross(baseSeg.p1-baseSeg.p2,seg2.p1-seg2.p2),0) ) return false;
  }

  // ?????§???????????´???????????§?????????????????§???????????§????????????????????????????§???¢??¨??????????????????????????§????????????
  Segment segs[2] = {seg1,seg2};
  rep(i,2){
    Segment seg = segs[i];
    rep(j,3){
      Segment baseSeg = Segment(base[j],base[(j+1)%3]);
      if( intersectSS(seg,baseSeg) ) {
	if( equals(cross(seg.p1-seg.p2,baseSeg.p1-baseSeg.p2),0) ) {
	//if( equals(cross(seg.p1-seg.p2,baseSeg.p1-baseSeg.p2),0) && seg.p1 == baseSeg.p1 ) {
	//int res = ccw(seg.p1,seg.p2,baseSeg.p2);
	//if( res == ONLINE_FRONT || res == ON_SEGMENT ) return false;

	  vector<Point> vec;
	  vec.push_back(seg.p1);
	  vec.push_back(seg.p2);
	  vec.push_back(baseSeg.p1);
	  vec.push_back(baseSeg.p2);
	  sort(vec.begin(),vec.end());
	  //vir = vec[0];
	  //sort(vec.begin(),vec.end(),cmp_dist);
	  vec.erase(unique(vec.begin(),vec.end()),vec.end());
	  rep(i,(int)vec.size()-1) {
	    Point mp = ( vec[i] + vec[i+1] ) / 2.0;
	    if( onSegment(seg.p1,seg.p2,mp) && onSegment(baseSeg.p1,baseSeg.p2,mp) ) return false;
	  }


	  continue;
	}
	Point cp = crosspoint(seg,baseSeg);
	if( !( cp == seg.p1 ) ) return false;
      }
    }
  }

  return true;
}

inline bool check(Point p,int j){
  // ??????????????????????????????p????????¨?????????
  if( !isValid(p) ) return false;

  // ????????????????§???¢??¨?????????????????????????§?????????°????????????



  // ????????????????§???¢???????????\?§????????????????????????????
  //if( inPolygon(base,p,true) ) return false;
  //return !inPolygon(base,p,true);
  double cs[3];

  rep(i,3) {
    if( onSegment(base[i],base[(i+1)%3],p) ) return false;
    Point a = base[(i+1)%3] - base[i];
    Point b = p - base[i];
    cs[i] = cross(a,b);
  }
  if( LT(cs[0],0) && LT(cs[1],0) && LT(cs[2],0) ) return false;
  if( LT(0,cs[0]) && LT(0,cs[1]) && LT(0,cs[2]) ) return false;

  if(!checkIntersect(p,Segment(base[j],p),Segment(base[(j+1)%3],p))) return false;

  return true;
  //return checkIntersect(p,Segment(base[i],p),Segment(base[(i+1)%3],p));
}

//???????????????????????????????????????????????????????????????????????§??????
bool FinalCheck(int limit = 3){
  Line lines[3][2];
  rep(i,limit) lines[i][0] = Line(base[i],ps[i]), lines[i][1] = Line(base[(i+1)%3],ps[i]);
  rep(i,limit) {
    REP(j,i+1,limit) {
      if( ps[i] == ps[j] ) return false;
      rep(k,2) {
	Segment ururu_beam1 = lines[i][k];
	rep(l,2){
	  Segment ururu_beam2 = lines[j][l];
	  if( intersectSS(ururu_beam1,ururu_beam2) ) {
	    Point cp = crosspoint(ururu_beam1,ururu_beam2);
	    if( cp == ururu_beam1.p1 && cp == ururu_beam2.p1 ) continue;
	    return false;
	  }
	}
      }
    }
  }
  return true;
}

double getH(){

  Line lines[3];
  rep(i,3){
    Vector e = ( base[i] - base[(i+1)%3] ) / abs( base[i] - base[(i+1)%3] );
    e = rotate(e,toRad(90.0));
    lines[i] = Line(ps[i],ps[i]+e*1000);
  }

  Point cp = crosspoint(lines[0],lines[1]);
  rep(i,3) if( cp == ps[i] ) return 1e30;
  
  Point onBaseP0 = crosspoint(lines[0],Line(base[0],base[1]));

  double a = abs(cp-onBaseP0);
  double b = abs(onBaseP0-ps[0]);
  if( equals(a,b) ) return 1e30;
  if( LTE(b,a) ) return 1e30;

  return sqrt(b*b-a*a);
}

void compute() {
  double mini = 1e30;
    REP(x1,-100,101){
  REP(y1,-100,101){
if(y1==-21||y1==66)continue;
      if( !check(Point(x1,y1),0) ) continue;
      ps[0] = Point(x1,y1);
      double lengthOfPs0ToBase1 = abs(ps[0]-base[1]);      
      //REP(x2,-100,101){
      for(int x2 = max(-100,(int)(base[1].x-lengthOfPs0ToBase1)); x2<=min(100,(int)(base[1].x+lengthOfPs0ToBase1));x2++ ) {
	double diff_x = abs(x2-base[1].x);
	if( LT(lengthOfPs0ToBase1,diff_x) ) continue;
	double diff_y = sqrt( lengthOfPs0ToBase1*lengthOfPs0ToBase1 - diff_x*diff_x );

	if( !equals(diff_y,(int)(diff_y+EPS)) ) continue;
	for(int coef=-1;coef<=1;coef+=2){ // ????£????????????????
	  double y2 = base[1].y + diff_y * (double)coef;
	  if( !( equals(y2,(int)(y2+EPS)) || equals(y2,(int)(y2-EPS)) ) ) continue;
	  if( !check(Point(x2,y2),1) ) continue;
	  ps[1] = Point(x2,y2);
	  if( !FinalCheck(2) ) continue;
	  pair<Point,Point> tmp = crosspointCC(base[0],abs(ps[0]-base[0]),base[2],abs(ps[1]-base[2]));
	  Point tps[2] = {tmp.first,tmp.second};
	  bool succ = false;
	  rep(i,2){
	    if( !check(tps[i],2) ) continue;
	    ps[2] = tps[i];

	    if( !( equals(ps[2].x,(int)(ps[2].x+EPS)) || equals(ps[2].x,(int)(ps[2].x-EPS)) ) || !( equals(ps[2].y,(int)(ps[2].y+EPS)) || equals(ps[2].y,(int)(ps[2].y-EPS)) ) ) continue;
	    if( !FinalCheck() ) continue;
	    double h = getH();
	    if( LT(h,mini) ) mini = h;
	    if( !equals(h,1e30) ) { succ = true; break; }
	  }
	  if( succ ) break;
	}
      }
    }
  }
  if( equals(mini,1e30) ) puts("-1");
  else printf("%.10f\n",mini);
}

int main() {
  while( 1 ){
    bool fin = true;
    rep(i,3) {
      scanf("%lf %lf",&base[i].x,&base[i].y);
      if( !( base[i] == Point(0,0) ) ) fin = false;
    }
    if( fin ) break;
    compute();
  }
  return 0;
}
accuracy: 1
time_ms: 7970
memory_kb: 1280
final_rank: 19

code_snippet: #include<cstdio>
#include<vector>
#include<utility>
#include<complex>
#include<cmath>
#include<algorithm>

using namespace std;

typedef double Real;
typedef pair<int,int> P;

vector<P> dirs[200*200*2+1];

int crP(int x1,int y1,int x2,int y2){
	return x1*y2-x2*y1;
}

void init_dir(){
	for(int x=-200;x<=200;x++) for(int y=-200;y<=200;y++){
		dirs[x*x+y*y].push_back(P(x,y));
	}
}

Real getHeight(Real a,Real b,Real c){
	Real y=(a + (b*b-c*c)/a)/2;
	return sqrt(b*b-y*y);
}

Real getH2(Real a,Real b,Real c){
	Real y = (a + (b*b-c*c)/a)/2;
	return a-y;
}

const Real eps = 1e-8;

int cnt=0;
Real getHeight(Real a,Real b,Real c,Real d,Real e,Real f){
//	printf("%f %f %f %f %f %f\n",a,b,c,d,e,f);
	Real h_=getHeight(a,d,f);
	Real x=getH2(a,d,f);
	Real h2=getHeight(a,b,c);
	Real y=getH2(a,b,c);
	Real p=y-x;
	Real q=h2-h_;
	Real val = -(e*e - h_*h_ - (h_+q)*(h_+q) - p*p) / (2.0 * (h_+q) * h_);
	if(abs(val) >= 1.0 - eps) return -1;
//	printf("%f %f %f %f %f %f %f %f\n",h_,x,h2,y,p,q,val,h_*sqrt(1-val*val));
//	if(++cnt>10) exit(0);
	return h_ * sqrt(1-val*val);
}

bool sameSide(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4){
	int p3 = crP(x2-x1,y2-y1,x3-x2,y3-y2);
	int p4 = crP(x2-x1,y2-y1,x4-x2,y4-y2);
	return p3*p4>=0;
}

int dis2(int x1,int y1,int x2,int y2){
	return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
}

Real dis(int x1,int y1,int x2,int y2){
	return sqrt(dis2(x1,y1,x2,y2));
}

bool check(int x){
	return x>=-100&&x<=100;
}

Real solve(int x1,int y1,int x2,int y2,int x3,int y3){
	Real a=dis(x1,y1,x2,y2);
	Real b=dis(x2,y2,x3,y3);
	Real c=dis(x3,y3,x1,y1);
	Real res = -1;
	for(int x4=-100;x4<=100;x4++) for(int y4=-100;y4<=100;y4++){
		if(sameSide(x1,y1,x2,y2,x3,y3,x4,y4)) continue;
		int d2=dis2(x2,y2,x4,y4);
		Real d=sqrt(d2);
		int f2=dis2(x1,y1,x4,y4);
		Real f=sqrt(f2);
		for(int i = 0; i < dirs[d2].size(); i++){
			for(int j = 0; j < dirs[f2].size(); j++){
				int x5 = x2 + dirs[d2][i].first;
				int y5 = y2 + dirs[d2][i].second;
				int x6 = x1 + dirs[f2][j].first;
				int y6 = y1 + dirs[f2][j].second;
				if((!check(x5)) || (!check(y5)) || (!check(x6)) || (!check(y6))) continue;
				if(sameSide(x2,y2,x3,y3,x1,y1,x5,y5)) continue;
				if(sameSide(x3,y3,x1,y1,x2,y2,x6,y6)) continue;
				int e2 = dis2(x3,y3,x6,y6);
				if(e2 != dis2(x3,y3,x5,y5)) continue;
				Real e = sqrt(e2);
				Real h = getHeight(a,b,c,d,e,f);
				if(h > 0 && (res < 0 || res > h)) res = h;
	//			if(d2==5&&e2==5) printf("%d %d %d %f\n",d2,e2,f2,h);
			}
		}
	}
	return res;
}

int main(){
	init_dir();
	while(true){
		int x1,y1,x2,y2,x3,y3;
		scanf("%d%d%d%d%d%d2",&x1,&y1,&x2,&y2,&x3,&y3);
		if(x1==0&&y1==0&&x2==0&&y2==0&&x3==0&&y3==0) break;
		Real ans = solve(x1,y1,x2,y2,x3,y3);
		if(ans < 0) printf("-1\n");
		else printf("%.9f\n",ans);
//		break;
	}
	return 0;
}
accuracy: 1
time_ms: 1230
memory_kb: 4440
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <complex>

using namespace std;

typedef complex<double> P;
typedef pair<P,double> circle;
struct L { P p, q; L(P p, P q) : p(p), q(q) {} };

template <class T>
inline const T& abs(const T& a)
{
	return a > 0 ? a : -a;
}

const double EPS = 1e-8;

double dot(P a, P b) { return real(conj(a)*b); }
double cross(P a, P b) { return imag(conj(a)*b); }

P footPerp(L l, P p) {
	return l.p + (l.q-l.p) * dot(l.q-l.p, p-l.p) / norm(l.q-l.p);
}

double lenPerp(L l, P p){
	return abs(footPerp(l, p)-p);
}

P ssCrosspoint(L a, L b){
	double A = cross(a.q-a.p, b.q-b.p);
	double B = cross(a.q-a.p, a.q-b.p);
	return b.p + B/A * (b.q-b.p);
}

bool crossCircle(circle c1, circle c2){
	double r1 = c1.second;
	double r2 = c2.second;
	double d = abs(c1.first-c2.first);
	if(d<r1||d<r2)
		return d-abs(r1-r2)>EPS;
	return r1+r2-d>-EPS;
}

vector<P> crossPoint(circle c1, circle c2){
	vector<P> res;
	double r1 = c1.second;
	double r2 = c2.second;
	double r3 = abs(c1.first-c2.first);
	double rc = (r3*r3+r1*r1-r2*r2)/(2*r3);
	double rs = sqrt(r1*r1-rc*rc);
	P dif = (c2.first-c1.first)/r3;
	res.push_back(c1.first+dif*P(rc,rs));
	if(abs(rs) > EPS) res.push_back(c1.first+dif*P(rc,-rs));
	return res;
}

int main(){
	int x1, y1, x2, y2, x3, y3;
	while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3, x1|y1|x2|y2|x3|y3){
		x1 += 100, y1 += 100;
		x2 += 100, y2 += 100;
		x3 += 100, y3 += 100;
		while(x1-x2>0){
			int tmp = x1; x1 = x2; x2 = x3; x3 = tmp;
			    tmp = y1; y1 = y2; y2 = y3; y3 = tmp;
		}
		P p1 = P(x1, y1), p2 = P(x2, y2), p3 = P(x3, y3);
		double res = 1e12;
		int cnt = 0;
		for(int xa=0;xa<=200;xa++){
			for(int ya=0;ya<=200;ya++){
				if(cross(p2-p1, P(xa,ya)-p1) > -EPS) break;
				double len = abs(P(xa,ya)-p2);
				int r1 = int(len+EPS);
				for(int xb=max(0,x2-r1);xb<=min(200,x2+r1);xb++){
					if(len < abs(x2-xb)) continue;
					double dsq = sqrt(len*len-(x2-xb)*(x2-xb));
					int sqt = int(dsq+EPS);
					if(abs(dsq-sqt) > EPS) continue;
					for(int sgn=-1;sgn<=1;sgn+=2){
						int yb = sgn*sqt + y2;
						if(yb < 0 || 200 < yb) continue;
						if(abs(abs(p2-P(xb,yb)) - len) > EPS || abs(P(xb,yb)-P(xa,ya)) < EPS) continue;
						if(cross(p3-p2, P(xb,yb)-p2) > -EPS) continue;
						circle ca = make_pair(p1, abs(p1-P(xa,ya)));
						circle cb = make_pair(p3, abs(p3-P(xb,yb)));

						P pt = ssCrosspoint(L(P(xa,ya), P(xa,ya)+P(0,1)*(p2-p1)), L(P(xb,yb), P(xb,yb)+P(0,1)*(p3-p2)));
						double la = lenPerp(L(p1,p2), P(xa,ya));
						double lb = lenPerp(L(p1,p2), pt);
						if(la*la-lb*lb < EPS) continue;
						if(sqrt(la*la-lb*lb) > res) continue;

						if(!crossCircle(ca, cb)) continue;
						vector<P> cp = crossPoint(ca, cb);
						for(int i=0;i<cp.size();i++){
							int xc = cp[i].real()+0.5;
							int yc = cp[i].imag()+0.5;
							if(xc < 0 || 200 < xc || yc < 0 || 200 < yc) continue;
							if(cross(p1-p3, P(xc,yc)-p3) > -EPS) continue;
							if(abs(P(xc,yc)-cp[i]) > EPS) continue;
							res = min(res, sqrt(la*la-lb*lb));
						}
					}
				}
			}
		}
		if(res < 1e10) printf("%.7lf\n", res);
		else           puts("-1");
	}
}
accuracy: 1
time_ms: 6250
memory_kb: 988
final_rank: 2

code_snippet: #include <iostream>
#include <vector>
#include <complex>

using namespace std;

typedef complex<double> P;
typedef pair<P,double> circle;
struct L { P p, q; L(P p, P q) : p(p), q(q) {} };

template <class T>
inline const T& abs(const T& a)
{
	return a > 0 ? a : -a;
}

const double EPS = 1e-8;

double dot(P a, P b) { return real(conj(a)*b); }
double cross(P a, P b) { return imag(conj(a)*b); }

P footPerp(L l, P p) {
	return l.p + (l.q-l.p)*(dot(l.q-l.p, p-l.p) / (abs(l.q-l.p)*abs(l.q-l.p)));
}

double lenPerp(L l, P p){
	return abs(footPerp(l, p)-p);
}

P ssCrosspoint(L a, L b){
	double A = cross(a.q-a.p, b.q-b.p);
	double B = cross(a.q-a.p, a.q-b.p);
	return b.p + B/A * (b.q-b.p);
}

bool crossCircle(circle c1, circle c2){
	double r1 = c1.second;
	double r2 = c2.second;
	double d = abs(c1.first-c2.first);
	if(d<r1||d<r2)
		return d-abs(r1-r2)>EPS;
	return r1+r2-d>-EPS;
}

vector<P> crossPoint(circle c1, circle c2){
	vector<P> res;
	double r1 = c1.second;
	double r2 = c2.second;
	double r3 = abs(c1.first-c2.first);
	double rc = (r3*r3+r1*r1-r2*r2)/(2*r3);
	double rs = sqrt(r1*r1-rc*rc);
	P dif = (c2.first-c1.first)/r3;
	res.push_back(c1.first+dif*P(rc,rs));
	if(abs(rs) > EPS) res.push_back(c1.first+dif*P(rc,-rs));
	return res;
}

int main(){
	int x1, y1, x2, y2, x3, y3;
	while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3, x1|y1|x2|y2|x3|y3){
		x1 += 100, y1 += 100;
		x2 += 100, y2 += 100;
		x3 += 100, y3 += 100;
		while(x1-x2>0){
			int tmp = x1; x1 = x2; x2 = x3; x3 = tmp;
			    tmp = y1; y1 = y2; y2 = y3; y3 = tmp;
		}
		P p1 = P(x1, y1), p2 = P(x2, y2), p3 = P(x3, y3);
		double res = 1e12;
		int cnt = 0;
		for(int xa=0;xa<=200;xa++){
			for(int ya=0;ya<=200;ya++){
				if(cross(p2-p1, P(xa,ya)-p1) > -EPS) break;
				double len = abs(P(xa,ya)-p2);
				int r1 = int(len+EPS);
				for(int xb=max(0,x2-r1);xb<=min(200,x2+r1);xb++){
					if(len < abs(x2-xb)) continue;
					double dsq = sqrt(len*len-(x2-xb)*(x2-xb));
					int sqt = int(dsq+EPS);
					if(abs(dsq-sqt) > EPS) continue;
					for(int sgn=-1;sgn<=1;sgn+=2){
						int yb = sgn*sqt + y2;
						if(yb < 0 || 200 < yb) continue;
						if(abs(abs(p2-P(xb,yb)) - len) > EPS || abs(P(xb,yb)-P(xa,ya)) < EPS) continue;
						if(cross(p3-p2, P(xb,yb)-p2) > -EPS) continue;
						circle ca = make_pair(p1, abs(p1-P(xa,ya)));
						circle cb = make_pair(p3, abs(p3-P(xb,yb)));

						P pt = ssCrosspoint(L(P(xa,ya), P(xa,ya)+P(0,1)*(p2-p1)), L(P(xb,yb), P(xb,yb)+P(0,1)*(p3-p2)));
						double la = lenPerp(L(p1,p2), P(xa,ya));
						double lb = lenPerp(L(p1,p2), pt);
						if(la*la-lb*lb < EPS) continue;
						if(sqrt(la*la-lb*lb) > res) continue;

						if(!crossCircle(ca, cb)) continue;
						vector<P> cp = crossPoint(ca, cb);
						for(int i=0;i<cp.size();i++){
							int xc = cp[i].real()+0.5;
							int yc = cp[i].imag()+0.5;
							if(xc < 0 || 200 < xc || yc < 0 || 200 < yc) continue;
							if(cross(p1-p3, P(xc,yc)-p3) > -EPS) continue;
							if(abs(P(xc,yc)-cp[i]) > EPS) continue;
							res = min(res, sqrt(la*la-lb*lb));
						}
					}
				}
			}
		}
		if(res < 1e10) printf("%.7lf\n", res);
		else           puts("-1");
	}
}
accuracy: 1
time_ms: 6260
memory_kb: 984
final_rank: 3

code_snippet: #include<iostream>
#include<complex>
#include<cmath>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define mp         make_pair

const double eps = 1e-10;

typedef complex<int> P;
typedef complex<double> DP;

class Tri{
public:
  int x[3],y[3];
};

inline double compute_dist(double x,double y){
  return sqrt(x*x+y*y);
}

int double_to_int(double &a){
  if (a <0)return (int)(a-0.5);
  else return     (int)(a+0.5);
}

bool isint(double a){
  if (a <0){
    if ( fabs((int)(a-0.5)-a)<eps)return true;
  }else {
    if ( fabs((int)(a+0.5)-a)<eps)return true;
  }
  return false;
}

double myabs(P a){
  return sqrt(a.real()*a.real()+a.imag()*a.imag());
}

inline void CC_intersection(int &ax,int &ay,int &bx,int &by,double &r1,double &r2,double &d,
			    double &x1,double &y1,double &x2,double &y2){
  double l,m,n;
  double x,y;
  double p,q;
  l=(d*d-r2*r2+r1*r1)/(2*d);
  
  x=ax+(bx-ax)*l/d;
  y=ay+(by-ay)*l/d;
  n=sqrt(r1*r1-l*l);
  p=(by-ay)/d*n;
  q=(bx-ax)/d*n;
  
  x1=x+p;
  y1=y-q;

  x2=x-p;
  y2=y+q;
}

int is_intersected_circle(int &ax,int &ay,int &bx,int &by,
			  double &r1,double& r2,double &d){
  d = compute_dist(ax-bx,ay-by);
  if (d<eps && fabs(r1-r2)<eps)return 3;
  if (d+r2 < r1)return 0;
  if (d+r1 < r2)return 1;
  if (d > r1+r2)return 4;
  return 2;
}

inline double cross(double ax,double ay,double bx,double by){
  return ax*by - ay*bx;
}

inline double dot(double ax,double ay,double bx,double by){
  return ax*bx+ay*by;}

inline bool isp(int &ax,int & ay,int & bx,int & by,int & cx,int & cy){
  double tmp1=cross(bx-ax,by-ay,cx-ax,cy-ay);
  double tmp2=dot(bx-ax,by-ay,cx-ax,cy-ay);
  return tmp1<eps&&tmp1>-eps&&tmp2<eps&&tmp2>-eps;
}

inline bool is_intersected_ls(int &a1x,int &a1y,int &a2x,int &a2y,int &b1x,int &b1y,int &b2x,int &b2y){
  if (  ( cross(a2x-a1x,a2y-a1y,b1x-a1x,b1y-a1y)*cross(a2x-a1x,a2y-a1y,b2x-a1x,b2y-a1y)<-eps) && 
	( cross(b2x-b1x,b2y-b1y,a1x-b1x,a1y-b1y)*cross(b2x-b1x,b2y-b1y,a2x-b1x,a2y-b1y)<-eps))
    return true;
  return false;
}

inline bool is_in(int *inx,int *iny,int &ax,int& ay){
  int cnt =0;
  int n = 3;
  rep(i,n){
    int curx=inx[i],cury=iny[i];
    int nextx=inx[(i+1)%n],nexty=iny[(i+1)%n];
    curx-=ax;
    cury-=ay;
    nextx-=ax;
    nexty-=ay;
    if (cury > nexty)swap(curx,nextx),swap(cury,nexty);
    if (cury<0 && 0<=nexty &&
	cross(nextx,nexty,curx,cury)>=0)cnt++;
    if (isp(inx[i],iny[i],inx[(i+1)%n],iny[(i+1)%n],ax,ay))return true;
  }
  if (cnt %2 == 1)return true;
  else return false;
}

inline double distance_l_p(int &ax,int &ay,int &bx,int &by,int &cx,int &cy){
  return fabs(cross(bx-ax,by-ay,cx-ax,cy-ay))/compute_dist(bx-ax,by-ay);
}

inline double solve_linear(double A1,double B1,double C1,
		    double A2,double B2,double C2,
			   double x2,double y2,double d2
		    ){
  if (fabs(A1*B2-A2*B1)<1e-8|| fabs(A1)<eps){
    return -1;
  }
  double y = (A1*C2-A2*C1)/(A1*B2-A2*B1);
  double x = (C1-B1*y)/A1;
  double z = d2*d2 - (x-x2)*(x-x2) - (y-y2)*(y-y2);
  if (z < 1e-4)return -1;

  return sqrt(z);
  if (isnan(z)||z<0)return -1;
  else return sqrt(z);
}

double ans;
inline void compute_height(Tri in[4]){
  double r[3];
  REP(i,1,4){
    r[i-1]   =  compute_dist(in[i].x[2]-in[i].x[0],
			     in[i].y[2]-in[i].y[0]);
  }
  double tmp = solve_linear((in[2].x[0]-in[1].x[0])<<1,
			    (in[2].y[0]-in[1].y[0])<<1,
			    r[0]*r[0]-r[1]*r[1]
			    -(in[1].x[0]*in[1].x[0]-in[2].x[0]*in[2].x[0])
			    -(in[1].y[0]*in[1].y[0]-in[2].y[0]*in[2].y[0]),
			    (in[2].x[0]-in[3].x[0])<<1,
			    (in[2].y[0]-in[3].y[0])<<1,
			    r[2]*r[2]-r[1]*r[1]
			    -(in[3].x[0]*in[3].x[0]-in[2].x[0]*in[2].x[0])
			    -(in[3].y[0]*in[3].y[0]-in[2].y[0]*in[2].y[0]),
			    in[2].x[0],in[2].y[0],r[1]
			    );
  if (tmp < 0.00001||isnan(tmp));
  else {
    ans = min(ans,tmp);
    return;
  }
  return;
}

inline bool isvalid(Tri in[4],int now){
  rep(j,3){
    if ((int)(in[now].x[j])<-100||(int)(in[now].x[j])>100 ||
	(int)(in[now].y[j])<-100||(int)(in[now].y[j])>100){
      return false;
    }
  }

  rep(j,now){
    rep(k,3){
      if (is_intersected_ls(in[now].x[0],in[now].y[0],in[now].x[2]    ,in[now].y[2],
			    in[j].x[k]  ,in[j].y[k]  ,in[j].x[(k+1)%3],in[j].y[(k+1)%3])){
	return false;
      }
      if (is_intersected_ls(in[now].x[1],in[now].y[1],in[now].x[2]    ,in[now].y[2],
			    in[j].x[k]  ,in[j].y[k]  ,in[j].x[(k+1)%3],in[j].y[(k+1)%3])){
	return false;
      }
      if (isp(in[j].x[k],in[j].y[k],in[j].x[(k+1)%3],in[j].y[(k+1)%3],in[now].x[2]    ,in[now].y[2])){
	return false;
      }
    }
    
    if (is_in(in[j].x,in[j].y,in[now].x[2],in[now].y[2])){
      return false;
    }

    if (j != 0 && fabs(in[now].x[2]-in[j].x[2])<1e-8&&fabs(in[now].y[2]-in[j].y[2])<1e-8){
      return false;
    } 
  }
  return true;
}

inline void decide3(Tri in[4],double &dist2){
  double dist1=compute_dist(in[1].x[0]-in[1].x[2],in[1].y[0]-in[1].y[2]);
  P c1(in[3].x[1],in[3].y[1]);
  P c2(in[3].x[0],in[3].y[0]);

  double tx1,tx2,ty1,ty2,d;
  int x1,x2,y1,y2;
  if (is_intersected_circle(c1.real(),c1.imag(),c2.real(),c2.imag(),dist1,dist2,d) == 2){
    CC_intersection(c1.real(),c1.imag(),c2.real(),c2.imag(),dist1,dist2,d,tx1,ty1,tx2,ty2);

    if (isint(tx1)&&isint(ty1)){
      x1=double_to_int(tx1);
      y1=double_to_int(ty1);
      in[3].x[2]=x1;
      in[3].y[2]=y1;
      if (isvalid(in,3))compute_height(in);
    }
	
    if (isint(tx2)&&isint(ty2)){
      x2=double_to_int(tx2);
      y2=double_to_int(ty2);
      in[3].x[2]=x2;
      in[3].y[2]=y2;
      if (isvalid(in,3))compute_height(in);
    }
  }
}

inline void decide2(Tri in[4]){
  double dist=compute_dist(in[1].x[1]-in[1].x[2],in[1].y[1]-in[1].y[2]);
  int lim = (int)(dist+0.1);
  for(int x=0;x<=lim;x++){
    double ty = sqrt(dist*dist-x*x+eps);
    if ( !isint(ty))continue;
    int y = double_to_int(ty);
    in[2].x[2]=in[2].x[0]+x;
    in[2].y[2]=in[2].y[0]+y;
    double dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
    in[2].y[2]=in[2].y[0]-y;
    dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
    
    in[2].x[2]=in[2].x[0]-x;
    in[2].y[2]=in[2].y[0]+y;
    dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
    
    in[2].y[2]=in[2].y[0]-y;
    dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
  
  }
}

inline void decide1(Tri in[4]){
  REP(y,-100,101){
    REP(x,-100,101){
      in[1].x[2]=x;
      in[1].y[2]=y;
      if (isvalid(in,1))decide2(in);
    }
  }
}

main(){
  Tri in[4];
    
  while(cin>>in[0].x[0]>>in[0].y[0]
	>>in[0].x[1]>>in[0].y[1]
	>>in[0].x[2]>>in[0].y[2]){

    if (in[0].x[0] == 0 && in[0].y[0] == 0 &&
	in[0].x[1] == 0 && in[0].y[1] == 0 &&
	in[0].x[2] == 0 && in[0].y[2] == 0)break;
    
    in[1].x[0]=in[0].x[0];    in[1].y[0]=in[0].y[0];
    in[1].x[1]=in[0].x[1];    in[1].y[1]=in[0].y[1];

    in[2].x[0]=in[0].x[1];    in[2].y[0]=in[0].y[1];
    in[2].x[1]=in[0].x[2];    in[2].y[1]=in[0].y[2];
    
    in[3].x[0]=in[0].x[2];    in[3].y[0]=in[0].y[2];
    in[3].x[1]=in[0].x[0];    in[3].y[1]=in[0].y[0];

    ans = 1e100;
    decide1(in);
    if (ans >1e99)printf("-1\n");
    else printf("%.7lf\n",ans);
  }
}
accuracy: 1
time_ms: 7990
memory_kb: 960
final_rank: 18

code_snippet: #include<iostream>
#include<complex>
#include<cmath>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define mp         make_pair

const double eps = 1e-10;

typedef complex<int> P;
typedef complex<double> DP;

class Tri{
public:
  int x[3],y[3];
};

inline double compute_dist(double x,double y){
  return sqrt(x*x+y*y);
}

int double_to_int(double &a){
  if (a <0)return (int)(a-0.5);
  else return     (int)(a+0.5);
}

bool isint(double a){
  if (a <0){
    if ( fabs((int)(a-0.5)-a)<eps)return true;
  }else {
    if ( fabs((int)(a+0.5)-a)<eps)return true;
  }
  return false;
}

double myabs(P a){
  return sqrt(a.real()*a.real()+a.imag()*a.imag());
}

inline void CC_intersection(int &ax,int &ay,int &bx,int &by,double &r1,double &r2,double &d,
			    double &x1,double &y1,double &x2,double &y2){
  double l,m,n;
  double x,y;
  double p,q;
  l=(d*d-r2*r2+r1*r1)/(2*d);
  
  x=ax+(bx-ax)*l/d;
  y=ay+(by-ay)*l/d;
  n=sqrt(r1*r1-l*l);
  p=(by-ay)/d*n;
  q=(bx-ax)/d*n;
  
  x1=x+p;
  y1=y-q;

  x2=x-p;
  y2=y+q;
}

int is_intersected_circle(int &ax,int &ay,int &bx,int &by,
			  double &r1,double& r2,double &d){
  d = compute_dist(ax-bx,ay-by);
  if (d<eps && fabs(r1-r2)<eps)return 3;
  if (d+r2 < r1)return 0;
  if (d+r1 < r2)return 1;
  if (d > r1+r2)return 4;
  return 2;
}

inline double cross(double ax,double ay,double bx,double by){
  return ax*by - ay*bx;
}

inline double dot(double ax,double ay,double bx,double by){
  return ax*bx+ay*by;}

inline bool isp(int &ax,int & ay,int & bx,int & by,int & cx,int & cy){
  double tmp1=cross(bx-ax,by-ay,cx-ax,cy-ay);
  double tmp2=dot(bx-ax,by-ay,cx-ax,cy-ay);
  return tmp1<eps&&tmp1>-eps&&tmp2<eps&&tmp2>-eps;
}

inline bool is_intersected_ls(int &a1x,int &a1y,int &a2x,int &a2y,int &b1x,int &b1y,int &b2x,int &b2y){
  if (  ( cross(a2x-a1x,a2y-a1y,b1x-a1x,b1y-a1y)*cross(a2x-a1x,a2y-a1y,b2x-a1x,b2y-a1y)<-eps) && 
	( cross(b2x-b1x,b2y-b1y,a1x-b1x,a1y-b1y)*cross(b2x-b1x,b2y-b1y,a2x-b1x,a2y-b1y)<-eps))
    return true;
  return false;
}

inline bool is_in(int *inx,int *iny,int &ax,int& ay){
  int cnt =0;
  int n = 3;
  rep(i,n){
    int curx=inx[i],cury=iny[i];
    int nextx=inx[(i+1)%n],nexty=iny[(i+1)%n];
    curx-=ax;
    cury-=ay;
    nextx-=ax;
    nexty-=ay;
    if (cury > nexty)swap(curx,nextx),swap(cury,nexty);
    if (cury<0 && 0<=nexty &&
	cross(nextx,nexty,curx,cury)>=0)cnt++;
    if (isp(inx[i],iny[i],inx[(i+1)%n],iny[(i+1)%n],ax,ay))return true;
  }
  if (cnt %2 == 1)return true;
  else return false;
}

inline double distance_l_p(int &ax,int &ay,int &bx,int &by,int &cx,int &cy){
  return fabs(cross(bx-ax,by-ay,cx-ax,cy-ay))/compute_dist(bx-ax,by-ay);
}

inline double solve_linear(double A1,double B1,double C1,
		    double A2,double B2,double C2,
			   double x2,double y2,double d2
		    ){
  if (fabs(A1*B2-A2*B1)<1e-8|| fabs(A1)<eps){
    return -1;
  }
  double y = (A1*C2-A2*C1)/(A1*B2-A2*B1);
  double x = (C1-B1*y)/A1;
  double z = d2*d2 - (x-x2)*(x-x2) - (y-y2)*(y-y2);
  if (z < 1e-4)return -1;

  return sqrt(z);
  if (isnan(z)||z<0)return -1;
  else return sqrt(z);
}

double ans;
inline void compute_height(Tri in[4]){
  double r[3];
  REP(i,1,4){
    r[i-1]   =  compute_dist(in[i].x[2]-in[i].x[0],
			     in[i].y[2]-in[i].y[0]);
  }
  double tmp = solve_linear(2*(in[2].x[0]-in[1].x[0]),
			    2*(in[2].y[0]-in[1].y[0]),
			    r[0]*r[0]-r[1]*r[1]
			    -(in[1].x[0]*in[1].x[0]-in[2].x[0]*in[2].x[0])
			    -(in[1].y[0]*in[1].y[0]-in[2].y[0]*in[2].y[0]),
			    2*(in[2].x[0]-in[3].x[0]),
			    2*(in[2].y[0]-in[3].y[0]),
			    r[2]*r[2]-r[1]*r[1]
			    -(in[3].x[0]*in[3].x[0]-in[2].x[0]*in[2].x[0])
			    -(in[3].y[0]*in[3].y[0]-in[2].y[0]*in[2].y[0]),
			    in[2].x[0],in[2].y[0],r[1]
			    );
  if (tmp < 0.00001||isnan(tmp));
  else {
    ans = min(ans,tmp);
    return;
  }
  return;
}

inline bool isvalid(Tri in[4],int now){
  rep(j,3){
    if ((int)(in[now].x[j])<-100||(int)(in[now].x[j])>100 ||
	(int)(in[now].y[j])<-100||(int)(in[now].y[j])>100){
      return false;
    }
  }

  rep(j,now){
    rep(k,3){
      if (is_intersected_ls(in[now].x[0],in[now].y[0],in[now].x[2]    ,in[now].y[2],
			    in[j].x[k]  ,in[j].y[k]  ,in[j].x[(k+1)%3],in[j].y[(k+1)%3])){
	return false;
      }
      if (is_intersected_ls(in[now].x[1],in[now].y[1],in[now].x[2]    ,in[now].y[2],
			    in[j].x[k]  ,in[j].y[k]  ,in[j].x[(k+1)%3],in[j].y[(k+1)%3])){
	return false;
      }
      if (isp(in[j].x[k],in[j].y[k],in[j].x[(k+1)%3],in[j].y[(k+1)%3],in[now].x[2]    ,in[now].y[2])){
	return false;
      }
    }
    
    if (is_in(in[j].x,in[j].y,in[now].x[2],in[now].y[2])){
      return false;
    }

    if (j != 0 && fabs(in[now].x[2]-in[j].x[2])<1e-8&&fabs(in[now].y[2]-in[j].y[2])<1e-8){
      return false;
    } 
  }
  return true;
}

inline void decide3(Tri in[4],double &dist2){
  double dist1=compute_dist(in[1].x[0]-in[1].x[2],in[1].y[0]-in[1].y[2]);
  P c1(in[3].x[1],in[3].y[1]);
  P c2(in[3].x[0],in[3].y[0]);

  double tx1,tx2,ty1,ty2,d;
  int x1,x2,y1,y2;
  if (is_intersected_circle(c1.real(),c1.imag(),c2.real(),c2.imag(),dist1,dist2,d) == 2){
    CC_intersection(c1.real(),c1.imag(),c2.real(),c2.imag(),dist1,dist2,d,tx1,ty1,tx2,ty2);

    if (isint(tx1)&&isint(ty1)){
      x1=double_to_int(tx1);
      y1=double_to_int(ty1);
      in[3].x[2]=x1;
      in[3].y[2]=y1;
      if (isvalid(in,3))compute_height(in);
    }
	
    if (isint(tx2)&&isint(ty2)){
      x2=double_to_int(tx2);
      y2=double_to_int(ty2);
      in[3].x[2]=x2;
      in[3].y[2]=y2;
      if (isvalid(in,3))compute_height(in);
    }
  }
}

inline void decide2(Tri in[4]){
  double dist=compute_dist(in[1].x[1]-in[1].x[2],in[1].y[1]-in[1].y[2]);
  int lim = (int)(dist+0.1);
  for(int x=0;x<=lim;x++){
    double ty = sqrt(dist*dist-x*x+eps);
    if ( !isint(ty))continue;
    int y = double_to_int(ty);
    in[2].x[2]=in[2].x[0]+x;
    in[2].y[2]=in[2].y[0]+y;
    double dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
    in[2].y[2]=in[2].y[0]-y;
    dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
    
    in[2].x[2]=in[2].x[0]-x;
    in[2].y[2]=in[2].y[0]+y;
    dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
    
    in[2].y[2]=in[2].y[0]-y;
    dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
  
  }
}

inline void decide1(Tri in[4]){
  REP(y,-100,101){
    REP(x,-100,101){
      in[1].x[2]=x;
      in[1].y[2]=y;
      if (isvalid(in,1))decide2(in);
    }
  }
}

main(){
  Tri in[4];
    
  while(cin>>in[0].x[0]>>in[0].y[0]
	>>in[0].x[1]>>in[0].y[1]
	>>in[0].x[2]>>in[0].y[2]){

    if (in[0].x[0] == 0 && in[0].y[0] == 0 &&
	in[0].x[1] == 0 && in[0].y[1] == 0 &&
	in[0].x[2] == 0 && in[0].y[2] == 0)break;
    
    in[1].x[0]=in[0].x[0];    in[1].y[0]=in[0].y[0];
    in[1].x[1]=in[0].x[1];    in[1].y[1]=in[0].y[1];

    in[2].x[0]=in[0].x[1];    in[2].y[0]=in[0].y[1];
    in[2].x[1]=in[0].x[2];    in[2].y[1]=in[0].y[2];
    
    in[3].x[0]=in[0].x[2];    in[3].y[0]=in[0].y[2];
    in[3].x[1]=in[0].x[0];    in[3].y[1]=in[0].y[0];

    ans = 1e100;
    decide1(in);
    if (ans >1e99)printf("-1\n");
    else printf("%.7lf\n",ans);
  }
}
accuracy: 1
time_ms: 7980
memory_kb: 960
final_rank: 15

code_snippet: #include<iostream>
#include<complex>
#include<cmath>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define mp         make_pair

const double eps = 1e-10;

typedef complex<int> P;
typedef complex<double> DP;

class Tri{
public:
  int x[3],y[3];
};

inline double compute_dist(double x,double y){
  return sqrt(x*x+y*y);
}

int double_to_int(double &a){
  if (a <0)return (int)(a-0.5);
  else return     (int)(a+0.5);
}

bool isint(double a){
  if (a <0){
    if ( fabs((int)(a-0.5)-a)<eps)return true;
  }else {
    if ( fabs((int)(a+0.5)-a)<eps)return true;
  }
  return false;
}

double myabs(P a){
  return sqrt(a.real()*a.real()+a.imag()*a.imag());
}

inline void CC_intersection(int &ax,int &ay,int &bx,int &by,double &r1,double &r2,double &d,
			    double &x1,double &y1,double &x2,double &y2){
  double l,m,n;
  double x,y;
  double p,q;
  l=(d*d-r2*r2+r1*r1)/(2*d);
  
  x=ax+(bx-ax)*l/d;
  y=ay+(by-ay)*l/d;
  n=sqrt(r1*r1-l*l);
  p=(by-ay)/d*n;
  q=(bx-ax)/d*n;
  
  x1=x+p;
  y1=y-q;

  x2=x-p;
  y2=y+q;
}

int is_intersected_circle(int &ax,int &ay,int &bx,int &by,
			  double &r1,double& r2,double &d){
  d = compute_dist(ax-bx,ay-by);
  if (d<eps && fabs(r1-r2)<eps)return 3;
  if (d+r2 < r1)return 0;
  if (d+r1 < r2)return 1;
  if (d > r1+r2)return 4;
  return 2;
}

inline double cross(double ax,double ay,double bx,double by){
  return ax*by - ay*bx;
}

inline double dot(double ax,double ay,double bx,double by){
  return ax*bx+ay*by;}

inline bool isp(int &ax,int & ay,int & bx,int & by,int & cx,int & cy){
  double tmp1=cross(bx-ax,by-ay,cx-ax,cy-ay);
  double tmp2=dot(bx-ax,by-ay,cx-ax,cy-ay);
  return tmp1<eps&&tmp1>-eps&&tmp2<eps&&tmp2>-eps;
}

inline bool is_intersected_ls(int &a1x,int &a1y,int &a2x,int &a2y,int &b1x,int &b1y,int &b2x,int &b2y){
  if (  ( cross(a2x-a1x,a2y-a1y,b1x-a1x,b1y-a1y)*cross(a2x-a1x,a2y-a1y,b2x-a1x,b2y-a1y)<-eps) && 
	( cross(b2x-b1x,b2y-b1y,a1x-b1x,a1y-b1y)*cross(b2x-b1x,b2y-b1y,a2x-b1x,a2y-b1y)<-eps))
    return true;
  return false;
}

inline bool is_in(int *inx,int *iny,int &ax,int& ay){
  int cnt =0;
  int n = 3;
  rep(i,n){
    int curx=inx[i],cury=iny[i];
    int nextx=inx[(i+1)%n],nexty=iny[(i+1)%n];
    curx-=ax;
    cury-=ay;
    nextx-=ax;
    nexty-=ay;
    if (cury > nexty)swap(curx,nextx),swap(cury,nexty);
    if (cury<0 && 0<=nexty &&
	cross(nextx,nexty,curx,cury)>=0)cnt++;
    if (isp(inx[i],iny[i],inx[(i+1)%n],iny[(i+1)%n],ax,ay))return true;
  }
  if (cnt %2 == 1)return true;
  else return false;
}

inline double distance_l_p(int &ax,int &ay,int &bx,int &by,int &cx,int &cy){
  return fabs(cross(bx-ax,by-ay,cx-ax,cy-ay))/compute_dist(bx-ax,by-ay);
}

inline double solve_linear(double A1,double B1,double C1,
		    double A2,double B2,double C2,
			   double x2,double y2,double d2
		    ){
  if (fabs(A1*B2-A2*B1)<1e-8|| fabs(A1)<eps){
    return -1;
  }
  double y = (A1*C2-A2*C1)/(A1*B2-A2*B1);
  double x = (C1-B1*y)/A1;
  double z = d2*d2 - (x-x2)*(x-x2) - (y-y2)*(y-y2);
  if (z < 1e-4)return -1;

  return sqrt(z);
  if (isnan(z)||z<0)return -1;
  else return sqrt(z);
}

double ans;
inline void compute_height(Tri in[4]){
  DP data[3];
  double r[3];
  REP(i,1,4){
    data[i-1].real()=in[i].x[0];
    data[i-1].imag()=in[i].y[0];
    r[i-1]   =  compute_dist(in[i].x[2]-in[i].x[0],
			     in[i].y[2]-in[i].y[0]);
  }
  double tmp = solve_linear(2*(data[1].real()-data[0].real()),
			    2*(data[1].imag()-data[0].imag()),
			    r[0]*r[0]-r[1]*r[1]
			    -(data[0].real()*data[0].real()-data[1].real()*data[1].real())
			    -(data[0].imag()*data[0].imag()-data[1].imag()*data[1].imag()),
			    2*(data[1].real()-data[2].real()),
			    2*(data[1].imag()-data[2].imag()),
			    r[2]*r[2]-r[1]*r[1]
			    -(data[2].real()*data[2].real()-data[1].real()*data[1].real())
			    -(data[2].imag()*data[2].imag()-data[1].imag()*data[1].imag()),
			    data[1].real(),data[1].imag(),r[1]
			    );
  if (tmp < 0.00001||isnan(tmp));
  else {
    ans = min(ans,tmp);
    return;
  }
  return;
}

inline bool isvalid(Tri in[4],int now){
  rep(j,3){
    if ((int)(in[now].x[j])<-100||(int)(in[now].x[j])>100 ||
	(int)(in[now].y[j])<-100||(int)(in[now].y[j])>100){
      return false;
    }
  }

  rep(j,now){
    rep(k,3){
      if (is_intersected_ls(in[now].x[0],in[now].y[0],in[now].x[2]    ,in[now].y[2],
			    in[j].x[k]  ,in[j].y[k]  ,in[j].x[(k+1)%3],in[j].y[(k+1)%3])){
	return false;
      }
      if (is_intersected_ls(in[now].x[1],in[now].y[1],in[now].x[2]    ,in[now].y[2],
			    in[j].x[k]  ,in[j].y[k]  ,in[j].x[(k+1)%3],in[j].y[(k+1)%3])){
	return false;
      }
      if (isp(in[j].x[k],in[j].y[k],in[j].x[(k+1)%3],in[j].y[(k+1)%3],in[now].x[2]    ,in[now].y[2])){
	return false;
      }
    }
    
    if (is_in(in[j].x,in[j].y,in[now].x[2],in[now].y[2])){
      return false;
    }

    if (j != 0 && fabs(in[now].x[2]-in[j].x[2])<1e-8&&fabs(in[now].y[2]-in[j].y[2])<1e-8){
      return false;
    } 
  }
  return true;
}

inline void decide3(Tri in[4],double &dist2){
  double dist1=compute_dist(in[1].x[0]-in[1].x[2],in[1].y[0]-in[1].y[2]);
  P c1(in[3].x[1],in[3].y[1]);
  P c2(in[3].x[0],in[3].y[0]);

  double tx1,tx2,ty1,ty2,d;
  int x1,x2,y1,y2;
  if (is_intersected_circle(c1.real(),c1.imag(),c2.real(),c2.imag(),dist1,dist2,d) == 2){
    CC_intersection(c1.real(),c1.imag(),c2.real(),c2.imag(),dist1,dist2,d,tx1,ty1,tx2,ty2);

    if (isint(tx1)&&isint(ty1)){
      x1=double_to_int(tx1);
      y1=double_to_int(ty1);
      in[3].x[2]=x1;
      in[3].y[2]=y1;
      if (isvalid(in,3))compute_height(in);
    }
	
    if (isint(tx2)&&isint(ty2)){
      x2=double_to_int(tx2);
      y2=double_to_int(ty2);
      in[3].x[2]=x2;
      in[3].y[2]=y2;
      if (isvalid(in,3))compute_height(in);
    }
  }
}

inline void decide2(Tri in[4]){
  double dist=compute_dist(in[1].x[1]-in[1].x[2],in[1].y[1]-in[1].y[2]);
  int lim = (int)(dist+0.1);
  for(int x=0;x<=lim;x++){
    double ty = sqrt(dist*dist-x*x+eps);
    if ( !isint(ty))continue;
    int y = double_to_int(ty);
    in[2].x[2]=in[2].x[0]+x;
    in[2].y[2]=in[2].y[0]+y;
    double dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
    in[2].y[2]=in[2].y[0]-y;
    dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
    
    in[2].x[2]=in[2].x[0]-x;
    in[2].y[2]=in[2].y[0]+y;
    dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
    
    in[2].y[2]=in[2].y[0]-y;
    dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
  
  }
}

inline void decide1(Tri in[4]){
  REP(y,-100,101){
    REP(x,-100,101){
      in[1].x[2]=x;
      in[1].y[2]=y;
      if (isvalid(in,1))decide2(in);
    }
  }
}

main(){
  Tri in[4];
    
  while(cin>>in[0].x[0]>>in[0].y[0]
	>>in[0].x[1]>>in[0].y[1]
	>>in[0].x[2]>>in[0].y[2]){

    if (in[0].x[0] == 0 && in[0].y[0] == 0 &&
	in[0].x[1] == 0 && in[0].y[1] == 0 &&
	in[0].x[2] == 0 && in[0].y[2] == 0)break;
    
    in[1].x[0]=in[0].x[0];    in[1].y[0]=in[0].y[0];
    in[1].x[1]=in[0].x[1];    in[1].y[1]=in[0].y[1];

    in[2].x[0]=in[0].x[1];    in[2].y[0]=in[0].y[1];
    in[2].x[1]=in[0].x[2];    in[2].y[1]=in[0].y[2];
    
    in[3].x[0]=in[0].x[2];    in[3].y[0]=in[0].y[2];
    in[3].x[1]=in[0].x[0];    in[3].y[1]=in[0].y[0];

    ans = 1e100;
    decide1(in);
    if (ans >1e99)printf("-1\n");
    else printf("%.7lf\n",ans);
  }
}
accuracy: 1
time_ms: 7990
memory_kb: 956
final_rank: 17

code_snippet: #include<iostream>
#include<complex>
#include<cmath>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define mp         make_pair

const double eps = 1e-10;

typedef complex<int> P;
typedef complex<double> DP;

class Tri{
public:
  int x[3],y[3];
};

inline double compute_dist(double x,double y){
  return sqrt(x*x+y*y);
}

int double_to_int(double &a){
  if (a <0)return (int)(a-0.5);
  else return     (int)(a+0.5);
}

bool isint(double a){
  if (a <0){
    if ( fabs((int)(a-0.5)-a)<eps)return true;
  }else {
    if ( fabs((int)(a+0.5)-a)<eps)return true;
  }
  return false;
}

double myabs(P a){
  return sqrt(a.real()*a.real()+a.imag()*a.imag());
}

inline void CC_intersection(int &ax,int &ay,int &bx,int &by,double &r1,double &r2,double &d,
			    double &x1,double &y1,double &x2,double &y2){
  double l,m,n;
  double x,y;
  double p,q;
  l=(d*d-r2*r2+r1*r1)/(2*d);
  
  x=ax+(bx-ax)*l/d;
  y=ay+(by-ay)*l/d;
  n=sqrt(r1*r1-l*l);
  p=(by-ay)/d*n;
  q=(bx-ax)/d*n;
  
  x1=x+p;
  y1=y-q;

  x2=x-p;
  y2=y+q;
}

int is_intersected_circle(int &ax,int &ay,int &bx,int &by,
			  double &r1,double& r2,double &d){
  d = compute_dist(ax-bx,ay-by);
  if (d<eps && fabs(r1-r2)<eps)return 3;
  if (d+r2 < r1)return 0;
  if (d+r1 < r2)return 1;
  if (d > r1+r2)return 4;
  return 2;
}

inline double cross(double ax,double ay,double bx,double by){
  return ax*by - ay*bx;
}

inline double dot(double ax,double ay,double bx,double by){
  return ax*bx+ay*by;}

inline bool isp(int &ax,int & ay,int & bx,int & by,int & cx,int & cy){
  double tmp1=cross(bx-ax,by-ay,cx-ax,cy-ay);
  double tmp2=dot(bx-ax,by-ay,cx-ax,cy-ay);
  return tmp1<eps&&tmp1>-eps&&tmp2<eps&&tmp2>-eps;
}

inline bool is_intersected_ls(int &a1x,int &a1y,int &a2x,int &a2y,int &b1x,int &b1y,int &b2x,int &b2y){
  if (  ( cross(a2x-a1x,a2y-a1y,b1x-a1x,b1y-a1y)*cross(a2x-a1x,a2y-a1y,b2x-a1x,b2y-a1y)<-eps) && 
	( cross(b2x-b1x,b2y-b1y,a1x-b1x,a1y-b1y)*cross(b2x-b1x,b2y-b1y,a2x-b1x,a2y-b1y)<-eps))
    return true;
  return false;
}

inline bool is_in(int *inx,int *iny,int &ax,int& ay){
  int cnt =0;
  int n = 3;
  rep(i,n){
    int curx=inx[i],cury=iny[i];
    int nextx=inx[(i+1)%n],nexty=iny[(i+1)%n];
    curx-=ax;
    cury-=ay;
    nextx-=ax;
    nexty-=ay;
    if (cury > nexty)swap(curx,nextx),swap(cury,nexty);
    if (cury<0 && 0<=nexty &&
	cross(nextx,nexty,curx,cury)>=0)cnt++;
    if (isp(inx[i],iny[i],inx[(i+1)%n],iny[(i+1)%n],ax,ay))return true;
  }
  if (cnt %2 == 1)return true;
  else return false;
}

inline double distance_l_p(int &ax,int &ay,int &bx,int &by,int &cx,int &cy){
  return fabs(cross(bx-ax,by-ay,cx-ax,cy-ay))/compute_dist(bx-ax,by-ay);
}

inline DP vector_mapping(int &ax,int &ay,int& bx,int& by,int &cx,int &cy){
  double tmp = distance_l_p(ax,ay,bx,by,cx,cy);
  double tmp2= compute_dist(cx-ax,cy-ay);
  double C   = sqrt(tmp2*tmp2-tmp*tmp+eps);
  if (dot(bx-ax,by-ay,cx-ax,cy-ay)<0)C*=-1;
  DP e(bx-ax,by-ay);
  DP A(ax,ay);
  e/=compute_dist(bx-ax,by-ay);
  e*=C;
  return A + e;
}

inline double solve_linear(double A1,double B1,double C1,
		    double A2,double B2,double C2,
			   double x2,double y2,double d2
		    ){
  if (fabs(A1*B2-A2*B1)<1e-8|| fabs(A1)<eps){
    return -1;
  }
  double y = (A1*C2-A2*C1)/(A1*B2-A2*B1);
  double x = (C1-B1*y)/A1;
  double z = d2*d2 - (x-x2)*(x-x2) - (y-y2)*(y-y2);
  if (z < 1e-4)return -1;

  return sqrt(z);
  if (isnan(z)||z<0)return -1;
  else return sqrt(z);
}

double ans;
inline void compute_height(Tri in[4]){
  DP data[3];
  double r[3];
  REP(i,1,4){
    data[i-1]=vector_mapping(in[i].x[0],in[i].y[0],in[i].x[1],in[i].y[1],in[i].x[2],in[i].y[2]);
    r[i-1]   =  distance_l_p(in[i].x[0],in[i].y[0],in[i].x[1],in[i].y[1],in[i].x[2],in[i].y[2]);
  }
  double tmp = solve_linear(2*(data[1].real()-data[0].real()),
			    2*(data[1].imag()-data[0].imag()),
			    r[0]*r[0]-r[1]*r[1]
			    -(data[0].real()*data[0].real()-data[1].real()*data[1].real())
			    -(data[0].imag()*data[0].imag()-data[1].imag()*data[1].imag()),
			    2*(data[1].real()-data[2].real()),
			    2*(data[1].imag()-data[2].imag()),
			    r[2]*r[2]-r[1]*r[1]
			    -(data[2].real()*data[2].real()-data[1].real()*data[1].real())
			    -(data[2].imag()*data[2].imag()-data[1].imag()*data[1].imag()),
			    data[1].real(),data[1].imag(),r[1]
			    );
  if (tmp < 0.00001||isnan(tmp));
  else {
    ans = min(ans,tmp);
    return;
  }
  return;
}

inline bool isvalid(Tri in[4],int now){
  rep(j,3){
    if ((int)(in[now].x[j])<-100||(int)(in[now].x[j])>100 ||
	(int)(in[now].y[j])<-100||(int)(in[now].y[j])>100){
      return false;
    }
  }

  rep(j,now){
    rep(k,3){
      if (is_intersected_ls(in[now].x[0],in[now].y[0],in[now].x[2]    ,in[now].y[2],
			    in[j].x[k]  ,in[j].y[k]  ,in[j].x[(k+1)%3],in[j].y[(k+1)%3])){
	return false;
      }
      if (is_intersected_ls(in[now].x[1],in[now].y[1],in[now].x[2]    ,in[now].y[2],
			    in[j].x[k]  ,in[j].y[k]  ,in[j].x[(k+1)%3],in[j].y[(k+1)%3])){
	return false;
      }
      if (isp(in[j].x[k],in[j].y[k],in[j].x[(k+1)%3],in[j].y[(k+1)%3],in[now].x[2]    ,in[now].y[2])){
	return false;
      }
    }
    
    if (is_in(in[j].x,in[j].y,in[now].x[2],in[now].y[2])){
      return false;
    }

    if (j != 0 && fabs(in[now].x[2]-in[j].x[2])<1e-8&&fabs(in[now].y[2]-in[j].y[2])<1e-8){
      return false;
    } 
  }
  return true;
}

inline void decide3(Tri in[4],double &dist2){
  double dist1=compute_dist(in[1].x[0]-in[1].x[2],in[1].y[0]-in[1].y[2]);
  P c1(in[3].x[1],in[3].y[1]);
  P c2(in[3].x[0],in[3].y[0]);

  double tx1,tx2,ty1,ty2,d;
  int x1,x2,y1,y2;
  if (is_intersected_circle(c1.real(),c1.imag(),c2.real(),c2.imag(),dist1,dist2,d) == 2){
    CC_intersection(c1.real(),c1.imag(),c2.real(),c2.imag(),dist1,dist2,d,tx1,ty1,tx2,ty2);

    if (isint(tx1)&&isint(ty1)){
      x1=double_to_int(tx1);
      y1=double_to_int(ty1);
      in[3].x[2]=x1;
      in[3].y[2]=y1;
      if (isvalid(in,3))compute_height(in);
    }
	
    if (isint(tx2)&&isint(ty2)){
      x2=double_to_int(tx2);
      y2=double_to_int(ty2);
      in[3].x[2]=x2;
      in[3].y[2]=y2;
      if (isvalid(in,3))compute_height(in);
    }
  }
}

inline void decide2(Tri in[4]){
  double dist=compute_dist(in[1].x[1]-in[1].x[2],in[1].y[1]-in[1].y[2]);
  int lim = (int)(dist+0.1);
  for(int x=0;x<=lim;x++){
    double ty = sqrt(dist*dist-x*x+eps);
    if ( !isint(ty))continue;
    int y = double_to_int(ty);
    in[2].x[2]=in[2].x[0]+x;
    in[2].y[2]=in[2].y[0]+y;
    double dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
    in[2].y[2]=in[2].y[0]-y;
    dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
    
    in[2].x[2]=in[2].x[0]-x;
    in[2].y[2]=in[2].y[0]+y;
    dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
    
    in[2].y[2]=in[2].y[0]-y;
    dist2=compute_dist(in[2].x[2]-in[2].x[1],in[2].y[2]-in[2].y[1]);
    if (isvalid(in,2))decide3(in,dist2);
  
  }
}

inline void decide1(Tri in[4]){
  REP(y,-100,101){
    REP(x,-100,101){
      in[1].x[2]=x;
      in[1].y[2]=y;
      if (isvalid(in,1))decide2(in);
    }
  }
}

main(){
  Tri in[4];
    
  while(cin>>in[0].x[0]>>in[0].y[0]
	>>in[0].x[1]>>in[0].y[1]
	>>in[0].x[2]>>in[0].y[2]){

    if (in[0].x[0] == 0 && in[0].y[0] == 0 &&
	in[0].x[1] == 0 && in[0].y[1] == 0 &&
	in[0].x[2] == 0 && in[0].y[2] == 0)break;
    
    in[1].x[0]=in[0].x[0];    in[1].y[0]=in[0].y[0];
    in[1].x[1]=in[0].x[1];    in[1].y[1]=in[0].y[1];

    in[2].x[0]=in[0].x[1];    in[2].y[0]=in[0].y[1];
    in[2].x[1]=in[0].x[2];    in[2].y[1]=in[0].y[2];
    
    in[3].x[0]=in[0].x[2];    in[3].y[0]=in[0].y[2];
    in[3].x[1]=in[0].x[0];    in[3].y[1]=in[0].y[0];

    ans = 1e100;
    decide1(in);
    if (ans >1e99)printf("-1\n");
    else printf("%.7lf\n",ans);
  }
}
accuracy: 1
time_ms: 7980
memory_kb: 960
final_rank: 15