atcoder#AGC020E. [AGC020E] Encoding Subsets
[AGC020E] Encoding Subsets
Score : points
Problem Statement
Consider the following set of rules for encoding strings consisting of 0
and 1
:
- Strings
0
and1
can be encoded as0
and1
, respectively. - If strings and can be encoded as and , respectively, then string can be encoded as .
- If string can be encoded as and is a positive integer, then string ( repeated times) can be encoded as
(
x
)
.
For example, string 001001001
, among other possibilities, can be encoded as 001001001
, 00(1(0x2)x2)1
and (001x3)
.
Let's call string a subset of string if:
- and are equal in length and consist of
0
and1
; - for all indices such that =
1
, it's also true that =1
.
You are given string consisting of 0
and 1
. Find the total number of distinct encodings of all subsets of , modulo .
Constraints
- consists of
0
and1
.
Input
Input is given from Standard Input in the following format:
Output
Print the total number of distinct encodings of all subsets of modulo .
011
9
There are four subsets of :
011
can be encoded as011
and0(1x2)
;010
can be encoded as010
;001
can be encoded as001
and(0x2)1
;000
can be encoded as000
,0(0x2)
,(0x2)0
and(0x3)
.
Thus, the total number of encodings of all subsets of is .
0000
10
This time has only one subset, but it can be encoded in different ways.
101110
156
001110111010110001100000100111
363383189
Don't forget to take the result modulo .