/****************************************** * AUTHOR: CHIRAG AGARWAL * * INSTITUITION: BITS PILANI, PILANI * ******************************************/ #include using namespace std; typedef long long LL; typedef long double LD; const int MOD=1e9+7; typedef long long LL; int add(int a, int b, int c) { int res = a + b; return (res >= c ? res - c : res); } int mod_neg(int a, int b, int c) { int res; if(abs(a-b) < c) res = a - b; else res = (a-b) % c; return (res < 0 ? res + c : res); } int mul(int a, int b, int c) { LL res = (LL)a * b; return (res >= c ? res % c : res); } template T power(T e, T n, T m) { T x = 1, p = e; while(n) { if(n & 1) x = mul(x, p, m); p = mul(p, p, m); n >>= 1; } return x; } template T extended_euclid(T a, T b, T &x, T &y) { T xx = 0, yy = 1; y = 0; x = 1; while(b) { T q = a / b, t = b; b = a % b; a = t; t = xx; xx = x - q * xx; x = t; t = yy; yy = y - q * yy; y = t; } return a; } template T mod_inverse(T a, T n) { T x, y, z = 0; T d = extended_euclid(a, n, x, y); return (d > 1 ? -1 : mod_neg(x, z, n)); } const int MAX=1e5+5; LL f[MAX]; int main() { int n,k,x; scanf("%d %d %d",&n,&k,&x); if(x==1) { f[2]=0; f[3]=k-1; } else { f[2]=1; f[3]=k-2; } for(int i=4;i<=n;i++) { f[i]=(((f[i-2]*1ll*(k-1))%MOD)+((((power(k-1,i-3,MOD)-f[i-2]+MOD)%MOD)*1ll*(k-2))%MOD))%MOD; }//f represents ending with x printf("%lld\n",f[n]); return 0; }