#P17551. [JAG 2026 Summer Camp #2] Take Many ABA
[JAG 2026 Summer Camp #2] Take Many ABA
Problem Description
For a string consisting of A and B, define as the maximum number of times the following operation can be performed.
Operation: Remove ABA that appears as a (not necessarily contiguous) subsequence of , and close up the resulting gaps.
You are given a string consisting of A, B, and ?. Find the sum of over all strings obtained by replacing each ? in with either A or B, modulo .
Input Format
The input is given in the following format:
S
is a string consisting of A, B, and ?, and its length is between and , inclusive.
Output Format
Print the answer.
A?B?
2
?B?A?B?
15
????????????????????
4595728
Hint
The possible strings and their corresponding values of for the first sample are as follows:
- : .
- : .
- : .
- : .
Therefore, the answer is .