#d2563. 子串分值和

子串分值和

Sum of Substring Values

Problem Description

For a string SS, we define f(S)f(S) as the number of distinct characters that appear in SS. For example f(aba)=2f(aba) = 2, f(abc)=3f(abc) = 3, f(aaa)=1f(aaa) = 1.

Now you are given a string SS (suppose its length is lenlen). Please compute $\sum\limits_{i=0}^{len-1} \sum\limits_{j=i}^{len-1} f(S[i:j])$.

Input Format

One line containing a string SS consisting of lowercase letters.

Output Format

Output one integer, the answer.

Sample Input

ababc

Sample Output

28

Constraints

For all data, the string length len≤1 000 000len \leq 1\,000\,000, and string indices run from 00 to len−1len-1.