ZOAC 2
InterviewTime limit1sMemory limit512 MB
A disk holds the 26 uppercase letters in a circle, and an arrow starts at 'A'. Find the minimum total rotations needed to print a given string in order.
- Level
Easy3 of 10
- Topics
- Implementation, Greedy, String, Simulation
- Solved
- No attempts yet
Problem
In December 2019, Sungho, who is in charge of the opening of the second ZOAC, wants to promote ZOAC more spectacularly than anyone else.
Thinking last year's ZOAC format was too boring, Sungho came up with a new rule for showing a string!

The rules are as follows.
- Letters are written in order on a disk like the one in the picture. At the first moment, the arrow points at 'A'.
- The disk can be turned left or right. Turning the disk by one position takes 1 unit of time.
- The letter the arrow points at can be printed. Printing a letter takes no time.
The participants of ZOAC would get bored if it took too long, so Sungho wants to print the given string from front to back as quickly as possible.
For the busy Sungho, find the minimum time needed to print the given string.
Input
The first line gives a string consisting of uppercase English letters. The length of the string is at most 100. The empty string is not given.
Output
Print the minimum time needed to print the given string.
Hint
ZOAC is short for Zero One Algorithm Contest, an algorithm contest hosted by 'Younggwaoil', the algorithm club of Hanyang University ERICA.