#include #define ll long long int using namespace std; ll power(ll x, ll y, ll p) { int res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x) % p; // y must be even now y = y>>1; // y = y/2 x = (x*x) % p; } return res; } long countArray(int n, int k, int x) { // Return the number of ways to fill in the array. if(k==1 && n!=1) return 0; ll res; res= power(k-1,n-4,1000000007)%1000000007; ll ans = (k*k)%1000000007; ans = (ans+3)%1000000007; ll temp = (3*k)%1000000007; ans = (ans - temp + 1000000007)%1000000007; res = (res * ans)%1000000007; return res; } int main() { int n; int k; int x; cin >> n >> k >> x; long answer = countArray(n, k, x); cout << answer << endl; return 0; }