cswork / OAOpen practice workspace

SnowflakeOA #16

String Formation (Also for AI/ML Software Engineer Intern :)

Estimated HardJudge-ready

Topics (AI-labelled)String DP

Take characters from a set of equal-length words to form target, where the chosen column indices are strictly increasing and the same word may be chosen more than once. Ways are distinguished by the chosen columns and the chosen words; different entries of a duplicated word still count as different choices. Output the answer modulo 10⁹+7.

Input

The first line contains the number of words n, followed by n lines of words, and the last line contains target. 1≤n≤1000, each word has length 1..3000 and the total length is ≤100000; 1≤target length≤word length; characters are a..z.

Output

Output the single integer required by the problem.

Example 1

Input:

3
valya
lyglb
vldoh
val

Output:

4

Example 2

Input:

3
adc
aec
efg
ac

Output:

4

Example 3

Input:

2
aa
aa
aa

Output:

4

Example notes

The answers to the three public examples are, in order: 4; 4; 4. All examples have been verified by independent small-scale enumeration or state search.

Editorial

Loading solution…