#C4403. Return to Origin with Minimum Moves

    ID: 47938 Type: Default 1000ms 256MiB

Return to Origin with Minimum Moves

Return to Origin with Minimum Moves

You are given a sequence of moves represented by the characters 'U', 'D', 'L', and 'R'. The moves change the robot's position on a 2D plane starting at the origin (0, 0). 'U' increments the y-coordinate, 'D' decrements the y-coordinate, 'L' decrements the x-coordinate, and 'R' increments the x-coordinate.

Your task is to compute the minimum number of moves required to return the robot to the origin after it has executed a given sequence of moves. Mathematically, if the final displacement of the robot is (x, y), then the answer is computed as \(|x| + |y|\).

inputFormat

The input consists of two lines:

  • The first line contains an integer n, representing the number of moves.
  • The second line contains a string of length n consisting only of the characters 'U', 'D', 'L', 'R'.

outputFormat

Output a single integer, which is the minimum number of moves required to return to the origin.

## sample
6
UUDDLR
0