409795: GYM103743 L Collecting Diamonds

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

L. Collecting Diamondstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Our best explorer, Vingying, finds a deep cave that is full of diamonds! Well, he is a very careful man, so he decides to do some research before collecting them.

The diamonds can be divided into three kinds, noted as $$$\text{A,B,C}$$$ for convenience. There are a total of $$$n$$$ diamonds in a row, which can be regarded as a sequence $$$s_1,s_2,\dots,s_n$$$ from left to right. Vingying will perform the operation several times, which consists of the following three steps in order.

  1. Choose an index $$$i$$$ ($$$1\le i \le n - 2$$$) satisfying $$$s_i = \text{A}$$$, $$$s_{i+1}=\text{B}$$$, $$$s_{i+2}=\text{C}$$$.
  2. If the index is odd, then collect $$$s_i$$$ and $$$s_{i+2}$$$; otherwise, collect $$$s_{i+1}$$$.
  3. Update $$$n$$$ to the number of diamonds left and reindex the diamonds.

For example, $$$s=\text{ABCABC}$$$. We can choose index $$$1$$$ and collect $$$1,3$$$, then $$$s$$$ becomes $$$\text{BABC}$$$ indexed $$$1,2,3,4$$$. But if we choose index $$$4$$$ and collect $$$5$$$, then $$$s$$$ becomes $$$\text{ABCAC}$$$ indexed $$$1,2,3,4,5$$$.

Vingying wants to know the maximum number of operations (not the diamonds) he can do.

Input

The input contains a string consisting of only $$$\text{A,B,C}$$$ representing the sequence of the diamonds. The length of the string won't exceed $$$2\times10^5$$$.

Output

Output a single integer representing the maximum number of operations.

ExamplesInput
ABCAAABCCC
Output
2
Input
AABCAAABCCC
Output
4

加入题单

上一题 下一题 算法标签: