Statistics of strings
Practice
3 (6 votes)
Algorithms
Hard
String manipulation
Problem
88% Success 1647 Attempts 50 Points 3s Time Limit 512MB Memory 1024 KB Max Code

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 \(\sum_{s \in S} f(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 \(z_0=0\).

Input format

First line of input contains three space separated integers n, a and \(mod\) (\(1 \leq n \leq 22\), \(1 \leq a \leq 10^9\), \(1 \leq mod \leq 10^9\)).

Note that \(mod\) may be composite.

Output format

Print the single integer \(\sum_{s \in S} f(s)\) modulo \(mod\).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
164 votes
Tags:
ApprovedBinary SearchMediumOpenSorting
Points:30
5 votes
Tags:
AlgorithmsDynamic ProgrammingEasyOpenTwo dimensional
Editorial

Login to unlock the editorial