#P9232. [蓝桥杯 2023 省 A] 更小的数
[蓝桥杯 2023 省 A] 更小的数
Problem Description

Xiao Lan has a string of length consisting only of digit characters , with indices from to . You can treat it as an -digit decimal number . Xiao Lan can choose a continuous substring of and reverse that substring, at most once. Xiao Lan wants the new number obtained by reversing the chosen substring and putting it back into its original position to satisfy . Please help him compute how many different substring choices there are in total. As long as the positions of the two substrings in are not exactly the same, we consider them different choices.
Note that leading zeros are allowed, i.e., the most significant digit of the number may be , and this is valid.
Input Format
Input one line containing a string of length representing (containing only digit characters ). From left to right, the indices are .
Output Format
Output one line containing an integer representing the answer.
210102
8
Hint
Sample Explanation.
There are different choices in total:
- The chosen substring indices are , after reversing .
- The chosen substring indices are , after reversing .
- The chosen substring indices are , after reversing .
- The chosen substring indices are , after reversing .
- The chosen substring indices are , after reversing .
- The chosen substring indices are , after reversing .
- The chosen substring indices are , after reversing .
- The chosen substring indices are , after reversing .
Constraints.
For of the testdata, .
For of the testdata, .
For all testdata, .
Translated by ChatGPT 5