Question
Equal Count Substrings
You are given a string KaTeX can only parse string typed expression of length KaTeX can only parse string typed expression consisting only of characters KaTeX can only parse string typed expression, KaTeX can only parse string typed expression, and KaTeX can only parse string typed expression. Your task is to count the number of substrings in which the number of occurrences of KaTeX can only parse string typed expression, KaTeX can only parse string typed expression, and KaTeX can only parse string typed expression are equal.
Input
The first line contains a single integer KaTeX can only parse string typed expression — the length of the string.
The second line contains the string KaTeX can only parse string typed expression of length KaTeX can only parse string typed expression, consisting only of characters KaTeX can only parse string typed expression, KaTeX can only parse string typed expression, and KaTeX can only parse string typed expression.
Output
Print a single integer — the number of substrings where the count of KaTeX can only parse string typed expression, KaTeX can only parse string typed expression, and KaTeX can only parse string typed expression are equal.
Example
Input
6
abcabc

Output
5

Explanation
Valid substrings with equal number of 'a', 'b', and 'c':
(0, 2) → "abc"
(1, 3) → "bca"
(2, 4) → "cab"
(3, 5) → "abc"
(0, 5) → "abcabc"
Total = 5 substrings.

Online