#P7525. Shelter
Shelter
Description
During her time in space, besides creating freely in the virtual world, Rin also plays an interesting little game every day.
When she first arrived in space, her father left her a non-empty string consisting of lowercase English letters, with length . Every day, Rin finds the largest integer () such that the prefix of length and the suffix of length of the string are the same (note that may be ), and then appends this prefix/suffix to the end of the whole string to form a new string. For example, when the string is mivikismivik, the largest (both the prefix and suffix of length are mivik), so Rin appends mivik to the end of the string, forming the new string mivikismivikmivik.
After spending days in space, this string has become very long. Rin is suddenly curious about what the length of the string is now. Can you help her? Since the answer may be very large, you only need to output the result modulo .
Input Format
The first line contains two positive integers , representing the length of the initial string and the number of days Rin has spent in space.
The second line contains a string of length consisting of lowercase English letters, representing the string left to Rin by her father.
Output Format
Output one integer in one line, representing the length of the string after days modulo .
7 1
abcdabc
10
5 2
ioioi
11
8 50
idolidol
263923940
Hint
Sample Explanation
Sample 1: After one operation, the string becomes abcdabcabc, with length .
Sample 2: After one operation, the string becomes ioioiioi, and after another operation it becomes ioioiioiioi, with length .
Constraints
For all testdata, , .
Subtask 1 (15 pts): consists of only one kind of letter.
Subtask 2 (20 pts): has a proper period whose length is not (i.e. a period whose length is a divisor of ).
Subtask 3 (65 pts): No special constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号