Description

Suppose that you want to move a game character by using 4 commands. The commands are as follows.

• U: Move upward by one space

• D: Move downward by one space

• R: Move rightward by one space

• L: Move leftward by one space

The character starts from the (0, 0) position on the coordinate plane. The border of the coordinate plane consists of the left top (-5, 5), left bottom (-5, -5), right top (5, 5), and right bottom (5, -5).

For example, assume that you command to the character as "ULURRDLLU".

• From the first through the 7-th command, the character moves as follows.

• From the 8-th through the 9-th command, the character moves as follows.

At this point, you want to know the length of the spaces where the character moves for the first time among the roads where the character passes. For example, in the above case, the character moved by the length of 9, but the length of spaces where the character moved for the first time is 7. (The spaces moved by the 8-th and the 9-th commands are already visited by the second and the third commands.)

But, the command moving over the border of the coordinate plane is ignored.

For example, assume that you command to the character as "LULLLLLLU".

• The character moves according to the first through the 6-th command and ignores the 7-th and the 8-th commands. And then, the character moves according to the 9-th command.

At this point, the length of spaces where the character moves for the first time is 7.

Given the commands `dirs` as parameter, write a function `solution` to return the length of spaces where the character moves for the first time.

Constraints
• `dirs` is given in the string format, and there is no character other than 'U', 'D', 'R', and 'L'.
• Length of `dirs` is natural number less than or equal to 500.