import std.algorithm, std.conv, std.range, std.stdio, std.string; const mod = 10^^9+7; alias mint = FactorRing!mod; void main() { auto rd = readln.split.to!(int[]), n = rd[0], k = rd[1], d = rd[2]; auto s = n/(k-1) - (n%(k-1) == 0 || n%(k-1) == 1); auto t = n-s*(k-1); if (d == 1) { writeln(t); return; } auto dp1 = new mint[][](t+1, s+1), dp2 = new mint[][](t+1, s+1), dp3 = new mint[][](t+1, s+1), dp4 = new mint[][](t+1, s+1); dp1[0][0] = 1; dp2[0][0] = 1; foreach (i; 1..t+1) { dp1[i][0] = 1; dp2[i][0] = 1; dp3[i][0] = dp4[i-1][0]; dp4[i][0] = dp4[i-1][0]+1; foreach (j; 1..s+1) { dp1[i][j] = dp1[i-1][j] + dp1[i][j-1]; dp2[i][j] = dp1[i-1][j] + dp2[i][j-1]*d; dp3[i][j] = dp4[i-1][j] + dp3[i][j-1]; dp4[i][j] = dp2[i][j] + dp3[i][j]; } } writeln(dp4[t][s]); } struct FactorRing(int m, bool pos = false) { version(BigEndian) { union { long vl; struct { int vi2; int vi; } } } else { union { long vl; int vi; } } static init() { return FactorRing!(m, pos)(0); } @property int toInt() { return vi; } alias toInt this; this(int v) { vi = v; } this(int v, bool runMod) { vi = runMod ? mod(v) : v; } this(long v) { vi = mod(v); } ref FactorRing!(m, pos) opAssign(int v) { vi = v; return this; } pure auto mod(int v) const { static if (pos) return v % m; else return (v % m + m) % m; } pure auto mod(long v) const { static if (pos) return cast(int)(v % m); else return cast(int)((v % m + m) % m); } static if (!pos) { pure auto opUnary(string op: "-")() const { return FactorRing!(m, pos)(mod(-vi)); } } static if (m < int.max / 2) { pure auto opBinary(string op: "+")(int rhs) const { return FactorRing!(m, pos)(mod(vi + rhs)); } pure auto opBinary(string op: "-")(int rhs) const { return FactorRing!(m, pos)(mod(vi - rhs)); } } else { pure auto opBinary(string op: "+")(int rhs) const { return FactorRing!(m, pos)(mod(vl + rhs)); } pure auto opBinary(string op: "-")(int rhs) const { return FactorRing!(m, pos)(mod(vl - rhs)); } } pure auto opBinary(string op: "*")(int rhs) const { return FactorRing!(m, pos)(mod(vl * rhs)); } pure auto opBinary(string op)(FactorRing!(m, pos) rhs) const if (op == "+" || op == "-" || op == "*") { return opBinary!op(rhs.vi); } static if (m < int.max / 2) { auto opOpAssign(string op: "+")(int rhs) { vi = mod(vi + rhs); } auto opOpAssign(string op: "-")(int rhs) { vi = mod(vi - rhs); } } else { auto opOpAssign(string op: "+")(int rhs) { vi = mod(vl + rhs); } auto opOpAssign(string op: "-")(int rhs) { vi = mod(vl - rhs); } } auto opOpAssign(string op: "*")(int rhs) { vi = mod(vl * rhs); } auto opOpAssign(string op)(FactorRing!(m, pos) rhs) if (op == "+" || op == "-" || op == "*") { return opOpAssign!op(rhs.vi); } }