#abc373b. B - 1D Keyboard

B - 1D Keyboard

Score : 200200 points

问题陈述

有一个键盘,上面有 2626 个键排列在数轴上。

这个键盘的排列由一个字符串 SS 表示,它是 ABCDEFGHIJKLMNOPQRSTUVWXYZ 的一个排列。对应于字符 SxS_x 的键位于坐标 xx (1x26)(1 \leq x \leq 26)。这里,SxS_x 表示 SS 的第 xx 个字符。

你将使用这个键盘按照顺序输入 ABCDEFGHIJKLMNOPQRSTUVWXYZ,用你的右手食指精确地一次输入每个字母。要输入一个字符,你需要将手指移动到对应于该字符的键的坐标并按下该键。

最初,你的手指位于对应于 A 的键的坐标。找到从按下 A 的键到按下 Z 的键的手指可能的最小总移动距离。这里,按下一个键不计入距离。

以上为大语言模型 kimi 翻译,仅供参考。

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