#P1393. Mivik 的标题

    ID: 5912 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串数学KMP快速数论变换 NTT

Mivik 的标题

Description

Since Mivik wrote the book by randomly hitting keys on the keyboard, he plans to do the same for the book title. Mivik's keyboard has mm different keys, corresponding to mm different characters. Mivik decides to hit keys on this keyboard uniformly at random nn times to produce the title. However, for some reason, Mivik wants the title to contain a person's name SS. Therefore, Mivik asks you: what is the probability that the randomly typed title contains this name.

Also, Mivik does not like weird-looking decimals, so you only need to output this probability modulo 998244353998244353.

Input Format

The first line contains three integers nn, mm, S|S|, where S|S| is the length of this name.

The second line gives S|S| integers aia_i, representing this name.

Output Format

Output one integer in one line, representing the probability modulo 998244353998244353.

3 2 2
1 1
623902721
6 3 4
1 2 3 2
480636170

Hint

Sample Explanation

In sample 1, for convenience, we define the two keys on the keyboard as a and b. Then all strings of length 3 are aaa, aab, aba, abb, baa, bab, bba, bbb, a total of 8 strings. Among them, the ones that contain the given name aa are aaa, aab, baa, which is 3 strings, so the probability is 38\frac{3}{8}. Taking it modulo gives 623902721.

Constraints

For all testdata, 1S1051\le |S|\le 10^5, SnS+105|S|\le n\le |S|+10^5, 1m1081\le m\le 10^8.

Subtask 1 (5 pts): m=1m=1.

Subtask 2 (20 pts): 1n,m2501\le n, m\le 250.

Subtask 3 (30 pts): 1n,m50001\le n, m\le 5000.

Subtask 3 (45 pts): no special constraints.

Translated by ChatGPT 5