#abc329c. C - Count xxx

C - Count xxx

Score : 300300 points

问题描述

给定一个长度为 NN 的由小写英文字母组成的字符串 SS

找出 SS 中由单一字符重复构成的非空子串的数量。这里,即使两个子串以不同的方式获得,只要它们作为字符串相等,就加以区分。

SS 的非空子串是指通过从 SS 的起始处删除零个或多个字符,并从结尾处删除零个或多个字符后得到的长度至少为一的字符串。例如,ababcabc 的非空子串,而 ac 和空字符串则不是。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a string SS of length NN consisting of lowercase English letters.

Find the number of non-empty substrings of SS that are repetitions of one character. Here, two substrings that are equal as strings are not distinguished even if they are obtained differently.

A non-empty substring of SS is a string of length at least one obtained by deleting zero or more characters from the beginning and zero or more characters from the end of SS. For example, ab and abc are non-empty substrings of abc, while ac and the empty string are not.

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • SS is a string of length NN consisting of lowercase English letters.

Input

The input is given from Standard Input in the following format:

NN

SS

Output

Print the number of non-empty substrings of SS that are repetitions of one character.

Sample Input 1

6
aaabaa

Sample Output 1

4

The non-empty substrings of SS that are repetitions of one character are a, aa, aaa, and b; there are four of them. Note that there are multiple ways to obtain a or aa from SS, but each should only be counted once.

Sample Input 2

1
x

Sample Output 2

1

Sample Input 3

12
ssskkyskkkky

Sample Output 3

8

update @ 2024/3/10 01:54:02