Type: Default 2000ms 256MiB

1D Keyboard

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Problem Statement

There is a keyboard with 2626 keys arranged on a number line.

The arrangement of this keyboard is represented by a string SS, which is a permutation of ABCDEFGHIJKLMNOPQRSTUVWXYZ. The key corresponding to the character SxS_x is located at coordinate xx (1x26)(1 \leq x \leq 26). Here, SxS_x denotes the xx-th character of SS.

You will use this keyboard to input ABCDEFGHIJKLMNOPQRSTUVWXYZ in this order, typing each letter exactly once with your right index finger. To input a character, you need to move your finger to the coordinate of the key corresponding to that character and press the key.

Initially, your finger is at the coordinate of the key corresponding to A. Find the minimal possible total traveled distance of your finger from pressing the key for A to pressing the key for Z. Here, pressing a key does not contribute to the distance.

Constraints

  • SS is a permutation of ABCDEFGHIJKLMNOPQRSTUVWXYZ.

Input

The input is given from Standard Input in the following format:

SS

Output

Print the answer.

Sample Input 1

ABCDEFGHIJKLMNOPQRSTUVWXYZ

Sample Output 1

25

From pressing the key for A to pressing the key for Z, you need to move your finger 11 unit at a time in the positive direction, resulting in a total traveled distance of 2525. It is impossible to press all keys with a total traveled distance less than 2525, so print 25.

Sample Input 2

MGJYIZDKSBHPVENFLQURTCWOAX

Sample Output 2

223

SDNU_ACM_ICPC_2024_WEEKLY_PRACTICE_1st

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
8
Start at
2024-10-27 18:30
End at
2024-10-27 21:30
Duration
3 hour(s)
Host
Partic.
39