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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

typedef valarray<double> point;
struct line : public vector<point> {
  line() {}
  line(point a, point b) { push_back(a); push_back(b); }
  point v() const { return (*this)[1]-(*this)[0]; }
};
point Point() { point p(3); return p; }
point Point(double x, double y, double z) {
  point p(3);
  p[0]=x;p[1]=y;p[2]=z;
  return p;
}
double dot(const point& a, const point& b) {
  return (a * b).sum();
}
point cross(const point& a, const point& b) {
  return a.cshift(+1)*b.cshift(-1)
       - a.cshift(-1)*b.cshift(+1);
}
double norm(const point &a) {
  return dot(a,a);
}
double length(const point &a) {
  return sqrt(dot(a,a));
}
double angle(const point &a, const point &b) {
  return acos( dot(a,b)/length(a)/length(b) );
}
point input() {
  double a[3];
  REP(i,3) cin >>a[i];
  return point(a,3);
}
ostream &operator<<(ostream &os, const point &a) {
  char str[200];
  snprintf(str, 199, "(%.2f, %.2f, %.2f)", a[0], a[1], a[2]);
  os << str;
  return os;
}
point projection(const line &l, const point &p) {
  double t = dot(p-l[0], l.v()) / norm(l.v());
  return l[0] + t * l.v();
}

struct sphere {
  point p;
  double r;
  sphere(const point &p, double r) : p(p), r(r) {}
  sphere() {}
};

vector<point> crosspointLineSphere(const line &l, const sphere &c) {
  vector<point> ret;
  point center = projection(l, c.p);
  double d =  length(center - c.p);
  if (c.r < d-EPS) return ret;
  double t = sqrt(max(0.0,c.r*c.r-d*d));
  point vect = l[1] - l[0];
  vect /= length(vect);
  ret.push_back(center - vect*t);
  if (t > EPS) {
    ret.push_back(center + vect*t);
  }
  return ret;
}

// 平面
struct plane {
  point p, n;
  plane() : p(Point()),n(Point()){}
  plane(const point &p, const point &n) : p(p),n(n) {}
  plane(double A, double B, double C, double D)
    : p(Point()), n(Point(A,B,C)) {
    n /= length(n);
    // Ax+By+Cz=D
    if (abs(A) > 0) p = Point(D/A,0,0);
    else if (abs(B) > 0) p = Point(0,D/B,0);
    else p = Point(0,0,D/C);
  }
};
int relationPlP(const plane &pl, const point &p) {
  double d = dot(p-pl.p, pl.n)/length(p-pl.p);
  if (abs(d) < EPS) return 0;
  return d>0?1:-1;
}
bool intersectPlS(const plane &pl, const line &s) {
  return relationPlP(pl,s[0]) * relationPlP(pl,s[1]) <= 0;
}
point crosspointPlL(const plane &pl, const line &l) {
  double d = dot(pl.n,l.v());
  if (abs(d) < EPS) return l[0];
  double t = -dot(pl.n,l[0]-pl.p) / d;
  return l[0]+t*l.v();
}
bool crossline(const plane &pl1, const plane &pl2, line &res) {
  point v = cross(pl1.n,pl2.n);
  if (norm(v) < EPS) return 0;
  point tv = cross(pl1.n,v);
  double t = dot(pl2.p-pl1.p,pl2.n) / dot(tv,pl2.n);
  point p = pl1.p + t * tv;
  res = line(p,p+v);
  return 1;
}

bool solve(double x, double y, double z) {
  point p1(Point(x,y,z));
  point v11(input());
  point v12(input());
  point p2(input());
  point v21(input());
  point v22(input());
  plane pl1(p1, cross(v11,v12));
  plane pl2(p2, cross(v21,v22));
  line cl;
  if (!crossline(pl1, pl2, cl)) return 0;
  vector<point> pv = crosspointLineSphere(cl, sphere(p1,1));
  if (pv.size() != 2) return 0;
  double d1 = length(pv[0]-p2);
  double d2 = length(pv[1]-p2);
  return (d1 < 1-EPS && d2 > 1+EPS ||
          d2 < 1-EPS && d1 > 1+EPS);
}

int main() {
  double x,y,z;
  while(cin >> x >> y >> z) {
    cout << (solve(x,y,z)?"YES":"NO") << endl;
  }
}
### Prompt

