#include #include #include #include #include #include #include #define ll long long int main() { ll int n; ll int k; ll int x; scanf("%lld%lld%lld",&n,&k,&x); if(n==3) { if(x==1) { printf("%lld",k-1); return 0; } else { printf("%lld",k-2); return 0; } } if(n==4) { if(x==1) { printf("%lld",(k-1)*(k-2)); return 0; } else { printf("%lld",(k-1)*(k-2)+k-2); return 0; } } ll int ans=0; if(x==1) { ans=pow(k-1,n-3)*(k-2)+pow(n-3,k-2); } else { ans=pow(k-1,n-3)*(k-2)+pow(n-3,k-2); } printf("%lld\n", ans); return 0; }