#P1861E. Non-Intersecting Subpermutations
Non-Intersecting Subpermutations
Description
You are given two integers and .
For an array of length , let's define its cost as the maximum number of contiguous subarrays of this array that can be chosen so that:
- each element belongs to at most one subarray;
- the length of each subarray is exactly ;
- each subarray contains each integer from to exactly once.
For example, if , and the array is , its cost is because, for example, we can choose the subarrays from the -nd element to the -th element and from the -th element to the -th element, and we can show that it's impossible to choose more than subarrays.
Calculate the sum of costs over all arrays of length consisting of integers from to , and print it modulo .
The only line of the input contains two integers and ().
Print one integer — the sum of costs of all arrays of length consisting of integers from to taken modulo .
Input
The only line of the input contains two integers and ().
Output
Print one integer — the sum of costs of all arrays of length consisting of integers from to taken modulo .
Related
In following contests: