QOJ.ac

QOJ

시간 제한: 3.0 s 메모리 제한: 2048 MB

#22862. קחו הרבה ABA

통계

עבור מחרוזת $T$ המורכבת מהתווים A ו-B, נגדיר את $f(T)$ בתור המספר המרבי של פעמים שבהן ניתן לבצע את הפעולה הבאה.

פעולה: הסירו מופע של ABA המופיע כתת-סדרה (לאו דווקא רציפה) של $T$, וסגרו את הרווחים שנוצרו.

נתונה לכם מחרוזת $S$ המורכבת מהתווים A, B ו-?. מצאו את הסכום של $f(T)$ על פני כל המחרוזות $T$ המתקבלות מהחלפת כל ? ב-$S$ ב-A או ב-B, מודולו $998244353$.

קלט

הקלט ניתן בפורמט הבא:

$$S$$

$S$ היא מחרוזת המורכבת מהתווים A, B ו-?, ואורכה בין $3$ ל-$1000$, כולל.

פלט

הדפיסו את התשובה.

Examples

Input 1

A?B?

Output 1

2

Input 2

?B?A?B?

Output 2

15

Input 3

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

Output 3

4595728

הערה

המחרוזות האפשריות $T$ והערכים המתאימים של $f(T)$ עבור הדוגמה הראשונה הם כדלקמן:

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

לכן, התשובה היא $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.