import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.math.BigInteger; public class Solution { private static final long MOD = 1000000007; public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int x = in.nextInt(); long time = System.currentTimeMillis(); /* long res = 1; for (int i = 1; i < n - 1; i++) { if (i < n - 2) { res *= k - 1; res %= MOD; } else { res *= k - 2; res %= MOD; if (x != 1) res += 1; res %= MOD; } } System.out.println(res % MOD); */ BigInteger total = new BigInteger(Integer.toString(k - 1)); total = total.pow(n - 2); BigInteger sub = n % 2 == 0 ? total.subtract(BigInteger.ONE) : total.add(BigInteger.ONE); sub = sub.divide(new BigInteger(Integer.toString(k))); total = total.subtract(sub); if (x == 1) total = n % 2 == 0 ? total.subtract(BigInteger.ONE) : total.add(BigInteger.ONE); System.out.println(total.mod(new BigInteger("1000000007"))); //System.out.println(System.currentTimeMillis() - time); } }