atcoder#ABC305G. [ABC305G] Banned Substrings
[ABC305G] Banned Substrings
Score : points
Problem Statement
You are given a set of non-empty strings of length at most consisting of a
and b
.
Find the number of strings of length consisting of a
and b
that satisfy the following condition:
- does not contain as a consecutive substring for any .
Since the answer can be enormous, find it modulo .
Constraints
- and are integers.
- is a non-empty string of length at most consisting of
a
andb
.
Input
The input is given from Standard Input in the following format:
Output
Print the answer modulo in a single line.
4 3
aab
bbab
abab
10
There are strings of length consisting of a
and b
that do not contain aab
, bbab
, or abab
as consecutive substrings: aaaa
, abaa
, abba
, abbb
, baaa
, baba
, babb
, bbaa
, bbba
, and bbbb
. Thus, you should print .
20 1
aa
17711
1000000007 28
bbabba
bbbbaa
aabbab
bbbaba
baaabb
babaab
bbaaba
aabaaa
aaaaaa
aabbaa
bbaaaa
bbaabb
bbabab
aababa
baaaba
ababab
abbaba
aabaab
ababaa
abbbba
baabaa
aabbbb
abbbab
baaaab
baabbb
ababbb
baabba
abaaaa
566756841
Print the answer modulo .