Robot On a Grid


Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

A robot is situated in the Cartesian Plane and is currently on \((0,0)\).
It is then given \(N\) instructions (followed sequentially), either to go one unit left (\(L\)), right (\(R\)), up (\(U\)), or down (\(D\)).

Input Specification

The first line will contain the integer \(N\) (\(1 \le N \le 10^5\)), the number of instructions. The second line contains the string of the \(N\) instructions.

Output Specification

Print two space-separated integers: the final coordinates of the robot.

Sample Input

5
LRUDL

Sample Output

-1 0

We can simulate the robot's movements:
\((0,0)\) -> \((-1,0)\) -> \((0,0)\) -> \((0,1)\) -> \((0,0)\) -> \((-1,0)\)


Comments

There are no comments at the moment.