Determine the final location of a point after a sequence of directional moves and report the trace of its movement.
Trace
You are given a sequence of moves on a 2D grid. Starting from the origin , each move changes the current position by one unit in one of the four cardinal directions: up, down, left, or right.
Your task is to process all moves in order and output the final coordinates of the point. The problem is primarily a straightforward simulation of the movement sequence.
Input Format
- The first line contains an integer — the number of moves.
- The second line contains a string of length describing the moves.
- Each character is one of
U,D,L,R.
Interpretation:
Uincreases by 1Ddecreases by 1Ldecreases by 1Rincreases by 1
Output Format
Print two integers: the final and coordinates after performing all moves.
Constraints
- The move string has length
- All characters are valid direction commands
Example 1
Input
5 RRULD
Output
1 0
Explanation
Start at . After R R U L D, the position becomes .
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.