import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static BigInteger one = BigInteger.ONE; static BigInteger two = one.add(one); static BigInteger three = two.add(one); static BigInteger mod = new BigInteger("" + 1000000007); static BigInteger countArray(int n, int k, int x) { // Return the number of ways to fill in the array. BigInteger bigK = new BigInteger("" + k); BigInteger num1 = bigK.subtract(one); BigInteger total = (num1.pow(n - 2)); if (x == 1) { return (total.subtract(bigK.subtract(one))).mod(mod); } else { return (total.subtract(bigK.subtract(two))).mod(mod); } } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int x = in.nextInt(); BigInteger answer = countArray(n, k, x); System.out.println(answer); in.close(); } }