Cookie Counter

Count sequences of D days, each amount in [0, X), summing to N, modulo 1e9+7.

Medium7CombinatoricsDynamic programmingMathNo attempts yetTime limit8sMemory limit512 MB

Problem

Grandma left NN cookies behind. My elder sister and I wanted to eat them right away, but a note was attached to the box.

  • The cookies go bad, so all of them have to be eaten within DD days.
  • Overeating is bad for you, so the number eaten on a single day has to be strictly less than XX.

My sister asked, "How many ways are there to eat all of the cookies? Let's count them!"

One way is the list of how many cookies are eaten on day 11, day 22, and so on through day DD. Each daily amount is at least 00 and less than XX, and the DD amounts add up to exactly NN. A day with no cookies at all is allowed. Two ways are different if there is a day on which the numbers of cookies eaten differ.

For example, if NN, DD and XX are 55, 22 and 55, there are 4 ways.

  • Eat 1 cookie on the first day and 4 cookies on the second day.
  • Eat 2 cookies on the first day and 3 cookies on the second day.
  • Eat 3 cookies on the first day and 2 cookies on the second day.
  • Eat 4 cookies on the first day and 1 cookie on the second day.

The number of ways gets very large, so counting by hand is hopeless. Write a program that counts it instead.

Input

The input consists of several datasets. There are at most 100 datasets. Each dataset is one line holding three integers NN (1N20001 \le N \le 2000), DD (1D10121 \le D \le 10^{12}) and XX (1X20001 \le X \le 2000), separated by spaces. The end of the input is a line containing three zeros, and that line is not processed.

Output

For each dataset, print the number of ways modulo 10000000071000000007 on its own line.