| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 5 | 4 | 4 | 100.000% |
You are given $K$ strings $S_1, S_2, \dots, S_K$ of lowercase Latin letters. You are also given a string $T$.
Define a function $f(n)$, where $n$ is an integer, as the following.
It can be proven that $\lim\limits_{n \to \infty} f(n)$ exists and can be written as a rational number $p / q$. Find $pq^{-1} \bmod 998244353$.
The first line contains the string $T$ ($1 \leq |T| \leq 5000$) consisting of lowercase Latin letters. The second line contains an integer $K$ ($1 \leq K \leq 5000)$. Each of the next $K$ lines contains $S_i$ ($1 \leq |S_i| \leq 5000$) consisting of lowercase Latin letters. The sum of $|S_i|$ does not exceed $1000000$.
Output the limit $pq^{-1} \bmod 998244353$.
ab 2 a b
748683265
Explanation of Sample 1: It can be shown that $\lim\limits_{n \to \infty} f(n) = \frac{1}{4}$.
ab 4 aaa abab baba bbb
1
Explanation of Sample 2: It can be shown that $\lim\limits_{n \to \infty} f(n) = 1$.