Keyboard
Output: Standard Output (stdout)
Memory limit: 64 megabytes
Time limit: 1.0 seconds
In an attempt to increase your typing speed for the next round of the New Zealand Informatics Competition, you've bought yourself a new keyboard. But manufacturers have lately been following some inexplicable trend of removing useful features from their products, so your new keyboard is only able to type the uppercase characters from A
to Z
. It also has only 3 keys:
- The
SEND
key sends the selected character to the computer. The selected character initially starts atA
. - The
+
key changes the selected character to the next character in the alphabet. If the last selected character wasZ
, it changes it toA
instead. - The
-
key changes the selected character to the previous character in the alphabet. If the last selected character wasA
, it changes it toZ
instead.
You'd like to know how long it will take you to type certain words. Given a string s consisting of up to 1000 uppercase characters, determine the minimum number of keystrokes required to type s using your new keyboard.
Input
There is a single line, containing the string s. It is guaranteed that s is non-empty, and consists of up to 1000 uppercase English characters.
Output
You should print a single integer – the minimum number of keystrokes required to type the string s using your new keyboard.
Subtasks
- Subtask 1 (50%): s consists of only
A
and/orB
characters. - Subtask 2 (50%): No further restrictions apply.
Sample Explanation
In the first sample case, the optimal solution contains the following 7 keystrokes:
- Press the
+
key to change the selected character fromA
toB
. - Press the
SEND
key to typeB
. - Press the
-
key to change the selected character fromB
toA
. - Press the
SEND
key to typeA
. - Press the
-
key to change the selected character fromA
to Z". - Press the
-
key to change the selected character fromZ
to Y". - Press the
SEND
key to typeY
.
In the second sample case, the optimal solution contains the following 6 keystrokes:
- Press the
SEND
key to typeA
. - Press the
+
key to change the selected character fromA
toB
. - Press the
SEND
key to typeB
. - Press the
SEND
key to typeB
. - Press the
-
key to change the selected character fromB
to A". - Press the
SEND
key to typeA
.
-
Sample Input 1
BAY
Sample Output 1
7
-
Sample Input 2
ABBA
Sample Output 2
6