#jag2017autumnh. [jag2017autumn_h]Separate String
[jag2017autumn_h]Separate String
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 16px; line-height: 18px; background-color: #f5f5f5; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
You are given a string and a set of different strings. You need to separate such that each part is included in .
For example, the following 4 separation methods satisfy the condition when and .
Your task is to count the number of ways to separate . Because the result can be large, you should output the remainder divided by .
Input
The input consists of a single test case formatted as follows.
The first line consists of an integer which is the number of the elements of . The following lines consist of distinct strings separated by line breaks. The -th string represents the -th element of . consists of lowercase letters and the length is between and , inclusive. The summation of length of is at most . The next line consists of a string which consists of lowercase letters and represents the string to be separated and the length is between and , inclusive.
Output
Calculate the number of ways to separate and print the remainder divided by .
Sample Input 1
3
a
b
ab
abab
Output for Sample Input 1
4
Sample Input 2
3
a
b
c
xyz
Output for Sample Input 2
0
Sample Input 3
7
abc
ab
bc
a
b
c
aa
aaabcbccababbc
Output for Sample Input 3
160
Sample Input 4
10
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaaaaaa
aaaaaaaa
aaaaaaaaa
aaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Output for Sample Input 4
461695029