using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Diagnostics; class Solution { 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); } static long countArray(int n, int k, int x) { // special cases if (n == 2) { if (x == 1) { return 0; } else { return 1; } } else if (n == 3) { if (k == 2) { if (x == 1) { return 0; } else { return 1; } } else { if (x == 1) { return k - 1; } else { return k - 2; } } } long mod = 1000000007; long count = k; for (int i = 0; i < n - 3; i++) { count *= k - 1; count = count >= mod ? count % mod : count; } // Console.WriteLine("{0} different sub arrays", count); int s = n - 2; long discount = 2 * (long)Math.Pow(k - 1, s - 1); discount -= countArray(s, k, x); // Console.WriteLine("discount is {0}", discount); count -= discount; count = count >= mod ? count % mod : count; return count; } }