cswork / OAOpen practice workspace

AmazonOA #319

Optimized Identifiers

Estimated MediumJudge-ready

Topics (AI-labelled)StringsTwo Pointers

In each step, delete the first or the last character of the current string. The type of a string is its first character followed by its last character; a single character a has type aa, and the empty string has an empty type. Only the final type must equal the initial type; it may differ temporarily along the way. Find the maximum number of deletions.

Input

One line containing a lowercase string s; the original bounds are 2≤|s|≤200000.

Output

Output a single integer, the answer.

Example 1

Input:

babdcaac

Output:

5

Example 2

Input:

axxbab

Output:

4

Example 3

Input:

aba

Output:

2

Example notes

The answers are 5, 4 and 2. The output 0 of 319's original example babdcaac conflicts with the conclusion 5 in that example's own explanation and with 318, the complete version of the same problem; this site openly corrects it to 5 and binds both raw sources. The type of hchc should be hc, not h. The 318 source only looks at the first occurrence of the last character, so it misses shorter valid ranges further on.

Editorial

Loading solution…