Orig Description
Score : 700 points
Problem StatementYou are given a string S consisting of a,b and c. Find the number of strings that can be possibly obtained by repeatedly performing the following operation zero or more times, modulo 998244353:
Choose an integer i such that 1\leq i\leq |S|-1 and the i-th and (i+1)-th characters in S are different. Replace each of the i-th and (i+1)-th characters in S with the character that differs from both of them (among a, b and c).
Constraints
2 \leq |S| \leq 2 × 10^5
S consists of a, b and c.
InputInput is given from Standard Input in the following format:
S
OutputPrint the number of strings that can be possibly obtained by repeatedly performing the operation, modulo 998244353.
Sample Input 1abc
Sample Output 13
abc, aaa and ccc can be obtained.
Sample Input 2abbac
Sample Output 265
Sample Input 3babacabac
Sample Output 36310
Sample Input 4ababacbcacbacacbcbbcbbacbaccacbacbacba
Sample Output 4148010497
Extracted Specification
An integer \( |S| \) (2 ≤ \( |S| \) ≤ 2 × 10^5), representing the length of a string.
A string \( S \) consisting of characters from the set {'a', 'b', 'c'}.
### Example Input:
```
5
abbac
```
### Function Signature:
Write a function f(S) that takes in the input.
```python
def f(S: str):
'''
S: a string
'''
```
Test Case Generator
Sure! To create a test case generator for the given problem statement, we need to generate random strings composed of the characters 'a', 'b', and 'c' with lengths between 2 and 200,000. Here's a Python function to generate such test cases:
```python
import random
def generate_test_case():
# Length of the string
length = random.randint(2, 2 * 10**5)
# Generate a random string of the given length consisting of 'a', 'b', and 'c'
S = ''.join(random.choice(['a', 'b', 'c']) for _ in range(length))
return S
# Example usage:
for _ in range(5): # Generate 5 test cases for demonstration
print(generate_test_case())
```
This function will generate a string `S` of random length between 2 and 200,000 characters. Each character in the string will be randomly chosen from the set {'a', 'b', 'c'}.
You can call this function multiple times to generate different test cases. The generated strings can then be used as input for testing your solution to the problem.
Extract Arguments
def extract_arguments(fh):
S = fh.readline().strip()
return (S,)