#P9229. Simple Nine Rings Puzzle
Simple Nine Rings Puzzle
Simple Nine Rings Puzzle
Given a binary string (the rule string) and a state string of length , we consider the following puzzle. In the state string , each character represents a ring: means the -th ring is assembled while means it is taken apart. Initially, all rings are taken apart (i.e. ) and the goal is to get all rings assembled (i.e. ).
In each move, you may toggle (i.e. change a to or a to ) exactly one character of , but only if the prefix of before that position, namely , is a suffix of the rule string . (Note that the empty string is considered a suffix of any string, so the first ring can always be toggled.)
For example, if then its suffixes are ({"", \texttt{1}, \texttt{01}}). In a state such as of length 3, the move at position 3 is allowed only if the prefix is a suffix of .
Your task is to compute the minimum number of moves required to change from all zeros to all ones, and output the answer modulo .
inputFormat
A single line containing the binary string . It is guaranteed that consists only of characters 0
and 1
.
outputFormat
Output a single integer --- the minimum number of moves required to change the state from all zeros to all ones modulo .
sample
1
2