Question
Count Substrings with Equal Characters
You are given a string of length KaTeX can only parse string typed expression consisting of lowercase English letters. Your task is to count the number of substrings such that all characters in the substring are equal.
A substring is defined as a contiguous sequence of characters in the string.
Input
The first line contains a single integer KaTeX can only parse string typed expression — the length of the string.
The second line contains a string KaTeX can only parse string typed expression of length KaTeX can only parse string typed expression, consisting of lowercase English letters.
The second line contains a string KaTeX can only parse string typed expression of length KaTeX can only parse string typed expression, consisting of lowercase English letters.
Output
Print a single integer — the number of substrings where all characters are equal.
Example
Input
5
aaaba
Output
8
Explanation
Valid substrings with all equal characters:
"a" (index 0)
"a" (index 1)
"a" (index 2)
"b" (index 3)
"a" (index 4)
"aa" (indices 0–1)
"aa" (indices 1–2)
"aaa" (indices 0–2)
Total = 8 substrings.
5
aaaba
Output
8
Explanation
Valid substrings with all equal characters:
"a" (index 0)
"a" (index 1)
"a" (index 2)
"b" (index 3)
"a" (index 4)
"aa" (indices 0–1)
"aa" (indices 1–2)
"aaa" (indices 0–2)
Total = 8 substrings.