logo AlgoBeat OnlineJudge
登录 注册

#217801. [JAG 2026 Summer Camp #2] Take Many ABA

内存限制:2048 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 .

输入格式

The input is given in the following format:

S

is a string consisting of A, B, and ?, and its length is between and , inclusive.

输出格式

Print the answer.

样例

样例输入 1

A?B?

样例输出 1

2

样例输入 2

?B?A?B?

样例输出 2

15

样例输入 3

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

样例输出 3

4595728

数据范围与提示

The possible strings and their corresponding values of for the first sample are as follows:

  • : .
  • : .
  • : .
  • : .

Therefore, the answer is .