import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static long countArray(int n, int k, int x) { // Return the number of ways to fill in the array. if(n==3 && x==1) return k-1; else if(n==3) return k-2; if(n==4 & x==1) return (k-1)*(k-2); if(n==4) return((k-1)+(k-2)*(k-2)); long product=(long)Math.pow(k-1,n-4); long sum=0; sum=(product*(k-1)+product*(k-2)*(k-2)); return sum; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int x = in.nextInt(); long answer = countArray(n, k, x); System.out.println(answer); in.close(); } }