#P9043. [PA 2021] Zbalansowane słowa

[PA 2021] Zbalansowane słowa

Problem Description

A string ss is defined to be good if and only if all characters contained in it appear the same number of times.

Examples of good strings: mama, aabbcbcccbaa.

Examples of bad strings: ovo.

Given a string ss, find the number of good substrings of ss.

Input Format

One line containing a string ss.

Output Format

One line containing an integer, representing the required value.

aabbabcccba
28

Hint

For 100%100\% of the testdata, 1s3×1051 \leq |s| \leq 3 \times 10^5, and ss contains only the three lowercase letters a, b, c.

Translated by ChatGPT 5