cswork / OAOpen practice workspace

AmazonOA #55

Count Removable Indices

Estimated MediumJudge-ready

Topics (AI-labelled)StringsTwo Pointers

Given a lowercase string that is already a palindrome, count the indices whose removal still leaves a palindrome; equal characters at different indices are counted separately.

Input

A single line containing a palindrome string of length 2..100000.

Output

Output a single integer answer.

Example 1

Input:

zzz

Output:

3

Example 2

Input:

abba

Output:

2

Example 3

Input:

abcba

Output:

1

Example notes

Example 1: removing any z gives zz, 3 indices in total. Example 2: only one of the two middle b can be removed, giving aba, 2 in total. Example 3: only removing the center c gives abba, so the answer is 1.

Editorial

Loading solution…