#Lutece1850. MaxKU’s Z Algorithm
MaxKU’s Z Algorithm
Migrated from Lutece 1850 MaxKU’s Z Algorithm
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
If you have ever learned , you may know that for a string , can gain an integer array , which indicates the LCP(longest-common-prefix) between and .
Besides, we explicitly define as exception.
Now consider all the strings as set with the length and the charset size , calculate $\sum_{S \in \Re} \max(Z_0,Z_1,...,Z_{n-1})^2 \mod 10^9 + 7$
Input
Only one line contains two integers and .
Output
Print the corresponding answer in a single line.
Samples
1 772002
0
2 772002
772002
3 772002
975711675
Resources
The 16th UESTC Programming Contest Preliminary