#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <cmath>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const double pi = acos(-1);
const double t = sqrt(3)/2;

int judge1(int x)
{
  if(x==0)
    return 1;
  if(x==1)
    return 3;
  if(x==2)
    return 4;
  if(x==3)
    return 2;
}

int judge2(int x)
{
  if(x==0)
    return 3;
  if(x==1)
    return 1;
  if(x==2)
    return 2;
  if(x==3)
    return 4;
}

int judge3(int x)
{
  if(x==0)
    return 3;
  if(x==1)
    return 4;
  if(x==2)
    return 1;
  if(x==3)
    return 2;
}

int judge4(int x)
{
  if(x==0)
    return 4;
  if(x==1)
    return 3;
  if(x==2)
    return 2;
  if(x==3)
    return 1;
}

int judge5(int x)
{
  if(x==0)
    return 4;
  if(x==1)
    return 1;
  if(x==2)
    return 3;
  if(x==3)
    return 2;
}

int judge6(int x)
{
  if(x==0)
    return 1;
  if(x==1)
    return 4;
  if(x==2)
    return 2;
  if(x==3)
    return 3;
}

int main()
{
//  cout << t << endl;

//  cout << pi/90.0 << endl;

  char s1[5],s2[5];
  double d1,l1;
  double d2,l2;
  scanf("%s%lf%lf",s1,&d1,&l1);
  scanf("%s%lf%lf",s2,&d2,&l2);
  //double sum1 = 0,sum2 = 0;
  int t1 = d1;
  int t2 = d2;
  int id1,id2;

//  cout << d1 << " " << l1 << endl;
//  cout << d2 << " " << l2 << endl;

  d1 = d1*pi/180;
  d2 = d2*pi/180;
  if(s1[0]=='B'&&s1[1]=='D')
    d1 = 2*pi/3-d1;
  if(s2[0]=='B'&&s2[1]=='D')
    d2 = 2*pi/3-d2;
  if(s1[0]=='C'&&s1[1]=='B')
    d1 = 2*pi/3-d1;
  if(s2[0]=='C'&&s2[1]=='B')
    d2 = 2*pi/3-d2;
  if(s1[0]=='D'&&s1[1]=='C')
    d1 = 2*pi/3-d1;
  if(s2[0]=='D'&&s2[1]=='C')
    d2 = 2*pi/3-d2;

//  cout << d1 << " " << l1 << endl;
//  cout << d2 << " " << l2 << endl;


  //di yi ge
  double a,b;
  double sita = 2*pi/3-d1;

//  cout << d1 << " ++ " << sita << endl;
//  cout << 2.0*pi/180 << " +++ " << 118.0*pi/180 << endl;

  a = l1*sin(sita)/t;
  b = l1*sin(d1)/t;

//  cout << (2*l1*sin(pi*2.0/3.0-d1)/t) << " +=+ " << (l1/t)*sin(d1) << endl;
//  cout << a << " ++ " << b << endl;

  int h1 = floor(a);
  double ans1 = a-h1;
  h1++;
  int y1 = floor(b);
  double res1 = b-y1;
  int cnt1;
  if(res1<ans1)
    cnt1 = y1*2+1;
  else
    cnt1 = y1*2+2;

  //di er ge
  double a2,b2;
  double sita2 = 2*pi/3-d2;
  a2 = l2*sin(sita2)/t;
  b2 = l2*sin(d2)/t;

//  cout << a2 << " ++ " << b2 << endl;

  int h2 = floor(a2);
  double ans2 = a2-h2;
  h2++;
  int y2 = floor(b2);
  double res2 = b2-y2;
  int cnt2;
  if(res2<ans2)
    cnt2 = y2*2+1;
  else
    cnt2 = y2*2+2;

//    cout << h1 << " " << cnt1 << endl;
//    cout << h2 << " " << cnt2 << endl;

  //BC
  if((s1[0]=='B'&&s1[1]=='C')||(s1[0]=='C'&&s1[1]=='B'))
  {
    if(h1%2==1)
    {
      id1 = judge1(cnt1%4);
    }
    else
    {
      id1 = judge2(cnt1%4);
    }
  }

  if((s2[0]=='B'&&s2[1]=='C')||(s2[0]=='C'&&s2[1]=='B'))
  {
    if(h2%2==1)
    {
      id2 = judge1(cnt2%4);
    }
    else
    {
      id2 = judge2(cnt2%4);
    }
  }

  //CD
  if((s1[0]=='C'&&s1[1]=='D')||(s1[0]=='D'&&s1[1]=='C'))
  {
    if(h1%2==1)
    {
      id1 = judge3(cnt1%4);
    }
    else
    {
      id1 = judge4(cnt1%4);
    }
  }

  if((s2[0]=='C'&&s2[1]=='D')||(s2[0]=='D'&&s2[1]=='C'))
  {
    if(h2%2==1)
    {
      id2 = judge3(cnt2%4);
    }
    else
    {
      id2 = judge4(cnt2%4);
    }
  }

  //DB
  if((s1[0]=='D'&&s1[1]=='B')||(s1[0]=='B'&&s1[1]=='D'))
  {
    if(h1%2==1)
    {
      id1 = judge5(cnt1%4);
    }
    else
    {
      id1 = judge6(cnt1%4);
    }
  }

  if((s2[0]=='B'&&s2[1]=='D')||(s2[0]=='D'&&s2[1]=='B'))
  {
    if(h2%2==1)
    {
      id2 = judge5(cnt2%4);
    }
    else
    {
      id2 = judge6(cnt2%4);
    }
  }

  if(t1==30)
  {
    //BD
    if((s1[0]=='D'&&s1[1]=='B')||(s1[0]=='B'&&s1[1]=='D'))
    {
      double aa = l1/(sqrt(2)+1);
      int aaa = floor(aa);
      double bb = l1-(double)aaa*(sqrt(2)+1);
      if(bb<sqrt(2)/2)
        id1 = 1;
      else
        id1 = 2;
    }
    //CD
    if((s1[0]=='C'&&s1[1]=='D')||(s1[0]=='D'&&s1[1]=='C'))
    {
      double aa = l1/(sqrt(2)+1);
      int aaa = floor(aa);
      double bb = l1-(double)aaa*(sqrt(2)+1);
      if(bb<sqrt(2)/2)
        id1 = 4;
      else
        id1 = 2;
    }
    //BC
    if((s1[0]=='B'&&s1[1]=='C')||(s1[0]=='C'&&s1[1]=='B'))
    {
      double aa = l1/(sqrt(2)+1);
      int aaa = floor(aa);
      double bb = l1-(double)aaa*(sqrt(2)+1);
      if(bb<sqrt(2)/2)
        id1 = 3;
      else
        id1 = 2;
    }
  }

  if(t2==30)
  {
    //BD
    if((s2[0]=='D'&&s2[1]=='B')||(s2[0]=='B'&&s2[1]=='D'))
    {
      double aa = l2/(sqrt(2)+1);
      int aaa = floor(aa);
      double bb = l2-(double)aaa*(sqrt(2)+1);
      if(bb<sqrt(2)/2)
        id2 = 1;
      else
        id2 = 2;
    }
    //CD
    if((s2[0]=='C'&&s2[1]=='D')||(s2[0]=='D'&&s2[1]=='C'))
    {
      double aa = l2/(sqrt(2)+1);
      int aaa = floor(aa);
      double bb = l2-(double)aaa*(sqrt(2)+1);
      if(bb<sqrt(2)/2)
        id2 = 4;
      else
        id2 = 2;
    }
    //BC
    if((s2[0]=='B'&&s2[1]=='C')||(s2[0]=='C'&&s2[1]=='B'))
    {
      double aa = l2/(sqrt(2)+1);
      int aaa = floor(aa);
      double bb = l2-(double)aaa*(sqrt(2)+1);
      if(bb<sqrt(2)/2)
        id2 = 3;
      else
        id2 = 2;
    }
  }



  if(id1==id2)
  {
    printf("YES\n");
  }
  else {
    printf("NO\n");
}
  return 0;
}


Measured memory_bytes: 3400