atcoder#AGC050C. [AGC050C] Block Game
[AGC050C] Block Game
Score : points
Problem Statement
There is a sequence of cells that extends infinitely to both directions. You and Snuke play the following game:
- The judge chooses a string consisting of
B
andS
, called turn string, and show it to both players. - First, Snuke stands on one of the cells.
- Then, for each in this order, the following happens:- If the -th letter of is
B
, it is your turn. You choose a cell that contains neither other blocks nor Snuke, and put a block on the cell. After that, if both of the two cells adjacent to Snuke's cell are blocked, you win and the game ends.- If the -th letter of is
S
, it is Snuke's turn. He may move to an adjacent unblocked cell, or doesn't do anything.
- If the -th letter of is
- If the -th letter of is
B
, it is your turn. You choose a cell that contains neither other blocks nor Snuke, and put a block on the cell. After that, if both of the two cells adjacent to Snuke's cell are blocked, you win and the game ends. - If the -th letter of is
S
, it is Snuke's turn. He may move to an adjacent unblocked cell, or doesn't do anything. - If the game still hasn't ended, Snuke wins and the game ends.
You are given a string consisting of B
, S
, and ?
.
If contains ?
s, there are ways to replace each ?
with B
or S
and get a turn string.
Among those strings, how many will end up with your winning, in case both players play optimally?
Find the answer modulo .
Constraints
- consists of
B
,S
, and?
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
BSSBS
0
You take the st and the th turn, and Snuke takes the nd, the rd, and the th turn. In this case, if both players play optimally, it turns out that Snuke wins.
?S?B????S????????B??????B??S??
16777197