Tango Tango Insurrection

Time limit1sMemory limit128 MB

Problem

You are learning a simple arcade dancing game. The dance pad has four arrows arranged in a plus shape — Up, Left, Down, and Right:

      Up
Left        Right
      Down

While a song plays, arrows scroll up the screen, and the moment one reaches the top you must tap the matching arrow on the pad with your foot. Merely standing on an arrow does not count — you have to actually tap it. There is no penalty for stepping on an arrow you did not need. Your goal is to find the least tiring way to perform a given sequence of arrows.

Time is measured in eighth-note units. At every unit your left foot and your right foot each rest on a distinct arrow. During a single time unit at most one foot may perform an action (moving to another arrow and/or tapping); jumping (moving both feet at once) is not allowed. You must keep facing the screen, which restricts which foot may reach which arrow.

The energy an action costs depends on what that same foot did in the immediately preceding time unit:

  • If the foot did not act in the previous unit, the action costs 1.
  • If the foot did act in the previous unit, it costs:
    • 3 if it stays on the same arrow (a double-tap),
    • 5 if it moves to an adjacent arrow (Up–Left, Up–Right, Down–Left, or Down–Right),
    • 7 if it moves directly across the pad (Up–Down or Left–Right).

Doing nothing with a foot costs no energy and resets that foot, so its next action costs only 1 again. Ideally you alternate feet through a run of consecutive arrows.

Facing forward, you normally cannot place your left foot on Right or your right foot on Left. There is one exception, a temporary crossover: if your left foot is on Up or Down, you may twist and place your right foot on Left — but until your right foot leaves Left again, you cannot move your left foot to a different arrow. Symmetrically, if your right foot is on Up or Down, you may cross your left foot onto Right, and then your right foot is pinned until your left foot leaves Right.

Input

The input contains several arrow sequences. Each sequence is a single line of 1 to 70 characters. Each character is one of U, L, D, R (the arrow that must be tapped at that time unit) or . (no arrow needs to be tapped at that time unit). At the first time unit of every sequence your left foot starts on Left and your right foot starts on Right.

There are at most 100 sequences. The input ends with a line containing a single #.

Output

For each sequence, print one line containing a single integer: the minimum total energy needed to perform the entire sequence under the rules above.