cswork / OAOpen practice workspace

Pure StorageOA #7

Count Palindromic Substrings

Estimated MediumJudge-ready

Topics (AI-labelled)Palindromes

Given a lowercase string s, count all position pairs (i,j) with i≤j such that s[i..j] is a palindrome. Identical content at different positions is counted separately. The second upstream example gives the output for wowyouwin as 14, which conflicts with this definition; counting position by position as the statement defines gives 10, and this site uses 10.

Input

One line containing a non-empty string of only a-z. Added by this site: 1≤|s|≤200000.

Output

Output the number of palindromic substring occurrences, as a 64-bit integer.

Example 1

Input:

hellolle

Output:

13

Example 2

Input:

wowyouwin

Output:

10

Example 3

Input:

aa

Output:

3

Editorial

Loading solution…