luogu#P10272. 在四方城外
在四方城外
Background
Willow flowers, green hills, and moonlight.
The scent of wine in poems, and the scent of wine outside poems.
The sky inside the city, and the sky outside the city.
Word by word, stroke by stroke, what is understood, what is still hazy.
Look and look, learn and learn. The world is like murky wine; you only know its taste after you drink it.
Problem Description
Define the extension operation on a string as:
-
Find the longest of .
-
Set .
Note: in this problem, means a proper (that is, the string itself is not counted as a ).
Let the weight of an extension operation be the length of the string after extension, i.e. . Please compute the sum of weights from the -th extension of string to the -th extension.
Since the result may be very large, output the answer modulo .
Input Format
The first line contains a string .
The second line contains two integers .
Output Format
Output one number, i.e. the answer modulo .
ababcab
1 3
39
aa
3 5
59
Hint
Explanation for Sample 1
The -st extension: ababcab[ab], with weight .
The -nd extension: ababcabab[abab], with weight .
The -rd extension: ababcabababab[abab], with weight .
The sum of weights is .
Constraints
For of the testdata, and .
For of the testdata, .
For the other of the testdata, .
For of the testdata, and . The input consists only of integers and lowercase letters.
Translated by ChatGPT 5