String concatenation - MarisaOJ: Marisa Online Judge

String concatenation

Time limit: 3000 ms
Memory limit: 256 MB
Given $n$ distinct strings $S_1,S_2,...,S_n$ and a target string $T$. Count the number of ways to concatenate the strings to form $T$, where each string can be used multiple times. ### Input - The first line contains an integer $n$. - The next $n$ lines each contain a string $S_i$. - The next line contains the string $T$. ### Output - Print an integer, the number of ways to concatenate modulo $10^9+7$. ### Constraints - $1 \leq n \leq 10^5$. - $1 \leq |S_i|, |T| \leq 10^5$. - $1 \leq \sum |S_i| \leq 5 \times 10^5$. ### Example Input: ### Example Input: ``` 3 a b ab abab ``` Output: ``` 4 ``` There are 4 possible concatenations: - `a` + `b` + `a` + `b` - `a` + `b` + `ab` - `ab` + `a` + `b` - `ab` + `ab`