#P2022C. Protect the Second Best KK in the World
Protect the Second Best KK in the World
Protect the second best kk in the world
Time limit: 1 seconds
Memory limit: 512 megabytes
Problem Statement
As an individual trainee who has been practicing algorithm for 2.5 years(Almost 3 years actually), Ckk has become the second best Kunkun in the world. Unlike the best Kunkun in the world, the second best Kunkun doesn't like hang(Sing), iao(Dance), ap, anqiu(Basketball), but he can really (copy) and (paste) someone people's code.
One day, Ckk gets basic strings and a target string and he needs to build the target string with these basic strings using copy and paste which is easy for him. However, he wants to know how many copy and paste ways to build the target string. This is difficult for a 2.5 years algorithm trainee, so he asks you, a clever ikun for help.
More precisely, you have to calculate how many ways to build the target string out of the basic strings by concatenating them. You can use the basic strings any number of times and in any order.
Specially, two ways to build the target string are considered different, if and only if there is a position that you choose different basic strings. It is promised there aren't same strings among the basic strings.
Since the answer may be very large, you only need to output the result modulo .
Input
The first line contains one integers denoting the number of basic string.
The second line contains one integers denoting the length of target string and the string .
The next lines contain the length of each basic string and the string .
It's guaranteed that the total length of all strings in all test cases does not exceed .
Output
Print a single integer, denoting the answer to the question, modulo .
3
6 abbabb
1 a
1 b
2 ab
4
1
5 aaaab
1 a
0
6
30 abbabbabbbabaababbaaaababbbaba
1 a
1 b
2 ab
2 ba
3 aab
3 aba
72576
Notes
In the first Sample, we have 4 ways to build the string:
1.abbabb = a + b + b + a + b + b 2.abbabb = ab + b + a + b + b 3.abbabb = a + b + b + ab + b 4.abbabb = ab + b + ab + b