atcoder#DIVERTA20192E. Balanced Piles

Balanced Piles

Score : 800800 points

Problem Statement

There are NN squares arranged in a row, numbered 11 to NN from left to right. Takahashi will stack building blocks on these squares, on which there are no blocks yet.

He wants to stack blocks on the squares evenly, so he will repeat the following operation until there are HH blocks on every square:

  • Let MM and mm be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which mm blocks are stacked (if there are multiple such squares, choose any one of them), and add a positive number of blocks on that square so that there will be at least MM and at most M+DM + D blocks on that square.

Tell him how many ways there are to have HH blocks on every square by repeating this operation. Since there can be extremely many ways, print the number modulo 109+710^9+7.

Constraints

  • 2N1062 \leq N \leq 10^6
  • 1DH1061 \leq D \leq H \leq 10^6
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN HH DD

Output

Print the number of ways to have HH blocks on every square, modulo 109+710^9+7.

2 2 1
6

The possible transitions of (the number of blocks on Square 11, the number of blocks on Square 22) are as follows:

  • (0,0)(0, 0) -> (0,1)(0, 1) -> (1,1)(1, 1) -> (1,2)(1, 2) -> (2,2)(2, 2)
  • (0,0)(0, 0) -> (0,1)(0, 1) -> (1,1)(1, 1) -> (2,1)(2, 1) -> (2,2)(2, 2)
  • (0,0)(0, 0) -> (0,1)(0, 1) -> (2,1)(2, 1) -> (2,2)(2, 2)
  • (0,0)(0, 0) -> (1,0)(1, 0) -> (1,1)(1, 1) -> (1,2)(1, 2) -> (2,2)(2, 2)
  • (0,0)(0, 0) -> (1,0)(1, 0) -> (1,1)(1, 1) -> (2,1)(2, 1) -> (2,2)(2, 2)
  • (0,0)(0, 0) -> (1,0)(1, 0) -> (1,2)(1, 2) -> (2,2)(2, 2)

Thus, there are six ways to have two blocks on every square.

2 30 15
94182806
31415 9265 3589
312069529

Be sure to print the number modulo 109+710^9+7.