Score : $1600$ points
There are $N$ zeros and $M$ ones written on a blackboard. Starting from this state, we will repeat the following operation: select $K$ of the rational numbers written on the blackboard and erase them, then write a new number on the blackboard that is equal to the arithmetic mean of those $K$ numbers. Here, assume that $N + M - 1$ is divisible by $K - 1$.
Then, if we repeat this operation until it is no longer applicable, there will be eventually one rational number left on the blackboard.
Find the number of the different possible values taken by this rational number, modulo $10^9 + 7$.
The input is given from Standard Input in the following format:
$N$ $M$ $K$
Print the number of the different possible values taken by the rational number that will be eventually left on the blackboard, modulo $10^9 + 7$.
2 2 2
5
There are five possible values for the number that will be eventually left on the blackboard: $\frac{1}{4}$, $\frac{3}{8}$, $\frac{1}{2}$, $\frac{5}{8}$ and $\frac{3}{4}$.
For example, $\frac{3}{8}$ can be eventually left if we:
3 4 3
9
150 150 14
937426930