#ABC104D. We Love ABC
We Love ABC
题目描述
The ABC number of a string is the number of triples of integers that satisfy all of the following conditions:
- ( is the length of .)
-
A
( is the -th character of from the beginning.) -
B
-
C
For example, when ABCBC
, there are three triples of integers that satisfy the conditions: . Thus, the ABC number of is .
You are given a string . Each character of is A
, B
, C
or ?
.
Let be the number of occurrences of ?
in . We can make strings by replacing each occurrence of ?
in with A
, B
or C
. Find the sum of the ABC numbers of all these strings.
This sum can be extremely large, so print the sum mod .
字符串 的 _ABC 数是满足以下所有条件的整数 三元组的个数:
- ( 是 的长度。)
- A`( 是 从头开始的 个字符。)
B
C
例如,当 ABCBC`时,有三个整数三元组 满足条件: .因此, 的 ABC 数是 。
给你一个字符串 。 中的每个字符是
A
、B
、C
或?
。设 是 中出现
?
的次数。我们可以用A
、B
或C
替换 中出现的每个?
,从而组成 字符串。求所有这些字符串的 ABC 数字之和。这个和可能会非常大,因此打印取模为 的和。
输入格式
输入内容按以下格式标准输入:
输出格式
打印所有 字符串的 ABC 数字之和,模数为 。
样例 #1
样例输入 #1
A??C
样例输出 #1
8
样例 #2
样例输入 #2
ABCBC
样例输出 #2
3
样例 #3
样例输入 #3
????C?????B??????A???????
样例输出 #3
979596887
说明
数据规模与约定
- 的每个字符都是
A
、B
、C
或?
。
样例 解释
在这种情况下, ,我们可以通过用 A
、B
或 C
替换每次出现的 ?
来组成 字符串。每个字符串的 ABC 号码如下:
- AAAC`:
AABC
:AACC
:ABAC
:ABBC
:ABCC
:ACAC
:ACBC
:ACCC
:
其和为 ,因此我们打印 mod ,即 。
样例 解释
当 时,我们打印 本身的 ABC 数,模数为 。该字符串与问题陈述中给出的示例字符串相同,其 ABC 编号为 。
样例 解释
在这种情况下,所有 字符串的 ABC 数字之和是 ,我们应该打印这个数字的模数 ,即 。