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) { long nx = 1; long xt = 0; if(x==1) { xt=1; nx=0; } long temp; for(int i=2;i<=n;i++) { temp = nx; nx = m(nx*(k-2) + xt*(k-1)); xt = temp; } return xt; } 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(); } static long m(long k) { return k%1000000007; } }