7027.Special Substrings

Time Limit: 1s Memory Limit: 512MB

A substring is called special if every character that appears in the string appears the same number of times in the substring.

Your task is to count the number of special substrings in a given string.

Input Format(From the terminal/stdin)

The only input line has a string of length $n$ . Every character is between a...z.

  • $1 \le n \le 2 \cdot 10^5$

Output Format(To the terminal/stdout)

Print one integer: the number of special substrings.

Sample Input

Copy
abccabab
        \n

Sample Output

Copy
5
 \n

The special substrings are abc , cab , abccab , bccaba and ccabab .

Source: CSES, Additional Problems I, 2186

Submit

请先 登录

© 2025 FAQs