- Time limit: 1.00 s
- Memory limit: 512 MB
Given a string with characters and a dictionary with words , compute how many ways there is to produce the given string by concatenating words in the dictionary.
Input
The first line has the exactly characters, the string .
The next line contains a single integer, , the number of words in the dictionary.
The rest lines each contain one word in the dictionary.
Output
Output the number of ways modulo
Limits
- The combined length of all words in the dictionary is at most .
- Each word consists of only English lower case letters a-z.
Example
Input:
ababc 4 ab abab c cb
Output:
2
Explanation: The ways are ab+ab+c
and abab+c
.