Problem p03018 - Generation 1

Orig Description

Score : 600 points
Problem StatementYou are given a string s consisting of A, B and C.
Snuke wants to perform the following operation on s as many times as possible:
Choose a contiguous substring of s that reads ABC and replace it with BCA.
Find the maximum possible number of operations.
Constraints
1 \leq |s| \leq 200000
Each character of s is A, B and C.
InputInput is given from Standard Input in the following format:
s
OutputFind the maximum possible number of operations.
Sample Input 1ABCABC
Sample Output 13
You can perform the operations three times as follows: ABCABC → BCAABC → BCABCA → BCBCAA. This is the maximum result.
Sample Input 2C
Sample Output 20
Sample Input 3ABCACCBABCBCAABCB
Sample Output 36

Extracted Specification

Canonicalized Input Description:

A string \( s \) of length \( n \) (1 ≤ \( n \) ≤ 200000) consisting only of the characters 'A', 'B', and 'C'.

### Example Input:

```
ABCABC
```

### Function Signature:
Write a function f(s) that takes in the input.
```python
def f(s: str):
    '''
    s: a string consisting of the characters 'A', 'B', and 'C'
    '''
```

Test Case Generator

Sure, I can help you write a test case generator for the given problem statement. Here's a Python function to generate random test cases for the problem:

```python
import random

def tcgen():
    # Length of the string |s| between 1 and 200000
    length = random.randint(1, 200000)
    
    # Generate a random string of length `length` consisting of 'A', 'B', 'C'
    s = ''.join(random.choice('ABC') for _ in range(length))
    
    return s

# Example usage
if __name__ == "__main__":
    for _ in range(5):
        print(tcgen())
```

Explanation:

1. We first determine the length of the string `s`, which is a random integer between 1 and 200000.
2. We then generate a random string of the determined length, where each character is randomly chosen from the set {'A', 'B', 'C'}.
3. The generated string `s` is returned as the test case.

This function will help you generate different test cases with varying lengths and compositions of 'A', 'B', and 'C'. You can adjust the number of test cases to be generated by changing the range in the example usage section.

Extract Arguments

def extract_arguments(fh):
    s = fh.readline().strip()
    return s