Under construction

Still being built. Things may change

Separate String

Time limit2sMemory limit512 MB

Summary
Count the ways to split string t into a sequence of pieces, each of which is one of N given dictionary strings, modulo 1e9+7.
Level

Medium7 of 10

Topics
Dynamic programming, Trie, String matching, String
Solved
No attempts yet

Problem

You are given a string tt and a set SS of NN distinct strings. You must split tt into pieces so that every piece is an element of SS.

For example, when tt = abab and SS = {a, ab, b}, the following 4 splittings satisfy the condition.

  • a, b, a, b
  • a, b, ab
  • ab, a, b
  • ab, ab

Count the number of ways to split tt. The answer can be very large, so print the remainder after dividing it by 1,000,000,007.

Input

The input consists of a single test case in the following format.

N
s1
.
.
.
sN
t

The first line contains an integer NN (1≤N≤100,0001 \le N \le 100{,}000), the number of elements of SS. The next NN lines contain NN distinct strings, one per line. The ii-th string sis_i is the ii-th element of SS. Each sis_i consists of lowercase letters and has length between 1 and 100,000, inclusive. The sum of the lengths of all sis_i (1≤i≤N1 \le i \le N) is at most 200,000. The last line contains the string tt to be split. tt consists of lowercase letters and has length between 1 and 100,000, inclusive.

Output

Print the number of ways to split tt, modulo 1,000,000,007.

Examples4

  1. Example 1

    Input
    3
    a
    b
    ab
    abab
    
    Expected output
    4
    
  2. Example 2

    Input
    3
    a
    b
    c
    xyz
    
    Expected output
    0
    
  3. Example 3

    Input
    7
    abc
    ab
    bc
    a
    b
    c
    aa
    aaabcbccababbc
    
    Expected output
    160
    
  4. Example 4

    Input
    10
    a
    aa
    aaa
    aaaa
    aaaaa
    aaaaaa
    aaaaaaa
    aaaaaaaa
    aaaaaaaaa
    aaaaaaaaaa
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    
    Expected output
    461695029