Let
be a prime number. You are given three integers .
First, define negative exponents as follows. When , is the unique integer satisfying
For an integer , define as follows.
If an integer satisfies
then is called a possible value of .
Given , output the sum of all possible integers .
Here, is considered as an integer satisfying
Input
The input is given in the following format.
Output
Output the sum of all integers satisfying
Constraints
- .
- .
- .
Subtasks
Samples
Sample 1
Input
2 3 1
Output
8
Since , we have . Therefore, the answer is .
Sample 2
Input
2 1 -1
Output
499122177
The value satisfying is the modular inverse of , which is .
Sample 3
Input
2 1 3
Output
275347185
We have .