1079 - Fast Transword Game

Time Limit : 1 Second

Memory Limit : 128 MB

Submission: 37

Solved: 13

Description
All of us know the intellectual Games like Sudoku, Chess and Puzzles. It is said there were many people fond of these games before. Now people meet new games every day. One kind of them is more and more popular, which test our fast imagination and thinking. Many youngs like these games, when they get high scores in the game, they think they are more clever than others.

One of this kind of game is Fast Transword Game, which produced by GA.Co.Ltd, attracts more and more young people.

Fast Transword Game is a game which is played on the mobile products, it can be installed in mobile phone, PDAs. The game's rule is easy, you only need to transform one word to another word by using six buttons. But it's really hard to get a high score, like the Chess, you need to think about the next several steps so that you can have more chance to win.

Myl is a boy who lives on the planet, Earth. He wants to get a score as high as possible, he think that each statement has a best choice. He knows something about computer programming, but he don't know if he can solve it correctly with in the required time.

He have a try himself, but he needs a reference program to check whether it is a correct program, so he needs your help. Try to write a program to find the least number of steps to transform the first word to the second one.

To finish the game, you have to transform the first word to the second word, which has the length of 6. You can use 6 buttons to finish it. For example, you can use Up, Down, Left, Right and another two buttons "SL" and "SR". Like in the figure below, the player have six buttons, four buttons on the right is Up, Down, Left, Right. At the beginning of the game, the player gives you a word to transfer, the cursor is under the first character. Then you use the buttons to transfer it. The usage of the buttons are listed below:

Up: Only the letter on the cursor change to the next letter. The cursor does not move. For example: 'a' -> 'b', 'c' -> 'd', 'z' -> 'a'.

Down: Like the Up button, the letter only change to the previous letter. The cursor also does not move. For examples: 'a' -> 'z', 'b' -> 'a', 'h' -> 'g';

Left: Only the cursor shift to the left one. If it is already under the first letter, it will keep still.

Right: Like the Left button, only the cursor moves to the right one. If it is already under the 6th letter already, it will keep still.

SL: Swap the first letter and the letter under the cursor. The cursor doesn't move.

SR: Swap the Last letter and the letter under the cursor. The cursor doesn't move.
Input
The input contains several test cases. Each test case contains only one line.
Each line has two words, the first is the word waiting to be tranfered. The second is the goal word.
Output
One line for each case,output the least steps you have to push the buttons.
sample input
abcdef fedcba

abcdef abcdfg
sample output
11

7
hint
source
Yang g
© 2015 HUST ACMICPC TEAM. All Right Reserved.