Border
Time limit2sMemory limit512 MB
Given a string generated from a seed, compute the sum over all pairs i<j of the longest k where the prefix starting at i of length k equals the suffix ending at j of length k.
- Level
Hard8 of 10
- Topics
- String, String matching, Array
- Solved
- No attempts yet
Problem
You are given a string . We write its substrings as , and when , the substring is the empty string. Define as follows.
Output .
The string is generated as follows. The values and are the parameters of the generator.
long long seed;
for (int i = 1; i <= n; i++) {
seed = (seed * 13331 + 23333) % 1000000007;
s[i] = 'a' + (seed & 1);
}
Input
The first line contains two integers and (, ).
Output
Output the answer.