QOJ.ac

QOJ

Time Limit: 3.0 s Memory Limit: 2048 MB

#22862. Take Many ABA

Statistics

For a string $T$ consisting of A and B, define $f(T)$ as the maximum number of times the following operation can be performed.

Operation: Remove ABA that appears as a (not necessarily contiguous) subsequence of $T$, and close up the resulting gaps.

You are given a string $S$ consisting of A, B, and ?. Find the sum of $f(T)$ over all strings $T$ obtained by replacing each ? in $S$ with either A or B, modulo $998244353$.

Input

The input is given in the following format:

$$S$$

$S$ is a string consisting of A, B, and ?, and its length is between $3$ and $1000$, inclusive.

Output

Print the answer.

Examples

Input 1

A?B?

Output 1

2

Input 2

?B?A?B?

Output 2

15

Input 3

????????????????????

Output 3

4595728

Note

The possible strings $T$ and their corresponding values of $f(T)$ for the first sample are as follows:

  • $T = \texttt{AABA}$: $f(T) = 1$.
  • $T = \texttt{AABB}$: $f(T) = 0$.
  • $T = \texttt{ABBA}$: $f(T) = 1$.
  • $T = \texttt{ABBB}$: $f(T) = 0$.

Therefore, the answer is $1 + 0 + 1 + 0 = 2$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.