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. long max = 1000000007; long[] f = new long[n + 1]; //[1,...,1] long[] g = new long[n + 1]; //[1,...,2] f[3] = k - 1; g[2] = 1; g[3] = k - 2; for (int i = 4; i <= n; i++) { f[i] = (k - 1) * g[i - 1] % max; g[i] = (f[i - 1] + (k - 2) * g[i - 1]) % max; } return x == 1 ? f[n] : g[n]; } 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(); } }