100 atcoder#ABC104D. [ABC104D] We Love ABC
[ABC104D] We Love ABC
Score : points
Problem Statement
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 modulo .
Constraints
- Each character of is
A
,B
,C
or?
.
Input
Input is given from Standard Input in the following format:
Output
Print the sum of the ABC numbers of all the strings, modulo .
A??C
8
In this case, , and we can make strings by by replacing each occurrence of ?
with A
, B
or C
. The ABC number of each of these strings is as follows:
AAAC
:AABC
:AACC
:ABAC
:ABBC
:ABCC
:ACAC
:ACBC
:ACCC
:
The sum of these is , so we print modulo , that is, .
ABCBC
3
When , we print the ABC number of itself, modulo . This string is the same as the one given as an example in the problem statement, and its ABC number is .
????C?????B??????A???????
979596887
In this case, the sum of the ABC numbers of all the strings is , and we should print this number modulo , that is, .