atcoder#AGC009E. Eternal Average

Eternal Average

Score : 16001600 points

Problem Statement

There are NN zeros and MM ones written on a blackboard. Starting from this state, we will repeat the following operation: select KK 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 KK numbers. Here, assume that N+M1N + M - 1 is divisible by K1K - 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 109+710^9 + 7.

Constraints

  • 1N,M20001 \leq N, M \leq 2000
  • 2K20002 \leq K \leq 2000
  • N+M1N + M - 1 is divisible by K1K - 1.

Input

The input is given from Standard Input in the following format:

NN MM KK

Output

Print the number of the different possible values taken by the rational number that will be eventually left on the blackboard, modulo 109+710^9 + 7.

2 2 2
5

There are five possible values for the number that will be eventually left on the blackboard: 14\frac{1}{4}, 38\frac{3}{8}, 12\frac{1}{2}, 58\frac{5}{8} and 34\frac{3}{4}.

For example, 38\frac{3}{8} can be eventually left if we:

  • Erase 00 and 11, then write 12\frac{1}{2}.
  • Erase 12\frac{1}{2} and 11, then write 34\frac{3}{4}.
  • Erase 00 and 34\frac{3}{4}, then write 38\frac{3}{8}.
3 4 3
9
150 150 14
937426930