#include #include #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 vector VVL; typedef pair P; typedef pair PL; const ll mod = 1e9 + 7; ll dp[100000][2]; 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; } int main() { int n, k, x; cin >> n >> k >> x; dp[0][0] = 1; REP(i,n-1){ dp[i+1][0] = dp[i][1]; dp[i+1][1] = (dp[i][0] * (k-1) + dp[i][1] * (k-2)) % mod; } ll ans; if (x == 1){ ans = dp[n-1][0]; }else{ ans = divll(dp[n-1][1], k-1); } cout << ans << endl; return 0; }