#P11030. 『DABOI Round 1』Blessings Repeated
『DABOI Round 1』Blessings Repeated
Background
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 . To convince the other side, she will emphasize it times, so her speech is the concatenation of copies of the string in order.
As the rebutter, you may not be able to hear everything clearly, so you can only catch the keyword . You need to find, in the string formed by concatenating copies of , how many subsequences (not necessarily contiguous) are equal to . Output the answer modulo .
[Formal statement]
Given a positive integer and two strings .
Let the string be the string obtained by concatenating copies of . Let and .
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 .
Input Format
There are lines of input.
Line contains one integer .
Line contains one string .
Line contains one string .
Output Format
Output one line containing one integer, the answer.
2
stocyhorz
cyh
4
4
c
ccc
4
Hint
[Explanation for Sample 1]
Repeat times to get .
The answer set is , so .
[Constraints]
For all testdata, , , . Both strings and consist of lowercase English letters.
Translated by ChatGPT 5