#P9229. Simple Nine Rings Puzzle

    ID: 22384 Type: Default 1000ms 256MiB

Simple Nine Rings Puzzle

Simple Nine Rings Puzzle

Given a binary string ss (the rule string) and a state string tt of length s+1|s|+1, we consider the following puzzle. In the state string tt, each character represents a ring: ti=1t_i = \texttt{1} means the ii-th ring is assembled while ti=0t_i = \texttt{0} means it is taken apart. Initially, all rings are taken apart (i.e. t=0s+1t=\texttt{0}^{|s|+1}) and the goal is to get all rings assembled (i.e. t=1s+1t=\texttt{1}^{|s|+1}).

In each move, you may toggle (i.e. change a 00 to 11 or a 11 to 00) exactly one character tit_i of tt, but only if the prefix of tt before that position, namely t1t2ti1t_1t_2\cdots t_{i-1}, is a suffix of the rule string ss. (Note that the empty string is considered a suffix of any string, so the first ring can always be toggled.)

For example, if s=01s=\texttt{01} then its suffixes are ({"", \texttt{1}, \texttt{01}}). In a state such as t=010t=\texttt{010} of length 3, the move at position 3 is allowed only if the prefix t1t2=01t_1t_2=\texttt{01} is a suffix of ss.

Your task is to compute the minimum number of moves required to change tt from all zeros to all ones, and output the answer modulo 109+710^9+7.

inputFormat

A single line containing the binary string ss. It is guaranteed that ss 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 109+710^9+7.

sample

1
2