"Title description"
Alan is a typist in a confidential department, and she's now getting a job: you need to enter hundreds of passwords with a fixed length of 6 in a day. Of course, she wants to enter the process of hitting the keyboard the less the total number of the better.
Unfortunately, due to the need for confidentiality, the department used to enter the password of the keyboard is specially designed, there is no number keys on the keyboard, and only the following six keys: Swap0, Swap1, up, down, left, right, in order to illustrate the role of these 6 keys, we first define the input area of the 6 position number, 1,2,3,4,5,6 from left to right. The following lists the functions of each key:
Swap0: Press SWAP0, the position of the cursor is unchanged, the number of the position of the cursor and the input area of the number 1th position (the first number on the left) exchange. If the cursor is already in the entry area of position 1th, then press Swap0 key, the number of the input area is unchanged;
Swap1: Press SWAP1, the position of the cursor is unchanged, the number of the position of the cursor and the input area of the number 6th position (the sixth number on the left) exchange. If the cursor is already in the entry area of position 6th, then press SWAP1 key, the number of the input area is unchanged;
Up: Press up, the cursor position is unchanged, and the number of the cursor position is 1 (unless the number is 9). For example, if the number at the cursor position is 2, the number is changed to 3 after pressing up, and if the number is 9, the number does not change and the cursor position is not changed;
Down: Press down, the position of the cursor is unchanged, the number of the position of the cursor minus 1 (unless the number is 0), if the number is 0, then press down, the number is unchanged, the cursor position is unchanged;
Left: The cursor will not move if the cursor is already in position 1th of the entry area (the first position from the left), by pressing the ieft, and moving the pointer to one position.
Right: If the cursor is already positioned at position 6th in the entry area (sixth position from the left), the cursor is not moved.
Of course, in order to make such a keyboard function, each time the password entered, the input area will always randomly appear a length of 6 initial password, and the cursor is fixed in position 1th. When the above six special keys are cleverly used, the target password can be obtained, at which point the cursor is allowed to stop at any one location.
Now, Alan needs your help, write a program to find the minimum number of keystrokes required to enter a password.
"Input description"
The file is only one line, containing two lengths of 6 digits, the former is the initial password, the latter is the target password, two passwords separated by a space.
"Output description"
The file has only one row and contains a positive integer, which is the minimum number of keystrokes required.
"Sample Input"
123456
654321
"Sample Output"
11
"Data range and Tips"
The time limit should be 8s.
The initial password is 123456, and the cursor stops at the number 1. The keystroke sequence corresponding to the minimum number of keystrokes mentioned above is:
Keystroke sequence: |
The entry area after the keystroke (underline indicates where the cursor is located) |
|
123456 |
Swap1 |
623451 |
Right |
623451 |
Swap0 |
263451 |
Down |
253451 |
Right |
253451 |
Up |
254451 |
Right |
254451 |
Down |
254351 |
Right |
254351 |
Up |
254361 |
Swap0 |
654321 |
The minimum number of keystrokes is 11.
Smart Typist.