Just a Joystick
InterviewTime limit1sMemory limit1024 MB
Given two equal-length uppercase strings, find the fewest up or down joystick moves to change one into the other, with wrap-around between A and Z.
Problem
You just got the high score when playing Battlezone Asteroids Pac-Centipede on an arcade machine. On the 'Game Over' screen, you can enter your initials, one letter at a time. This arcade machine is modern, so it allows many more initials than the three that original machines accepted. You select the letters with only a joystick. For each letter, you move the joystick up or down to cycle through the letters, wrapping between 'Z' and 'A' in both directions. You move it to the right to go to the next letter.
The initials of the previous high-score winner are still filled in. Entering your own initials takes some time, and you want to know exactly how long. Using the most efficient method, how many times do you need to move the joystick up or down to enter your own initials?
Moves to the right are not counted.
Input
The first line contains an integer (), the number of letters available to enter your initials.
The second line contains a string of length , the initials of the previous high-score winner.
The third line contains a string of length , the initials that you want to enter.
The strings consist only of English uppercase letters (A-Z).
Output
Output the minimum number of times you should move the joystick up or down to enter your own initials. Moves to the right are not included.