cswork / OAOpen practice workspace

CitadelOA #21

Palindromic Substrings

Estimated MediumJudge-ready

Topics (AI-labelled)PalindromesTwo Pointers

Count all palindromic substrings; the same text occurring at different positions is counted separately. The original body is truncated, but aaa→6 and its enumeration make this rule clear; it differs from the distinct-text count of problem 4.

Input

One line containing a lowercase string; complete original bound 1≤length≤1000.

Output

Output a single integer, the answer.

Example 1

Input:

abc

Output:

3

Example 2

Input:

aaa

Output:

6

Example 3

Input:

abba

Output:

6

Example notes

The outputs of the three public examples are, in order: 3; 6; 6. These answers were verified by independent enumeration or direct simulation.

Editorial

Loading solution…