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++14 (GCC 5.4.1) (judge verdict: Accepted)

#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 1000005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,h,d;
int fact[MAXN],sfact[MAXN],dp[MAXN],sum[MAXN];
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
void dec(int &a,int b) {a-=b; if(a<0) a+=MOD;}
int get_sum(int x,int y)
{
    if(x<=0) return sum[y];
    int ret=sum[y];
    dec(ret,sum[x-1]);
    return ret;
}
int main()
{
    fact[0]=1;
    for(int i=1;i<=1000000;i++) fact[i]=1LL*fact[i-1]*i%MOD;
    for(int i=1;i<=1000000;i++) {sfact[i]=fact[i]; add(sfact[i],sfact[i-1]);}
    dp[0]=1;
    sum[0]=1;
    scanf("%d%d%d",&n,&h,&d);
    for(int i=1;i<=h-1;i++)
    {
        dp[i]=get_sum(i-d,i-1);
        dp[i]=1LL*dp[i]*sfact[n]%MOD;
        sum[i]=sum[i-1]; add(sum[i],dp[i]);
    }
    dp[h]=get_sum(h-d,h-1);
    dp[h]=1LL*dp[h]*fact[n]%MOD;
    printf("%d\n",dp[h]);
    return 0;
}