Training Site
Sideways banner

Keyboard

Input: Standard Input (stdin)
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 at A.
  • The + key changes the selected character to the next character in the alphabet. If the last selected character was Z, it changes it to A instead.
  • The - key changes the selected character to the previous character in the alphabet. If the last selected character was A, it changes it to Z 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/or B characters.
  • Subtask 2 (50%): No further restrictions apply.

Sample Explanation

In the first sample case, the optimal solution contains the following 7 keystrokes:

  1. Press the + key to change the selected character from A to B.
  2. Press the SEND key to type B.
  3. Press the - key to change the selected character from B to A.
  4. Press the SEND key to type A.
  5. Press the - key to change the selected character from A to Z".
  6. Press the - key to change the selected character from Z to Y".
  7. Press the SEND key to type Y.

In the second sample case, the optimal solution contains the following 6 keystrokes:

  1. Press the SEND key to type A.
  2. Press the + key to change the selected character from A to B.
  3. Press the SEND key to type B.
  4. Press the SEND key to type B.
  5. Press the - key to change the selected character from B to A".
  6. Press the SEND key to type A.
  • Sample Input 1

    BAY
    

    Sample Output 1

    7
    
  • Sample Input 2

    ABBA
    

    Sample Output 2

    6