#K35227. Robot Return to Origin

    ID: 25485 Type: Default 1000ms 256MiB

Robot Return to Origin

Robot Return to Origin

You are given the starting position of a robot on a 2D plane and a sequence of movement commands. Each command consists of a direction and a distance. The directions can be 'N' for North, 'S' for South, 'E' for East, and 'W' for West. The robot moves according to the commands in sequence. Your task is to determine if the robot returns to its starting position after executing all the commands.

Note: The commands are executed in order, and the movement commands affect the robot's coordinates in the usual way: North increases the y-coordinate, South decreases the y-coordinate, East increases the x-coordinate, and West decreases the x-coordinate.

Mathematically, if the starting position is \((x, y)\), after the sequence of commands the final position \((x_f, y_f)\) will be:

[ x_f = x + \sum_{i=1}^{n} d_i\text{ (if direction is E) } - \sum_{i=1}^{n} d_i\text{ (if direction is W) } ] [ y_f = y + \sum_{i=1}^{n} d_i\text{ (if direction is N) } - \sum_{i=1}^{n} d_i\text{ (if direction is S) } ]

Output "Yes" if \((x_f, y_f) = (x, y)\) otherwise output "No".

inputFormat

The input is read from standard input and has the following format:

  • The first line contains two integers: x and y, representing the starting position of the robot.
  • The second line contains an integer n, denoting the number of commands.
  • The following n lines each contain a command. Each command consists of a character (one of N, S, E, W) and an integer representing the distance to move in that direction.

outputFormat

Print a single line to standard output. It should be "Yes" if the robot returns to the starting position after executing all commands, and "No" otherwise.

## sample
0 0
4
N 1
S 1
E 2
W 2
Yes

</p>