시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 128 MB85562.500%

문제

Steganography is a special way to protect messages — instead of encryption, the message is somehow hidden. Historically, it was quite a popular technique, but nowadays it is superseded by ciphers, especially those based on keys. However, sometimes it may still be in use. One of the digital steganographic techniques is to hide small pieces of information into a digital image. The image modification is so small that it cannot be spotted by a human eye, but the information (such as a text message) is there and readable by computers. Your task is to compare two images and find such (possibly small) differences.

In this problem, we will focus on vector pictures. Your program is given two pictures and it should decide whether they contain the same image. Geometrically speaking, decide whether the two picture are similar, that means whether they can be transformed into each other using translation, rotation, and uniform scaling (but not mirroring). An example of two similar pictures follows.

입력

The input file consists of several test cases, each of them containing two vector pictures. Each picture is described by a sequence of instructions for a plotter device, one instruction per row. Every instruction begins with an uppercase letter followed by one space character and two integer coordinates separated by another space. The letter is either “L” (draw a line) or “M” (move without drawing). The coordinates specify the place to which the line is to be drawn or the current position moved. Coordinates are always given relatively to the end position of the previous instruction. The first instruction is relative to some (unspecified) starting point.

The last instruction of each picture is followed by a row containing the letter “E” (end) and an empty line. The last test case will be followed by a row containing the letter “Q” (quit).

The number of instructions for any picture is between 0 and 1000, inclusive. No instruction has both coordinates equal to zero. The absolute value of all (relative) coordinates is at most 1000.

출력

For each test case, print one line containing either the word “YES” (two pictures are similar) or “NO” (pictures are not similar).

예제 입력 1

L 3 1
L 3 1
M 3 0
M 0 1
L -3 -1
E

L 1 0
L -1 0
E

L 1 0
L 0 1
E

L 1 0
L -1 -1
E

L 2 0
L 1 1
L 0 1
L 2 3
L 0 1
L -1 1
L -2 0
L -1 -1
L 0 -1
L 2 -3
M 1 0
L -2 0
M 2 0
L 0 -1
L -1 1
L -1 -1
L 0 1
E

L 2 -4
L 3 -1
L 2 1
L 1 -2
L -2 -1
L 1 3
L -3 1
L 2 1
L 1 -2
L 8 -1
L 2 1
L 1 3
L -2 4
L -3 1
L -2 -1
L -4 -7
E

Q

예제 출력 1

YES
NO
YES