#P9043. Count Good Substrings
Count Good Substrings
Count Good Substrings
Given a string \( s \), a substring is considered good if and only if every distinct character in the substring appears the same number of times. In other words, a substring \( t \) is good if for every character \( c \) in \( t \), its frequency is equal to that of every other character in \( t \).
Examples:
mama
is good because the frequency of 'm' and 'a' are both 2.aabbcbcccbaa
is good.ovo
is not good because the frequencies are not equal.
Your task is to count the number of good substrings of the given string \( s \).
inputFormat
The input consists of a single line containing the string \( s \). The string does not contain spaces and consists of lowercase English letters.
outputFormat
Output a single integer, which is the number of good substrings in \( s \).
sample
a
1