cswork / OAOpen practice workspace

AmazonOA #165

Find Maximum Score

Estimated HardJudge-ready

Topics (AI-labelled)StringsDP Basics

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.

Input

One line with a lowercase string. This site sets 1≤length≤100000.

Output

Output a single integer answer.

Example 1

Input:

aabacfgh

Output:

21

Example 2

Input:

abcb

Output:

10

Example 3

Input:

abez

Output:

7

Example notes

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.

Editorial

Loading solution…