#P11030. 『DABOI Round 1』Blessings Repeated

    ID: 12162 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DPO2优化矩阵加速组合数学

『DABOI Round 1』Blessings Repeated

Background

https://www.luogu.com.cn/user/1051692
is respectfully called “Shengmu” (shèng mǔ) because of their strong abilities.

Shengmu is so dazzling. Thanks to Shengmu!

Problem Description

Shengmu is a debater, i.e. an ENTP.

In one debate, her viewpoint is the string SS. To convince the other side, she will emphasize it kk times, so her speech is the concatenation of kk copies of the string SS in order.

As the rebutter, you may not be able to hear everything clearly, so you can only catch the keyword TT. You need to find, in the string formed by concatenating kk copies of SS, how many subsequences (not necessarily contiguous) are equal to TT. Output the answer modulo 998244353998244353.


[Formal statement]

Given a positive integer kk and two strings S,TS, T.

Let the string ss be the string obtained by concatenating kk copies of SS. Let n=sn=\vert s \vert and m=Tm=\vert T \vert.

Let the answer set be $P=\{ (i_0,i_1,\dots,i_{m-1}) \mid 0\le i_0 < i_1 < \dots < i_{m-1} < n, \forall~0 \le j < m, s_{i_j}=T_j \}$. Compute Pmod998244353\vert P \vert \bmod 998244353.

Input Format

There are 33 lines of input.

Line 11 contains one integer kk.

Line 22 contains one string SS.

Line 33 contains one string TT.

Output Format

Output one line containing one integer, the answer.

2
stocyhorz
cyh
4
4
c
ccc
4

Hint

[Explanation for Sample 1]

Repeat SS 22 times to get stocyhorzstocyhorz\texttt{stocyhorzstocyhorz}.

The answer set is P={(3,4,5),(3,4,14),(3,13,14),(12,13,14)}P=\{(3,4,5),(3,4,14),(3,13,14),(12,13,14) \}, so P=4\vert P\vert=4.


[Constraints]

For all testdata, 0<k10180<k\le10^{18}, 0<S5×1030 < \vert S \vert \le 5 \times 10^3, 0<T100 < \vert T \vert \le 10. Both strings SS and TT consist of lowercase English letters.

Point\text{Point} kk\le S\vert S\vert\le T\vert T\vert\le
121\sim2 101810^{18} 5×1035 \times 10^3 11
33 11 22
454\sim5 100100 5×1035 \times 10 ^3
676\sim7 11 5050 44
8108\sim10 1010 5×1035 \times 10^3 1010
112011\sim20 101810^{18}

Translated by ChatGPT 5