#include <bits/stdc++.h>
#include <iomanip>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;
typedef vector<int> VI;
typedef vector<char> VB;
 
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
 
const LD eps=1e-10;
const long long INFLL=(LL)(1e9)*(LL)(1e9);
const int INF=1e9;
 
template<class T>
void chmin(T& a, const T b)
{
	if(a>b)
		a=b;
}
template<class T>
void chmax(T& a, const T b)
{
	if(a<b)
		a=b;
}
 
const LL pow(const LL p, const LL q)
{
	LL t=1;
	for(int i=0;i<q;i++)
		t*=p;
	return t;
}

template <typename T>
struct has_iter
{
	private:
		template <typename U>
		static constexpr true_type check(typename U::iterator*);
		template <typename U>
		static constexpr false_type check(...);

	public:
		static constexpr bool value = decltype(check<T>(nullptr))::value;
};

template<typename T, typename U = typename T::iterator>
void print(const T& container)
{
		auto&& first=begin(container), last=end(container);
		auto&& back=prev(last);
		for(auto e=first; e!=last; e=next(e))
			cout<<*e<<" \n"[e==back];
}

extern void* enabler;
template<typename Head, typename enable_if<!has_iter<Head>::value>::type*& = enabler>
void print(const Head& head)
{
	cout<<head<<endl;
}

template<typename Head, typename... Tail>
void print(const Head& head, const Tail&... tail)
{
	cout<<head<<" ";
	print(tail...);
}

void io_speedup()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec)
{
	for(T& x: vec) is >> x;
	return is;
}

template<typename T>
vector<T> read(int n)
{
	vector<T> t(n);
	cin>>t;
	return t;
}

template<typename T>
T read()
{
	T t;
	cin>>t;
	return t;
}

typedef LD ld;
const ld pi =acos(-1.0);
typedef complex<ld> Point;
struct Line
{
	Point a,b;
	Line(Point a_, Point b_):a(a_),b(b_)
	{}
	Line():a(Point(0,0)),b(Point(0,0))
	{}
};
ld dot(Point a, Point b)
{
	return real(conj(a) * b);
}
ld cross(Point a, Point b)
{
	return imag(conj(a) * b);
}
int ccw(Point a,Point b, Point c)
{
	b-=a;
	c-=a;
	if(cross(b,c)>eps) return 1;
	if(cross(b,c)<-eps) return -1;
	if(dot(b,c) < 0) return 2;
	if(norm(b)<norm(c)) return -2;
	return 0;
}
int main()
{
	string s1,s2;
	double d1,w1;
	double d2,w2;
	cin>>s1>>d1>>w1;
	cin>>s2>>d2>>w2;
	auto cs=[](string s)
	{
		if(s=="BC")
			return 0;
		else if(s=="CD")
			return 60;
		return 120;
	};
	d1+=cs(s1);
	d2+=cs(s2);
	Point p1(cos(d1*(pi/180))*w1, sin(d1*(pi/180))*w1);
	Point p2(cos(d2*(pi/180))*w2, sin(d2*(pi/180))*w2);
	auto f=[&](Point p)
	{
		double t=sqrt(3)/2;
		int ans1=-1;
		REP(j,100)
		{
			for(int i=-100;i<100;i++)
			{
				if((i+j)%2==0)
				{
					Point a(i/2.0, t*j);
					Point b((i+1)/2.0, t*(j+1));
					Point c((i-1)/2.0, t*(j+1));
					int f1=ccw(a, p, b);
					int f2=ccw(b, p, c);
					int f3=ccw(c, p, a);
					if(abs(f1+f2+f3)==3)
					{
						//print("yes",i,j);
						int r=0;
						if(j%4==0 || j%4==3) r=2;
						if(j%2==0)
							ans1=(r+200-i)%4;
						else
							ans1=(r+i+200)%4;
					}
				}
				else
				{
					Point a((i-1)/2.0, t*j);
					Point b((i+1)/2.0, t*(j));
					Point c((i)/2.0, t*(j+1));
					int f1=ccw(a, p, b);
					int f2=ccw(b, p, c);
					int f3=ccw(c, p, a);
					if(abs(f1+f2+f3)==3)
					{
						//print("yes",i,j);
						int r=0;
						if(j%4==0 || j%4==3) r=2;
						if(j%2==0)
							ans1=(r+200-i)%4;
						else
							ans1=(r+i+200)%4;
					}
				}
			}
		}
		return ans1;
	};
	//print(p1.real(), p1.imag(), p2.real(), p2.imag());
	//print(f(p1), f(p2));
	if(f(p1)==f(p2))
	print("YES");
	else
	print("NO");
}

Measured memory_bytes: 3556