atcoder#ARC149E. [ARC149E] Sliding Window Sort
[ARC149E] Sliding Window Sort
Score : points
Problem Statement
You are given positive integers , , and . Consider the following operation on a sequence of positive integers .
- Do the following for in this order.- Sort $A_{k\bmod N}, A_{(k+1)\bmod N}, \ldots, A_{(k+M-1)\bmod N}$ in ascending order. That is, replace with for each , where is the result of sorting $A_{k\bmod N}, A_{(k+1)\bmod N}, \ldots, A_{(k+M-1)\bmod N}$ in ascending order.
- Sort $A_{k\bmod N}, A_{(k+1)\bmod N}, \ldots, A_{(k+M-1)\bmod N}$ in ascending order. That is, replace with for each , where is the result of sorting $A_{k\bmod N}, A_{(k+1)\bmod N}, \ldots, A_{(k+M-1)\bmod N}$ in ascending order.
You are given a permutation of the integers from through . Find the number of sequences of positive integers that will equal after performing the operation above, modulo .
Constraints
- if .
Input
The input is given from Standard Input in the following format:
Print the number of sequences of positive integers that will equal after performing the operation, modulo .
6 3 5
6 4 2 3 1 5
18
For instance, satisfies the condition. On this , the operation will proceed as follows.
- The action for changes to .
- The action for changes to .
- The action for changes to .
- The action for changes to .
- The action for changes to , which equals .
6 3 5
6 5 4 3 2 1
0
No sequence satisfies the condition.
20 20 149
13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12
401576539
All permutations of the integers from through satisfy the condition.