import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static final long constant = 1_000_000_007; static long countArray(int n, int k, int x) { // Return the number of ways to fill in the array. long a = (k - 1) % constant; long b = (k - 2) % constant; int tempN = n - 3; while (tempN > 0) { long tempA = (k-1)*b % constant; long tempB = (a + (k-2)*b) % constant; a = tempA; b = tempB; tempN--; } if (x == 1) { return a; } else { return b; } } 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(); } }