H - Rings

Problem Statement

There are two circles with radius 1 in 3D space. Please check two circles are connected as chained rings.

Input

The input is formatted as follows.


{c_x}_1 {c_y}_1 {c_z}_1
{v_x}_{1,1} {v_y}_{1,1} {v_z}_{1,1} {v_x}_{1,2} {v_y}_{1,2} {v_z}_{1,2}
{c_x}_2 {c_y}_2 {c_z}_2
{v_x}_{2,1} {v_y}_{2,1} {v_z}_{2,1} {v_x}_{2,2} {v_y}_{2,2} {v_z}_{2,2}


First line contains three real numbers(-3 \leq {c_x}_i, {c_y}_i, {c_z}_i \leq 3). It shows a circle's center position. Second line contains six real numbers(-1 \leq {v_x}_{i,j}, {v_y}_{i,j}, {v_z}_{i,j} \leq 1). A unit vector ({v_x}_{1,1}, {v_y}_{1,1}, {v_z}_{1,1}) is directed to the circumference of the circle from center of the circle. The other unit vector ({v_x}_{1,2}, {v_y}_{1,2}, {v_z}_{1,2}) is also directed to the circumference of the circle from center of the circle. These two vectors are orthogonalized. Third and fourth lines show the other circle information in the same way of first and second lines. There are no cases that two circles touch.

Output

If two circles are connected as chained rings, you should print "YES". The other case, you should print "NO". (quotes for clarity)

Sample Input 1


0.0 0.0 0.0
1.0 0.0 0.0 0.0 1.0 0.0
1.0 0.0 0.5
1.0 0.0 0.0 0.0 0.0 1.0


Output for the Sample Input 1


YES


Sample Input 2


0.0 0.0 0.0
1.0 0.0 0.0 0.0 1.0 0.0
0.0 3.0 0.0
0.0 1.0 0.0 -1.0 0.0 0.0


Output for the Sample Input 2


NO


Sample Input 3


1.2 2.3 -0.5
1.0 0.0 0.0 0.0 1.0 0.0
1.1 2.3 -0.4
1.0 0.0 0.0 0.0 0.70710678 0.70710678


Output for the Sample Input 3


YES


Sample Input 4


1.2 2.3 -0.5
1.0 0.0 0.0 0.0 1.0 0.0
1.1 2.7 -0.1
1.0 0.0 0.0 0.0 0.70710678 0.70710678


Output for the Sample Input 4


NO






Example

Input

0.0 0.0 0.0
1.0 0.0 0.0 0.0 1.0 0.0
1.0 0.0 0.5
1.0 0.0 0.0 0.0 0.0 1.0


Output

YES
#include<cstdio>
#include<cmath>
const double eps=1e-9;
bool zero(double e)
{return fabs(e)<eps;}
int sgn(double e)
{return e<-eps?-1:e>eps;}
struct v3{
    double x,y,z;
    v3(){}
    v3(double x,double y,double z):x(x),y(y),z(z){}
    void s()
    {
        scanf("%lf%lf%lf",&x,&y,&z);
    }
    void p()
    {
      //  printf("%lf %lf %lf",x,y,z);
    }
    double len()
    {
        return sqrt(x*x+y*y+z*z);
    }
    v3 normalized()
    {
        double l=this->len();
        return v3(x/l,y/l,z/l);
    }
};
v3 operator +(v3 a,v3 b){return v3(a.x+b.x,a.y+b.y,a.z+b.z);}
v3 operator -(v3 a,v3 b){return v3(a.x-b.x,a.y-b.y,a.z-b.z);}
v3 operator *(v3 a,double b){return v3(a.x*b,a.y*b,a.z*b);}
v3 operator /(v3 a,double b){return v3(a.x/b,a.y/b,a.z/b);}
v3 operator *(double b,v3 a){return v3(a.x*b,a.y*b,a.z*b);}
v3 Det(v3 a,v3 b)
{
    return v3(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);
}
double Dot(v3 a,v3 b)
{
    return a.x*b.x+a.y*b.y+a.z*b.z;
}

struct l3
{
v3 a,b;
l3(){};
l3(v3 a,v3 b):a(a),b(b){};
};
struct p3
{
v3 a,b,c;
p3(){}
p3(v3 a,v3 b,v3 c):a(a),b(b),c(c){}
};
double vlen(v3 p){return sqrt(Dot(p,p));}
v3 pvec(v3 s1,v3 s2,v3 s3)
{
    return Det(s1-s2,s2-s3);
}
v3 pvec(p3 x)
{return pvec(x.a,x.b,x.c);}
int parallel(p3 u,p3 v)
{
    return vlen(Det(pvec(u),pvec(v)))<eps;

}
int parallel(v3 a,v3 b,p3 s)
{
    return zero(Dot(a-b,pvec(s)));
}
v3 intersection(v3 a,v3 b,p3 s)
{
    v3 ret=pvec(s);
    double t=(ret.x*(s.a.x-a.x)+ret.y*(s.a.y-a.y)+ret.z*(s.a.z-a.z))/
            (ret.x*(b.x-a.x)+ret.y*(b.y-a.y)+ret.z*(b.z-a.z));
    ret=a+(b-a)*t;
    return ret;

}
bool intersection(p3 pl1,p3 pl2,l3& li)
{
    if(parallel(pl1,pl2))return false;
    li.a=parallel(pl2.a,pl2.b,pl1)?intersection(pl2.b,pl2.c,p3(pl1.a,pl1.b,pl1.c)):
    intersection(pl2.a,pl2.b,p3(pl1.a,pl1.b,pl1.c));
    v3 fa;
    fa=Det(pvec(pl1),pvec(pl2));
    li.b=li.a+fa;
    return true;
}
double ptoplane(v3 p,p3 s)
{
    return fabs(Dot(pvec(s),p-s.a))/vlen(pvec(s));
}
double ptoline(v3 p,l3 l)
{
    return vlen(Det(p-l.a,l.b-l.a))/(l.a-l.b).len();
}
int main()
{
    v3 c1;
    c1.s();
    v3 d1,d2;
    d1.s();
    d2.s();
    p3 p1=p3(c1,c1+d1,c1+d2);


    v3 c2;
    c2.s();
    v3 d1p,d2p;
    d1p.s();
    d2p.s();
    p3 p2=p3(c2,c2+d1p,c2+d2p);

    l3 ins;
    //not parl//
    if(!intersection(p1,p2,ins)){puts("NO");return 0;}

    v3 l=(ins.b-ins.a).normalized();
    double r1=ptoline(c1,ins),r2=ptoline(c2,ins);
    if(r1>1+eps||r2>1+eps){puts("NO");return 0;}

    double le1=sqrt(1-r1*r1);

    //projection//
    v3 pt1;
    if(zero(ptoline(c1,ins)))
        pt1=c1;
    else{
        v3 p01=Det(c1-ins.a,c1-ins.b);
        v3 p02=Det(ins.b-ins.a,p01);
        p3 p0=p3(c1,c1+p01,c1+p02);
        pt1=intersection(ins.a,ins.b,p0);
    }


    v3 np1=pt1+l*le1,np2=pt1-l*le1;
    //ins.b.p();
    //np2.p();
    if(sgn(vlen(np1-c2)-1.0)*sgn(vlen(np2-c2)-1.0)!=-1){puts("NO");return 0;}
    puts("YES");
    return 0;




}