#P8715. [蓝桥杯 2020 省 AB2] 子串分值

[蓝桥杯 2020 省 AB2] 子串分值

Problem Description

For a string SS, we define its value f(S)f(S) as the number of characters that appear exactly once in SS. For example, $f\left({ }^{\prime \prime} \mathrm{aba}{ }^{\prime \prime}\right)=1$, $f\left({ }^{\prime \prime} \mathrm{abc}{ }^{\prime \prime}\right)=3$, and $f\left({ }^{\prime \prime} \mathrm{aaa} \mathrm{a}^{\prime \prime}\right)=0$.

Now given a string S[0..n1]S[0..n-1] (with length nn), please compute the sum of f(S[i..j])f(S[i..j]) over all non-empty substrings S[i..j]S[i..j] (0ij<n)(0 \leq i \leq j < n).

Input Format

Input one line containing a string SS consisting of lowercase letters.

Output Format

Output an integer representing the answer.

ababc
21

Hint

For 20%20\% of the testdata, 1n101 \leq n \leq 10.

For 40%40\% of the testdata, 1n1001 \leq n \leq 100.

For 50%50\% of the testdata, 1n10001 \leq n \leq 1000.

For 60%60\% of the testdata, 1n100001 \leq n \leq 10000.

For all testdata, 1n1000001 \leq n \leq 100000.

Lanqiao Cup 2020, second round provincial contest, Group A Problem H (Group B Problem H).

Translated by ChatGPT 5