using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static long[,] cs = new long[2, 2]; static long mod = 1000000007; static long countArray(long n, long k, long x) { cs[0, 0] = 0; cs[0, 1] = 1; for (long i = 2; i < n - 1; i++) { cs[1, 0] = (cs[0, 1] * (k - 1)) % mod; cs[1, 1] = (cs[0, 0] + (k - 2) * cs[0, 1]) % mod; cs[0, 0] = cs[1, 0]; cs[0, 1] = cs[1, 1]; } if (x == 1) { return ((k - 1) * cs[1, 1]) % mod; } else { return ((k - 2) * cs[1, 1] + cs[1, 0]) % mod; ; } } static void Main(String[] args) { string[] tokens_n = Console.ReadLine().Split(' '); int n = Convert.ToInt32(tokens_n[0]); int k = Convert.ToInt32(tokens_n[1]); int x = Convert.ToInt32(tokens_n[2]); long answer = countArray(n, k, x); Console.WriteLine(answer); } }