Beautiful Sequence Unraveling
Time limit7sMemory limit512 MB
Count arrays of length n with values from 1 to k where no split point has prefix maximum equal to suffix minimum, modulo the prime p.
- Level
Hard8 of 10
- Topics
- Math, Combinatorics, Dynamic programming
- Solved
- No attempts yet
Problem
You are the happy owner of a powerful tool called Beautiful Sequence Unraveler (BSU). BSU handles beautiful sequences well.
A beautiful sequence is an array of integers such that there is no integer with and .
You want to know how often such sequences occur. Count the beautiful sequences among all arrays of length whose integers are between and , inclusive. The count may be large, so print it modulo the prime .
Input
The only line contains three integers , , (, , ).
It is guaranteed that is prime.
Output
Print the answer modulo .