#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
#include <iomanip>
//#include <unordered_map>
//#include <unordered_set>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;


const int INF=0x3f3f3f3f;
//const ll INFF=1200000000000000000ll;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=3e5+5;
const int MOD=1e9+7;
const double pi=acos(-1.0);
//#define double long double
//#define ls T[k].l
//#define rs T[k].r
const double eps=1e-6;
//#define double long double
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
//#define double long double
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline int powMM(int a,int b,int M){
    int ret=1;
    a%=M;
    while (b){
        if (b&1) ret=1LL*ret*a%M;
        b>>=1;
        a=1LL*a*a%M;
    }
    return ret;
}
inline int add(int x,int y){x%=MOD;y%=MOD;return (1LL*x+y)%MOD;}
//inline int add(int x,int y){x+=y;if(x>=MOD)x-=MOD;return x;}
inline void addi(int &x,int y){y%=MOD;x+=y;if(x>=MOD)x-=MOD;}
inline int mul(int x,int y){return 1LL*x*y%MOD;}
//inline void addi(int &x,int y){x%=MOD;y%=MOD;(x+=y)%=MOD;}
inline void muli(int &x,int y){x%=MOD;y%=MOD;x=1LL*x*y%MOD;if(x<0)x+=MOD;}
inline void mod(int &x){if(x<0){x%=MOD;x=(x+MOD)%MOD;}}

//ll mul(ll a , ll b,ll Q){
//    return (a * b - (ll) ((long double)a * b / Q) * Q) % Q;
//}
//#define debug
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);

char as[20];
int len,deg;
double x,y;
int xc,yc;
double z[10];
double es;
double getd(double z){
    return z/180.0*pi;
}
int c[4][10]={{1,2,3,4},{4,2,1,3},{3,2,4,1}};
int a[105][105];
int cal1(){
    xc=yc=0;

    y=1.0*len*sin(getd(deg));
    x=1.0*len*cos(getd(deg));


    while(y>es)y-=es,++yc;

    z[0]=(es-y)/es*1.0;
    z[1]=1.0-z[0];
    int now=0;
    x-=yc*1.0/2.0;
    x-=z[0]/2.0*y/(es-y);
//    cout<<x<<endl;
    while(x>z[now]){
        x-=z[now];++xc;
        now^=1;
    }
//    cout<<xc<<" "<<yc<<endl;
    return a[yc][xc];
}
void init(int who){
    for(int i=0;i<4;i++)a[0][i]=c[who][i];
    for(int j=4;j<=100;j++)a[0][j]=a[0][j-4];
    for(int i=1;i<=100;i++)
        for(int j=0;j<=100;j++){
            int pre=(3-j%4+4)%4;
            a[i][j]=a[i-1][pre];
        }
//    for(int i=2;i>=0;i--,printf("\n"))
//        for(int j=0;j<=5;j++)
//            printf("%d ",a[i][j]);
}
int main()
{
    scanf("%s%d%d",as,&deg,&len);
    es=sqrt(3.0)/2.0;
    int val;
    if(as[0]=='B')val=0;
    else if(as[0]=='C')val=1;
    else if(as[0]=='D')val=2;
    init(val);

    int p1=cal1();

    scanf("%s%d%d",as,&deg,&len);
    es=sqrt(3.0)/2.0;
    if(as[0]=='B')val=0;
    else if(as[0]=='C')val=1;
    else if(as[0]=='D')val=2;
    init(val);

    int p2=cal1();
//    cout<<p1<<" "<<p2<<endl;
    if(p1==p2)printf("YES\n");
    else printf("NO\n");
    return 0;
}
/*

*/



Measured memory_bytes: 3420