#include using namespace std; using ll = long long; const ll MOD = 1000000007; ll modpow(ll x, ll n, ll mod = MOD) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll calc(int i, int d) { ll tmp = modpow(d + 1, i - 1); ll res = (tmp + MOD - 1) % MOD * modpow(d, MOD - 2) % MOD; (res += tmp * (d + 2) % MOD) %= MOD; (res += (MOD - i - 1)) %= MOD; return res; } ll G[50], N[50]; ll solve(int idx, ll num) { if (idx == 0) return 0; ll res = 0, cnt = 0; while (true) { if (cnt + N[idx - 1] <= num) { cnt += N[idx - 1]; (res += G[idx - 1]) %= MOD; } else { (res += solve(idx - 1, num - cnt)) %= MOD; break; } if (cnt == num) break; if (cnt + 1 <= num) { cnt += 1; (res += idx) %= MOD; } if (cnt == num) break; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, b, d; cin >> n >> b >> d; int lim = 0; N[0] = 1; for (int i = 0; ; i++) { if (N[i] - 1 > n) { N[i]--; break; } lim++; N[i + 1] = N[i] * (d + 1); N[i]--; } for (int i = 1; i < lim; i++) { G[i] = calc(i, d); } ll ans = calc(b, d); (ans += MOD - solve(lim, n)) %= MOD; cout << ans << endl; return 0; }