#K13391. Count Single Character Substrings

    ID: 23902 Type: Default 1000ms 256MiB

Count Single Character Substrings

Count Single Character Substrings

Given a string s consisting of lowercase English letters, your task is to count the number of substrings that contain exactly one distinct character.

A substring is a contiguous sequence of characters within the string. For example, for the string "aaab", there are 7 substrings that contain exactly one distinct character:

  • "a" (occurs 3 times)
  • "aa" (occurs 2 times)
  • "aaa" (occurs 1 time)
  • "b" (occurs 1 time)

The mathematical formulation for a group of consecutive similar characters of length \( k \) is:

\( \sum_{i=1}^{k} i = \frac{k (k+1)}{2} \)

Use this observation to efficiently compute the required count.

inputFormat

The input is a single line containing a string \( s \) composed of lowercase English letters. The string can be empty.

outputFormat

Output a single integer, the number of substrings of \( s \) that contain exactly one distinct character.

## sample
aaab
7