eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

High Score

High Score

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 '\textbf{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 '\textbf{Z}' is '\textbf{A}' and the letter preceding '\textbf{A}' is '\textbf{Z}'. Moving the joystick left or right changes the selection one step to the left or right, respectively. The selection also wraps around, so moving left when the first letter is selected will select the last letter and vice versa. 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. \InputFile On the first line a positive integer: the number of test cases, at most \textbf{100}. After that per test case: \begin{itemize} \item One line with a string \textbf{s} (\textbf{1} ≤ \textbf{length(s)} ≤ \textbf{1000}) consisting of uppercase letters: the name that you want to enter. \end{itemize} \OutputFile Per test case: \begin{itemize} \item One line with an integer: the minimum number of joystick moves needed. \end{itemize}
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
2
JEROEN
JAN
Выходные данные #1
56
23
Источник NWERC-2010