#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

const double eps = 1e-10 , pi = acos(-1.0);

inline int cmp(double x)
{
    return (x > eps) - (x < -eps);
}

inline double sqr(double x)
{
	return x * x;
}

struct Point
{
	double x,y;
	Point(double a = 0,double b = 0):x(a),y(b) {}
	void input()
	{
		scanf("%lf%lf",&x,&y);
	}
	bool operator < (const Point& R) const {
        if (cmp(x - R.x) == 0)
            return cmp(y - R.y) < 0;
        return cmp(x - R.x) < 0;
    }
    bool operator == (const Point& R) const {
        return cmp(x - R.x) == 0 && cmp(y - R.y) == 0;
    }
    Point operator + (const Point& R) const {
        return Point(x + R.x , y + R.y);
    }
    Point operator - (const Point& R) const {
        return Point(x - R.x , y - R.y);
    }
    Point operator * (const double& R) const {
        return Point(x * R , y * R);
    }
    Point operator / (const double& R) const {
        return Point(x / R , y / R);
    }
    double operator ^ (const Point& R) const {
        return x * R.y - y * R.x;
    }
    double operator % (const Point& R) const {
        return x * R.x + y * R.y;
	}	 
	double len()
	{
		return sqrt(sqr(x) + sqr(y));
	}
	double angle()
	{
		return atan2(y,x);
	}
}p[10],pp[10],v,o;

double l,d;
char str[20];
bool ans[2][4],now[4];
int stk[3],stkk[3];

Point Rotate(Point A , double rad) {
    double Sin = sin(rad) , Cos = cos(rad);
    return Point(A.x * Cos - A.y * Sin , A.x * Sin + A.y * Cos);
}

bool SPI(Point a1 , Point a2 , Point b1 , Point b2) {
    double c1 = (a2 - a1) ^ (b1 - a1);
    double c2 = (a2 - a1) ^ (b2 - a1);
    if (cmp(c1) == 0 && cmp(c2) == 0) {
        if (a2 < a1) swap(a1 , a2);
        if (b2 < b1) swap(b1 , b2);
        return max(a1 , b1) < min(a2 , b2);
    }
    double c3 = (b2 - b1) ^ (a1 - b1);
    double c4 = (b2 - b1) ^ (a2 - b1);
    return cmp(c1) * cmp(c2) < 0 && cmp(c3) * cmp(c4) < 0;
}

double con(double x)
{
	return x / 180.0 * pi;
}

Point calc(Point a, Point b, Point c)
{
	return a + b - c;
}

bool check(Point a, Point b)
{
	return SPI(Point(0,0),v,a,b);
}

int main()
{
	o = Point(-1,0);
	for(int ii = 0; ii < 2; ii++)
	{
		scanf("%s",str);
		scanf("%lf%lf",&d,&l);
		memset(now,0,sizeof(now));
		v = Rotate(Point(-l,0),con(d+60));
		p[1] = Rotate(o,con(60));
		p[2] = Rotate(o,con(120));
		stk[0] = 0;
		stk[1] = str[0] - 'A';
		stk[2] = str[1] - 'A';
		for(int i = 0; i < 3; i++)
			now[stk[i]] = 1;
		if(check(p[1],p[2]))
		{
			p[0] = calc(p[1],p[2],Point(0,0));
			now[6 - stk[0] - stk[1] - stk[2]] = true;
			now[0] = false;	
			stkk[0] = 6 - stk[0] - stk[1] - stk[2];
			stkk[1] = stk[1];
			stkk[2] = stk[2];
			for(int i = 0; i < 3; i++)
				stk[i] = stkk[i];
		}
		else
		{
			for(int i = 0; i < 4; i++)
				ans[ii][i] = now[i];
			continue;
		}
		while(check(p[0],p[2]) || check(p[1],p[0]))
		{
			int p1 = 0,p2;
			if(check(p[0],p[2]))
				p2 = 2;
			else
				p2 = 1;
			now[6 - stk[0] - stk[1] - stk[2]] = true;
			now[stk[3-p2]] = false;
			stkk[0] = 6 - stk[0] - stk[1] - stk[2];
			stkk[1] = stk[p1];
			stkk[2] = stk[p2];
			pp[0] = calc(p[p1],p[p2],p[3-p2]);
			pp[1] = p[p1];
			pp[2] = p[p2];
			for(int i = 0; i < 3; i++)
				stk[i] = stkk[i];
			for(int i = 0; i < 3; i++)
				p[i] = pp[i];
		}
		for(int i = 0; i < 4; i++)
			ans[ii][i] = now[i];
	}
	bool flag = true;
	for(int i = 0; i < 4; i++)
		if(ans[0][i] != ans[1][i])
			flag = false;
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}





Measured memory_bytes: 2996