Skip to main content
Back to problems
Codeforces
Easy
Arrays
Simulation
Trace

Determine the final location of a point after a sequence of directional moves and report the trace of its movement.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Trace

You are given a sequence of moves on a 2D grid. Starting from the origin (0,0)(0, 0), 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 nn — the number of moves.
  • The second line contains a string of length nn describing the moves.
  • Each character is one of U, D, L, R.

Interpretation:

  • U increases yy by 1
  • D decreases yy by 1
  • L decreases xx by 1
  • R increases xx by 1

Output Format

Print two integers: the final xx and yy coordinates after performing all moves.

Constraints

  • 1n1051 \le n \le 10^5
  • The move string has length nn
  • All characters are valid direction commands
Examples
Sample cases returned by the problem API.

Example 1

Input

5
RRULD

Output

1 0

Explanation

Start at (0,0)(0,0). After R R U L D, the position becomes (1,0)(1,0).

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.