Just a Joystick
시간 제한1초메모리 제한1024 MB
n개의 위치마다 A부터 Z까지 순환하는 알파벳에서 이전 글자를 원하는 글자로 바꾸는 최소 위/아래 이동 횟수를 구해 모두 더한다.
문제
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 seems to be a very modern arcade machine: whereas the original arcade machines only allowed entering three initials, this machine allows many more. However, to select the letters, you have access to just a joystick. For every letter, you need to move the joystick up or down to cycle between the letters (wrapping around between 'Z' and 'A', in both directions) and move it to the right to move to the next letter.
It appears that the initials of the previous high-score winner are still filled in. Entering your own initials is going to take some time, and you want to know exactly how long. How many times do you need to you move the joystick up or down to enter your own initials, if you do so in the most efficient way?
입력
The input consists of:
- One line with an integer (), the number of letters available to enter your initials.
- One line with a string of length , the initials of the previous high-score winner.
- One line with a string of length , the initials that you want to enter.
The strings only consist of English uppercase letters (A-Z).
출력
Output the minimum number of times you should move the joystick up or down to enter your own initials. This does not include the number of times that you need to move the joystick to the right.