Codeforces Round 258 (Div. 2)
D
Count Good Substrings
Codeforces
2000
原题
← CE →
翻译中…

We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba".

翻译中…

Given a string, you have to find two values:

翻译中…
  1. the number of good substrings of even length;
  2. the number of good substrings of odd length.
翻译中…

Input

翻译中…

The first line of the input contains a single string of length $*n*$ ($1 ≤ *n* ≤ 10^{5}$). Each character of the string will be either 'a' or 'b'.

翻译中…

Output

翻译中…

Print two space-separated integers: the number of good substrings of even length and the number of good substrings of odd length.

翻译中…

Note

翻译中…

In example 1, there are three good substrings ("b", "b", and "bb"). One of them has even length and two of them have odd length.

翻译中…

In example 2, there are six good substrings (i.e. "b", "a", "a", "b", "aa", "baab"). Two of them have even length and four of them have odd length.

翻译中…

In example 3, there are seven good substrings (i.e. "b", "a", "b", "b", "bb", "bab", "babb"). Two of them have even length and five of them have odd length.

翻译中…

Definitions

翻译中…

A substring $*s*[*l*, *r*]$ $(1 ≤ *l* ≤ *r* ≤ *n*)$ of string $*s* = *s*_{1}*s*_{2}... *s*_{*n*}$ is string $*s*_{*l*}*s*_{*l* + 1}... *s*_{*r*}$.

翻译中…

A string $*s* = *s*_{1}*s*_{2}... *s*_{*n*}$ is a palindrome if it is equal to string $*s*_{*n*}*s*_{*n* - 1}... *s*_{1}$.

翻译中…

样例

Input #1
bb
Output #1
1 2
InputCopy OutputCopy
Input #2
baab
Output #2
2 4
InputCopy OutputCopy
Input #3
babb
Output #3
2 5
InputCopy OutputCopy
Input #4
babaa
Output #4
2 7
InputCopy OutputCopy
题目信息
题号
451D
时间限制
2 s
内存限制
256 MB
标签
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。