Consider a permutation of . For each contiguous segment of length , call its smallest element the winner.
You are given and . Count the permutations for which the winners of all segments are pairwise different.
Output the answer modulo .
There are valid permutations. For example, has winners , , and .
There are valid permutations.
Every segment contains one element, so all permutations are valid.
The only permutation is .
There is only one segment, so all permutations are valid.
There are valid permutations.