#abc307e. [abc307_e]Distinct Adjacent
[abc307_e]Distinct Adjacent
Problem Statement
There are people numbered from to standing in a circle. Person is to the right of person , person is to the right of person , ..., and person is to the right of person .
We will give each of the people an integer between and , inclusive.
Among the ways to distribute integers, find the number, modulo , of such ways that no two adjacent people have the same integer.
Constraints
- and are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 3
Sample Output 1
6
There are six desired ways, where the integers given to persons are .
Sample Input 2
4 2
Sample Output 2
2
There are two desired ways, where the integers given to persons are .
Sample Input 3
987654 456789
Sample Output 3
778634319
Be sure to find the number modulo .