- Time limit: 1.00 s
- Memory limit: 512 MB
You are given a description of a robot's path. The robot begins at point and performs commands. Each command moves the robot some distance up, down, left or right.
The robot will stop when it has performed all commands, or immediately when it returns to a point that it has already visited. Your task is to calculate the total distance the robot moves.
Input
The first input line has an integer : the number of commands.
After that, there are lines describing the commands. Each line has a character and an integer : the robot moves the distance to the direction . Each direction is U (up), D (down), L (left), or R (right).
Output
Print the total distance the robot moves.
Constraints
Example
Input:
5 U 2 R 3 D 1 L 5 U 2
Output:
9