import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static final int mod = 1000_000_007; static long countArray(int n, int k, int x) { long[] dp = new long[n + 1]; dp[3] = (x == 1) ? k - 1 : k - 2; dp[2] = (x == 1) ? 0 : 1; for (int i = 4; i <= n; ++i) { dp[i] += dp[i-2] * (k - 1) + dp[i-1] * (k - 2); dp[i] %= mod; } return dp[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(); } }