AmazonOA #165
Find Maximum Score
估计困难可在线判题
A non-empty contiguous substring contributes 1 point if every pair of adjacent characters differs by at most 1 in alphabet position; a single character contributes 1 point in total. You may change at most one character of the original string to any lowercase letter; find the highest total score. The condition only constrains adjacent characters; it does not require the difference between the largest and smallest letters of the whole segment to be ≤1.
输入格式
One line with a lowercase string. This site sets 1≤length≤100000.
输出格式
Output a single integer answer.
样例 1
输入:
aabacfgh
输出:
21
样例 2
输入:
abcb
输出:
10
样例 3
输入:
abez
输出:
7
样例说明
Example 1: changing c to b gives aababfgh; the first segment of length 5 contributes 15 and the last segment of length 3 contributes 6, for a total of 21. Example 2: the whole string is already smooth, so all 10 substrings score. Example 3: changing e to a gives abaz; the first three characters contribute 6 and z contributes 1, for a total of 7.