Statistics of strings

3

6 votes
Algorithms, Hard, String Manipulation
Problem

Data science is very popular now. A lot of universities have courses about it. A lot of companies have open data science positions. So it's quite important to know how to work with statistics. And this task can help you to make first step into statistics.

Lets define S as all strings of the length n consisting of letters from the some alphabet of the size a. For each string s lets define f(s) - maximum among all z-function values of the string s. Your task is calculate sSf(s) modulo mod

You can read more about z-function on https://e-maxx-eng.appspot.com/string/z-function.html. Also in this problem we define z0=0.

Input format

First line of input contains three space separated integers n, a and mod (1n22, 1a109, 1mod109).

Note that mod may be composite.

Output format

Print the single integer sSf(s) modulo mod.

Time Limit: 3
Memory Limit: 512
Source Limit:
Explanation
  1. f(aaa)=2
  2. f(aab)=1
  3. f(aba)=1
  4. f(abb)=0
  5. f(baa)=0
  6. f(bab)=1
  7. f(bba)=1
  8. f(bbb)=2
Editor Image

?