AtCoder Beginner Contest 447
D
取 ABC 2
Take ABC 2
AtCoder
⌀ 430
原题
←E →

取 ABC 2AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

You are given a string $S$ consisting of the three characters A, B, and C.

给定一个仅由 A、B、C 三种字符组成的字符串 $S$。AI (CI翻译)

Define an operation as follows:

定义如下操作:AI (CI翻译)

Choose a tuple $(i, j, k)$ satisfying $1 \le i \lt j \lt k \le |S|$, $S_i =$ A, $S_j =$ B, and $S_k =$ C, and remove the $i$-th, $j$-th, and $k$-th characters from $S$. The remaining characters are packed to the left in their original order.

选择一个满足 $1 \le i \lt j \lt k \le |S|$、$S_i =$ A、$S_j =$ B 且 $S_k =$ C 的三元组 $(i, j, k)$,并从 $S$ 中删除第 $i$、第 $j$、第 $k$ 个字符。剩余字符按照原有顺序向左紧密排列。

AI (CI翻译)

Find the maximum number of times the operation can be performed on string $S$.

求最多可以对字符串 $S$ 执行多少次该操作。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \le |S| \le 10^{6}$
  • $S$ is a string consisting of A, B, and C.
  • $1 \le |S| \le 10^{6}$
  • $S$ 是一个仅由 A、B、C 组成的字符串。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

输入从标准输入按以下格式给出:AI (CI翻译)

S

S
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output the answer.

输出答案。AI (CI翻译)

样例

Input #1
ABACBCC
Output #1
2
The operation can be performed twice as follows: - For `ABACBCC`, perform the operation with $(i, j, k) = (1, 2, 7)$. The remaining string is `ACBC`. - For `ACBC`, perform the operation with $(i, j, k) = (1, 3, 4)$. The remaining string is `C`. The operation cannot be performed three or more times, so the answer is $2$. Thus, output $2$.
Input #2
CBACBB
Output #2
0
Input #3
BBBAAABCBCBAACBBCAAC
Output #3
5
题目信息
题号
abc447_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。