#D6061. Rendezvous on a Tetrahedron

    ID: 5032 Type: Default 1000ms 268MiB

Rendezvous on a Tetrahedron

Rendezvous on a Tetrahedron

Problem G Rendezvous on a Tetrahedron

One day, you found two worms PP and QQ crawling on the surface of a regular tetrahedron with four vertices AA, BB, CC and DD. Both worms started from the vertex AA, went straight ahead, and stopped crawling after a while.

When a worm reached one of the edges of the tetrahedron, it moved on to the adjacent face and kept going without changing the angle to the crossed edge (Figure G.1).

Write a program which tells whether or not PP and QQ were on the same face of the tetrahedron when they stopped crawling.

You may assume that each of the worms is a point without length, area, or volume.

Figure G.1. Crossing an edge

Incidentally, lengths of the two trails the worms left on the tetrahedron were exact integral multiples of the unit length. Here, the unit length is the edge length of the tetrahedron. Each trail is more than 0:001 unit distant from any vertices, except for its start point and its neighborhood. This means that worms have crossed at least one edge. Both worms stopped at positions more than 0:001 unit distant from any of the edges.

The initial crawling direction of a worm is specified by two items: the edge XYXY which is the first edge the worm encountered after its start, and the angle dd between the edge AXAX and the direction of the worm, in degrees.

Figure G.2. Trails of the worms corresponding to Sample Input 1

Figure G.2 shows the case of Sample Input 1. In this case, PP went over the edge CDCD and stopped on the face opposite to the vertex AA, while QQ went over the edge DBDB and also stopped on the same face.

Input

The input consists of a single test case, formatted as follows.

XPYPX_PY_P dPd_P lPl_P XQYQX_QY_Q dQd_Q lQl_Q

XWYWX_WY_W (W=P,QW = P,Q) is the first edge the worm WW crossed after its start. XWYWX_WY_W is one of BC, CD or DB.

An integer dWd_W (1dW591 \leq d_W \leq 59) is the angle in degrees between edge AXWAX_W and the initial direction of the worm WW on the face AXWYW\triangle AX_WY_W.

An integer lWl_W (1lW201 \leq l_W \leq 20) is the length of the trail of worm WW left on the surface, in unit lengths.

Output

Output YES when and only when the two worms stopped on the same face of the tetrahedron. Otherwise, output NO.

Sample Input 1

CD 30 1 DB 30 1

Sample Output 1

YES

Sample Input 2

BC 1 1 DB 59 1

Sample Output 2

YES

Sample Input 3

BC 29 20 BC 32 20

Sample Output 3

NO

Example

Input

CD 30 1 DB 30 1

Output

YES

inputFormat

Input 1

Figure G.2 shows the case of Sample Input 1. In this case, PP went over the edge CDCD and stopped on the face opposite to the vertex AA, while QQ went over the edge DBDB and also stopped on the same face.

Input

The input consists of a single test case, formatted as follows.

XPYPX_PY_P dPd_P lPl_P XQYQX_QY_Q dQd_Q lQl_Q

XWYWX_WY_W (W=P,QW = P,Q) is the first edge the worm WW crossed after its start. XWYWX_WY_W is one of BC, CD or DB.

An integer dWd_W (1dW591 \leq d_W \leq 59) is the angle in degrees between edge AXWAX_W and the initial direction of the worm WW on the face AXWYW\triangle AX_WY_W.

An integer lWl_W (1lW201 \leq l_W \leq 20) is the length of the trail of worm WW left on the surface, in unit lengths.

outputFormat

Output

Output YES when and only when the two worms stopped on the same face of the tetrahedron. Otherwise, output NO.

Sample Input 1

CD 30 1 DB 30 1

Sample Output 1

YES

Sample Input 2

BC 1 1 DB 59 1

Sample Output 2

YES

Sample Input 3

BC 29 20 BC 32 20

Sample Output 3

NO

Example

Input

CD 30 1 DB 30 1

Output

YES

样例

CD 30 1
DB 30 1
YES