cswork / OAOpen practice workspace

IntuitOA #9

DNA Sequencing — Palindrome Transformation Cost

HardJudge-ready

Topics (AI-labelled)PalindromesPrefix & Ranges

For each contiguous substring of the string, compute the minimum number of characters to change so that the substring becomes a palindrome, then find the sum of these costs over all substrings. This site follows the original problem's in-order palindrome definition, so characters cannot be rearranged.

See below for this site's input format and constraints.

Input

A single line containing a string dna of lowercase English letters only. This site uses 1≤|dna|≤100000.

Output

Output the sum of the palindrome change costs over all contiguous substrings.

Example 1

Input:

asbsd

Output:

11

Example 2

Input:

a

Output:

0

Example 3

Input:

aaa

Output:

0

Editorial

Loading solution…