取 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.
AI (CI翻译)选择一个满足
$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$个字符。剩余字符按照原有顺序向左紧密排列。
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 ofA,B, andC.
$1 \le |S| \le 10^{6}$$S$是一个仅由A、B、C组成的字符串。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
S
SAI (CI翻译)
Output
输出格式
AI (CI翻译)Output the answer.
输出答案。AI (CI翻译)
样例
ABACBCC
2
CBACBB
0
BBBAAABCBCBAACBBCAAC
5
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。