#K12731. Robot Final Position

    ID: 23756 Type: Default 1000ms 256MiB

Robot Final Position

Robot Final Position

You are given a robot starting at the origin \( (0,0) \). The robot executes a series of commands. Each command instructs the robot to move in one of the four cardinal directions: up (U), down (D), left (L), or right (R). The command is given in the format DIRECTION STEPS, where STEPS is a non-negative integer.

The final position \( (x, y) \) of the robot is computed as follows:

[ \begin{aligned} x &= \sum_{i=1}^{n} \Delta x_i, \ y &= \sum_{i=1}^{n} \Delta y_i, \end{aligned} ]

where for each command, \( \Delta x_i \) and \( \Delta y_i \) are determined by the direction of the command.

Example:

  • Input: 5 commands: "U 3", "R 2", "D 1", "L 4", "D 2"
  • Output: -2 0 because the robot moves to \( (-2,0) \).

inputFormat

The first line of input contains an integer \( n \) representing the number of commands. Each of the next \( n \) lines contains a command in the format DIRECTION STEPS, where DIRECTION is one of U, D, L, R and STEPS is an integer.

outputFormat

Output the final coordinates of the robot, \( x \) and \( y \), separated by a space.

## sample
5
U 3
R 2
D 1
L 4
D 2
-2 0