#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i=b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector VI; typedef vector VL; typedef vector VVI; typedef pair P; typedef pair PL; #define mod 1000000007 ll add(ll x, ll y){ return (x+y)%mod; } ll mul(ll x, ll y){ return (x%mod)*(y%mod)%mod; } ll powll(ll x, ll y){ ll res = 1LL; while(y){ if (y & 1LL) res *= x; res %= mod; x = (x*x) % mod; y >>= 1LL; } return res; } ll divll(ll x, ll y){ return (x * powll(y,mod-2)) % mod; } ll nPr(ll n, ll r){ ll res = 1LL; FOR(i,1,r){ res = (res * ((n-i+1) % mod)) % mod; } return res; } ll nCr(ll n, ll r){ ll res = nPr(n,r); FOR(i,1,r){ res = (res * powll(i,mod-2)) % mod; } return res; } int main() { ll n, k, d; cin >> n >> k >> d; ll x = (n-1)/(k-1), m = n - x*(k-1); if(d == 1){ cout << m << endl; return 0; } ll ans = 0, dd = 1; ll ncr = nCr(m-2+x, x); for (ll y = 0; y <= x; y++){ ans = (ans + dd * nCr(m-2+x-y, x-y)) % mod; dd = (dd * d) % mod; ncr = (ncr * (x-y)) % mod; ncr = divll(ncr, m-2+x-y); } ans = (ans * m) % mod; cout << ans << endl; return 0; }