#K88432. Count Single-Letter Substrings

    ID: 37307 Type: Default 1000ms 256MiB

Count Single-Letter Substrings

Count Single-Letter Substrings

You are given a string s consisting of lowercase letters. Your task is to compute the number of substrings of s that are made up of exactly one distinct letter. A substring is a contiguous sequence of characters.

For example, consider the string "aaaa". All its substrings are "a", "aa", "aaa", "aaaa" and the various overlapping ones. The total number of such substrings can be computed per contiguous block of repeated characters using the formula:

L(L+1)2,\frac{L\cdot(L+1)}{2},

where L is the length of the contiguous block.

Input: A single string s provided via standard input.

Output: An integer that represents the total count of substrings containing exactly one distinct letter.

Examples:

  • Input: aaaa → Output: 10
  • Input: abc → Output: 3
  • Input: abab → Output: 4
  • Input: zzzz → Output: 10

inputFormat

The input consists of a single line containing the string s.

You may assume that s consists only of lowercase English letters.

outputFormat

Output a single integer representing the total number of substrings that contain exactly one distinct letter.

## sample
aaaa
10