Your task is to create a Cpp solution to the following problem:

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

typedef valarray<double> point;
struct line : public vector<point> {
  line() {}
  line(point a, point b) { push_back(a); push_back(b); }
  point v() const { return (*this)[1]-(*this)[0]; }
};
point Point() { point p(3); return p; }
point Point(double x, double y, double z) {
  point p(3);
  p[0]=x;p[1]=y;p[2]=z;
  return p;
}
double dot(const point& a, const point& b) {
  return (a * b).sum();
}
point cross(const point& a, const point& b) {
  return a.cshift(+1)*b.cshift(-1)
       - a.cshift(-1)*b.cshift(+1);
}
double norm(const point &a) {
  return dot(a,a);
}
double length(const point &a) {
  return sqrt(dot(a,a));
}
double angle(const point &a, const point &b) {
  return acos( dot(a,b)/length(a)/length(b) );
}
point input() {
  double a[3];
  REP(i,3) cin >>a[i];
  return point(a,3);
}
ostream &operator<<(ostream &os, const point &a) {
  char str[200];
  snprintf(str, 199, "(%.2f, %.2f, %.2f)", a[0], a[1], a[2]);
  os << str;
  return os;
}
point projection(const line &l, const point &p) {
  double t = dot(p-l[0], l.v()) / norm(l.v());
  return l[0] + t * l.v();
}

struct sphere {
  point p;
  double r;
  sphere(const point &p, double r) : p(p), r(r) {}
  sphere() {}
};

vector<point> crosspointLineSphere(const line &l, const sphere &c) {
  vector<point> ret;
  point center = projection(l, c.p);
  double d =  length(center - c.p);
  if (c.r < d-EPS) return ret;
  double t = sqrt(max(0.0,c.r*c.r-d*d));
  point vect = l[1] - l[0];
  vect /= length(vect);
  ret.push_back(center - vect*t);
  if (t > EPS) {
    ret.push_back(center + vect*t);
  }
  return ret;
}

// 平面
struct plane {
  point p, n;
  plane() : p(Point()),n(Point()){}
  plane(const point &p, const point &n) : p(p),n(n) {}
  plane(double A, double B, double C, double D)
    : p(Point()), n(Point(A,B,C)) {
    n /= length(n);
    // Ax+By+Cz=D
    if (abs(A) > 0) p = Point(D/A,0,0);
    else if (abs(B) > 0) p = Point(0,D/B,0);
    else p = Point(0,0,D/C);
  }
};
int relationPlP(const plane &pl, const point &p) {
  double d = dot(p-pl.p, pl.n)/length(p-pl.p);
  if (abs(d) < EPS) return 0;
  return d>0?1:-1;
}
bool intersectPlS(const plane &pl, const line &s) {
  return relationPlP(pl,s[0]) * relationPlP(pl,s[1]) <= 0;
}
point crosspointPlL(const plane &pl, const line &l) {
  double d = dot(pl.n,l.v());
  if (abs(d) < EPS) return l[0];
  double t = -dot(pl.n,l[0]-pl.p) / d;
  return l[0]+t*l.v();
}
bool crossline(const plane &pl1, const plane &pl2, line &res) {
  point v = cross(pl1.n,pl2.n);
  if (norm(v) < EPS) return 0;
  point tv = cross(pl1.n,v);
  double t = dot(pl2.p-pl1.p,pl2.n) / dot(tv,pl2.n);
  point p = pl1.p + t * tv;
  res = line(p,p+v);
  return 1;
}

bool solve(double x, double y, double z) {
  point p1(Point(x,y,z));
  point v11(input());
  point v12(input());
  point p2(input());
  point v21(input());
  point v22(input());
  plane pl1(p1, cross(v11,v12));
  plane pl2(p2, cross(v21,v22));
  line cl;
  if (!crossline(pl1, pl2, cl)) return 0;
  vector<point> pv = crosspointLineSphere(cl, sphere(p1,1));
  if (pv.size() != 2) return 0;
  double d1 = length(pv[0]-p2);
  double d2 = length(pv[1]-p2);
  return (d1 < 1-EPS && d2 > 1+EPS ||
          d2 < 1-EPS && d1 > 1+EPS);
}

int main() {
  double x,y,z;
  while(cin >> x >> y >> z) {
    cout << (solve(x,y,z)?"YES":"NO") << endl;
  }
}
```