#C3376. Final Position of the Robot
Final Position of the Robot
Final Position of the Robot
Given an (M\times M) grid, a robot is placed at an initial position with coordinates ((R_{start}, C_{start})) (using 1-indexed coordinates) and receives a sequence of commands. Each command is one of the following:
- U: Move up (decrease the row by 1)
- D: Move down (increase the row by 1)
- L: Move left (decrease the column by 1)
- R: Move right (increase the column by 1)
If executing a command causes the robot to leave the grid, that command is ignored. Your task is to determine the final position of the robot after all commands have been executed.
inputFormat
The input is read from standard input (stdin) and consists of two lines. The first line contains three integers (M), (R_{start}), and (C_{start}) separated by spaces, representing the grid size and the starting row and column, respectively. The second line contains a string representing the sequence of commands.
outputFormat
Output the final position of the robot as two space-separated integers (row and column) on a single line, printed to standard output (stdout).## sample
5 3 3
UUDDLLRR
3 3
</p>