using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static long countArray(int n, int k, int x) { // Return the number of ways to fill in the array. long c = 1; long s = k-1; long b = 1000000007; for(int i = 0; i < n-3; i++) { c = (s - c + b) % b; s *= k-1; s = s%1000000007; } if(x != 1) return (s - c + b) % b; else return c*(k-1)%1000000007; } 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); } }