#C10033. Robot's Final Position
Robot's Final Position
Robot's Final Position
In this problem, you are given a grid of size \(n \times m\) and a robot which initially starts at the top-left cell of the grid at position \((1, 1)\). The robot receives \(t\) commands, each being one of the following: "UP", "DOWN", "LEFT", or "RIGHT". For each command, the robot moves one cell in the corresponding direction if the movement keeps the robot within the grid boundaries. Otherwise, the command is ignored.
Movement details in \(\LaTeX\): $$ \text{UP}: (r, c) \to (r-1, c), \quad \text{DOWN}: (r, c) \to (r+1, c), \quad \text{LEFT}: (r, c) \to (r, c-1), \quad \text{RIGHT}: (r, c) \to (r, c+1) $$
Your task is to compute and output the final position of the robot after executing all commands.
inputFormat
The input is given via standard input (stdin) and has the following format:
- The first line contains two integers \(n\) and \(m\), representing the number of rows and columns of the grid.
- The second line contains an integer \(t\), representing the number of commands.
- The next \(t\) lines each contain a single command: "UP", "DOWN", "LEFT", or "RIGHT".
outputFormat
Output the final row and column positions of the robot as two space-separated integers on one line to stdout.
## sample5 5
7
DOWN
DOWN
RIGHT
UP
LEFT
LEFT
DOWN
3 1