#C4994. Maximize Points from Consecutive Characters

    ID: 48593 Type: Default 1000ms 256MiB

Maximize Points from Consecutive Characters

Maximize Points from Consecutive Characters

You are given a string s of length n consisting of lowercase letters. Your task is to determine the maximum number of points you can obtain by grouping consecutive identical characters. For each contiguous group of identical characters of length L, you earn points. The final score is the sum of points for all groups.

Example: For the string aaabba (with n = 6), the groups are: "aaa", "bb", and "a". The points earned are:

  • For "aaa": 3² = 9 points
  • For "bb": 2² = 4 points
  • For "a": 1² = 1 point

Total points = 9 + 4 + 1 = 14.

You need to implement a function to compute the total points based on this rule.

inputFormat

The input is read from standard input and consists of two lines:

  1. The first line contains an integer n (1 ≤ n ≤ 105), which is the length of the string.
  2. The second line contains the string s of length n comprising lowercase English letters.

outputFormat

Output the maximum number of points that can be earned, printed on standard output as an integer.

## sample
6
aaabba
14

</p>