#R020E. [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
0and1can be encoded as0and1, 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
0and1; - 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
0and1.
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 :
011can be encoded as011and0(1x2);010can be encoded as010;001can be encoded as001and(0x2)1;000can be encoded as000,0(0x2),(0x2)0and(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 .