Problem:
Score : 800 points

Problem Statement

There are N squares arranged in a row, numbered 1 to N 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 H blocks on every square:

Let M and m be the maximum and minimum numbers of blocks currently stacked on a square, respectively. Choose a square on which m 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 M and at most M + D blocks on that square.

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

Constraints

2 \leq N \leq 10^6

1 \leq D \leq H \leq 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N H D

Output

Print the number of ways to have H blocks on every square, modulo 10^9+7.

Sample Input 1

2 2 1

Sample Output 1

6

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

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

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

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

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

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

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

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

Sample Input 2

2 30 15

Sample Output 2

94182806

Sample Input 3

31415 9265 3589

Sample Output 3

312069529

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

Solution in C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());
		long[,] changes = new long[2,3];
    for(int i = 0; i < 2; i++)
    {
      string[] inputa = Console.ReadLine().Split(' ');
	    changes[i,0] = long.Parse(inputa[0]);
      changes[i,1] = long.Parse(inputa[1]);
      changes[i,2] = long.Parse(inputa[2]);
    }

    long memo = 0;
    long m = n;
    for(int i = 0; i <= n; i++)
    {
      for(int j = 0; j <= n-i; j++)
      {
        if(changes[0,0] < changes[1,0]) memo += changes[1,0]*(i/changes[0,0])
          +(i-i/changes[0,0]*changes[0,0]);
        if(changes[0,1] < changes[1,1]) memo += changes[1,1]*(j/changes[0,1])
          +(j-j/changes[0,1]*changes[0,1]);
        if(changes[0,2] < changes[1,2]) memo += changes[1,2]*((n-i-j)/changes[0,2])
          +((n-i-j)-(n-i-j)/changes[0,2]*changes[0,2]);
        m = Math.Max(m,memo);
      }
    }
    n = m;
    m = n;

    if(changes[0,0] < changes[1,0])
    {
      for(int i = 0; i <= n; i++)
      { 
        memo = 0;
        if(changes[1,1] < changes[0,1]) memo += changes[0,1]*(i/changes[1,1]);
        if(changes[1,2] < changes[0,2]) memo += changes[0,2]*((n-i)/changes[1,2]);
        m = Math.Max(m,memo);
      }
    }else if(changes[0,1] < changes[1,1])
    {
      for(int i = 0; i <= n; i++)
      { 
        memo = 0;
        if(changes[1,0] < changes[0,0]) memo += changes[0,0]*(i/changes[1,0]);
        if(changes[1,2] < changes[0,2]) memo += changes[0,2]*((n-i)/changes[1,2]);
        m = Math.Max(m,memo);
      }
    }else if(changes[0,2] < changes[1,2])
    {
      for(int i = 0; i <= n; i++)
      { 
        memo = 0;
        if(changes[1,1] < changes[0,1]) memo += changes[0,1]*(i/changes[1,1]);
        if(changes[1,0] < changes[0,0]) memo += changes[0,0]*((n-i)/changes[1,0]);
        m = Math.Max(m,memo);
      }
    }else
    {
      for(int i = 0; i <= n; i++)
      {
        for(int j = 0; j <= n-i; j++)
        {
          memo = 0;
          if(changes[1,0] < changes[0,0]) memo += changes[0,0]*(i/changes[1,0]);
          if(changes[1,1] < changes[0,1]) memo += changes[0,1]*(j/changes[1,1]);
          if(changes[1,2] < changes[0,2]) memo += changes[0,2]*((n-i-j)/changes[1,2]);
          m = Math.Max(m,memo);
        }
      }
    }
    Console.WriteLine(m);
	}
}