#P6693. 谷歌翻(sheng)译(cao)机
谷歌翻(sheng)译(cao)机
Background
Little L has recently been obsessed with using Google’s “shengcao” generator to create all kinds of weird stuff.
After producing many different works, Little L began to think about the following problem.
Problem Description
Note: For convenience, in the following, all strings are 1-indexed, i.e., positions start from .
Little L treats the original text before each “shengcao” and the resulting text after “shengcao” as two strings and , both consisting only of lowercase letters.
We define a “partition sequence” and “partition substrings” as follows:
-
For a string of length , a “partition sequence” is defined as: there exists a sequence of length such that . For a partition sequence, its “partition substrings” are the substrings formed by the characters from position to (, possibly the empty string). Clearly, for a partition sequence of length , there are partition substrings in total.
-
For the same string, two partition sequences ( and ) are different if and only if their lengths are different (), or there exists an such that .
Different people may understand the same original text and result in different ways. We define one way of understanding as follows:
- For strings and , we choose one partition sequence for each of them ( and ). These two partition sequences must satisfy:
- The two partition sequences have the same length ().
- For any , we have , i.e., the character at position in is the same as the character at position in .
-
Define the “shengcao level” of this way of understanding as the sum of squares of the lengths of all partition substrings of the two strings, i.e., $\sum\limits_{i=0}^{k_1}(p_{i+1}-p_i-1)^2+\sum\limits_{i=0}^{k_2}(q_{i+1}-q_i-1)^2$.
-
Two ways of understanding are different if and only if their are different, or their are different.
Little L wants to know the sum of the shengcao levels over all ways of understanding. Since he does not like the number , he does not want you to tell him the result as that number, so you need to take the result modulo .
Input Format
The first line contains two positive integers , which are the lengths of and .
The next line contains a string of length , representing string .
The next line contains a string of length , representing string .
Output Format
One line containing one integer, the answer modulo .
3 4
abc
bacb
74
7 9
adcbbde
bdaegbcba
2128
Hint
For sample 1, there are the following ways of understanding:
- , the shengcao level is .
- , the shengcao level is .
- , the shengcao level is .
- , the shengcao level is .
- , the shengcao level is .
- , the shengcao level is .
- , the shengcao level is .
- , the shengcao level is .
The total shengcao level is .
Constraints
This problem uses bundled testdata.
- Subtask 1( ): .
- Subtask 2( ): .
- Subtask 3( ): no special constraints.
For of the data, , and and contain only lowercase letters.
Translated by ChatGPT 5