AT_abc447_d [ABC447D] Take ABC 2

Description

You are given a string $ S $ consisting of the three characters `A`, `B`, and `C`. Define an operation as follows: > 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. Find the maximum number of times the operation can be performed on string $ S $ .

Input Format

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

Output Format

Output the answer.

Explanation/Hint

### Sample Explanation 1 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 $ . ### Constraints - $ 1 \le |S| \le 10^{6} $ - $ S $ is a string consisting of `A`, `B`, and `C`.