#include using namespace std; typedef unsigned long long int ll; ll c=pow(10,9)+7; ll f(ll k,ll n,ll i) { if(i==n-1){return (k-1)%c;} else return ((f(k,n,i+1))*((k-1)%c))%c; } ll countArray(ll n,ll k,ll x) { // Return the number of ways to fill in the array. return (f(k,n,3)*((k-2)%c))%c+1; } int main() { ll n; ll k; ll x; cin >> n >> k >> x; ll answer = countArray(n, k, x); cout << answer << endl; return 0; }