시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 256 MB 5 2 2 40.000%

문제

Karel wants to register his robot Karel for a robot contest. The aim of the contest is to draw a picture using a program composed of the following instructions:

  • L Xrel Yrel — draw a line segment between the current robot position and the given relative coordinates. The robot moves to the end point of the segment.
  • M Xrel Yrel – move the current position by the given relative offset without drawing a line.

This sounds like a nice contest problem, doesn’t it? We want to give you an idea what it is like to organize a programming contest. All contests held at the Czech Technical University (since the very first one on May 13, 1995) always employed the automated judging of submissions. The output of a contestants’ program is compared with the correct answer by a computer, without the need of human intervention. This may seem obvious today but we should realize that back in the old years, many programming contests in the world used human judges to issue the final verdict. Manual judging then continued for many years in many other regions.

With some contest problems, there is more than one correct answer. In these cases, a special program (called validator ) has to be prepared to review the submission output and to issue a final verdict. Do you want to try out what it is like to write such a program?

Your task is to prepare a validator for the problem described above. The validator reads a picture generated by a contestants’ submission and decides whether it is equivalent to another picture — the correct answer prepared by judges.

Two pictures are considered equivalent if they are composed of the same visible line segments. Note however that the drawing instructions may differ. For instance, some of the segments may be divided into several shorter segments, or even drawn repeatedly. Also note that pictures with a different scale or rotation are considered different.

입력

The input contains several test cases. Each test case consists of two pictures. Each picture starts with a row containing one positive integer N, the number of drawing instructions to follow (1 ≤ N ≤ 5000). Then there are N lines, each containing one instruction. The instruction consists of an uppercase letter, one space and two integers Xi, Yi separated with another space (|Xi|, |Yi| ≤ 1000). The first letter will either be “L” or “M”.

There is one empty line after each test case. You may assume that no real (absolute) coordinate will be further than 30 000 in any direction from the picture starting point.

출력

For each test case, print one line containing either “YES” if the two pictures are equivalent, or “NO” if they differ.

예제 입력

2
L 1 1
L 1 1
1
L -2 -2

2
L 1 1
L 1 1
1
L 3 3

5
L 1 0
L 1 0
L 0 5
L 0 -5
L 2 0
3
L 0 5
M -2 -5
L 4 0

예제 출력

YES
NO
YES

힌트