printРабочее место участника

printЗадачи

1913. High Score

Ограничения: время – 200ms/500ms, память – 256MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

You've just been playing a video game in which you had to move a worm through a maze using a joystick. You got the high score, and now you have to enter your name using this joystick. This works as follows.
The initial name displayed on the screen is a string consisting only of 'A' characters. Initially the first letter of the string is selected. When you move the joystick forward, the selected letter is changed to the letter that immediately follows it in the alphabet. When you move the joystick backward, the selected letter is changed to the letter that immediately precedes it in the alphabet. The alphabet wraps around, so the letter following 'Z' is 'A' and the letter preceding 'A' is 'Z'.
Moving the joystick left or right changes the selection one step to the left or right, respectively. The selection does not wrap around, so moving left when the first letter is selected or right when the last letter is selected does not change the selection.
Because you would like to spend as little time as possible on entering your name, you want to know the smallest possible number of joystick moves needed to do this. Given the name you want to enter, write a program that calculates the minimum number of moves needed. You may assume that the length of the initial string is the same as the length of the name that you want to enter. Furthermore, it does not matter which letter is selected at the end of the process.
Input Format
The first line of input contains a single word less than 15 uppercase letters: the name that you want to enter.
Output Format
Output one line with an integer: the minimum number of joystick moves needed.

Sample Input

JAN

Sample Output

24
loading