#P1464. Cyclic Substrings
Cyclic Substrings
Cyclic Substrings
题目描述
Mr. Ham is interested in strings, especially palindromic strings. Today, he finds a string of length .
For the string of length , he defines its cyclic substring from the -th character to the -th character () as follows:
- If , the cyclic substring is the substring of from the -th character to the -th character. He denotes it as .
- If , the cyclic substring is , where denotes the concatenation of two strings. He also denotes it as .
For example, if , then , , and .
A string is palindromic if for all from to . For example, is palindromic, while is not.
Given the string , there will be many cyclic substrings of which are palindromic. Denote as the set of all distinct cyclic substrings of which are palindromic, as the number of times appears in as a cyclic substring, and as the length of . Mr. Ham wants you to compute
The answer may be very large, so you only need to output the answer modulo .
输入格式
The first line contains a number (), the length of the string .
The second line contains a string of length . Each character of is a digit.
输出格式
Output a single integer, denoting the sum modulo .
样例 #1
样例输入 #1
5
01010
样例输出 #1
39
提示
Note
In the sample, the palindromic cyclic substrings of are:
- .
- .
- .
- .
- .
- .
- .
The answer is $3^2 \times 1 + 2^2 \times 1 + 1^2 \times 2 + 2^2 \times 3 + 1^2 \times 3 + 1^2 \times 4 + 1^2 \times 5 = 39$.