#include using namespace std; #define mod 1000000007 int main() { int n,k,x; cin >> n >> k >> x; long long sum=1; for(int i=2;i<(n-2);i++) sum = (long long)((sum * (k-1))%mod); sum = (sum * k)%mod; cout << sum << endl; return 0; }