#P10566. 「Daily OI Round 4」Analysis

「Daily OI Round 4」Analysis

Problem Description

Xiao C's IT teacher assigned Xiao C some homework, as follows:

There is a string containing uppercase letters, lowercase letters, and digits. You may change any character into another character. Suppose the ASCII code of the character before the change is aa, and after the change is bb. Then this change costs ab|a-b| units of time. You need to turn the entire string into a string that contains only uppercase letters.

Xiao C also has many other important assignments such as Chinese, math, and English. To save time, you need to calculate the minimum time Xiao C needs to make the string contain only uppercase letters.

Input Format

One line containing a string ss, which is the string given by the teacher.

Output Format

One line containing a non-negative integer tt, representing the minimum total time needed to make the string contain only uppercase letters.

AA0aa
31
3kyOu
89

Hint

Sample Explanation

For the first sample, the best way is to change it into AAAZZ\texttt{AAAZZ}. Then the cost is 0+0+4865+9790+9790=310+0+|48-65|+|97-90|+|97-90|=31. It is easy to prove that there is no better solution.

Here, 4848 is the ASCII code of character 0\texttt{0}, 6565 is the ASCII code of character A\texttt{A}, 9090 is the ASCII code of character Z\texttt{Z}, and 9797 is the ASCII code of character a\texttt{a}.

Constraints

This problem uses bundled testdata.

Let lenlen be the length of string ss.

Subtask\text{Subtask} Score lenlen \le
00 1010 33
11 3030 1010
22 6060 10510^5

For all testdata, it is guaranteed that 1len1051 \le len \le 10^5, and ss contains only uppercase letters, lowercase letters, and digits.

Translated by ChatGPT 5