import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int gcd(int a,int b) { return a-b; } static long countArray(int n, int k, int x,long x1[],long x2[]) { // Return the number of ways to fill in the array. gcd(4,5); if(n<2) return 0l; if(n==3&&x==1) return k-1; if(n==3&&x!=1) return k-2; if(n==2&&x==1) return 0; if(n==2&&x!=1) return 1; return (k*x2[n-3]-2*x2[n-3]+countArray(n-2,k,x,x1,x2)+(long)(Math.pow(10,9)+7))%(long)(Math.pow(10,9)+7); } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int x = in.nextInt(); long x1[]=new long[100009]; long x2[]=new long[100009]; x1[0]=1l; x2[0]=1l; for(int i=1;i<=n;i++) { x1[i]=x1[i-1]*k; x2[i]=x2[i-1]*(k-1); x1[i]%=(long)(Math.pow(10,9)+7); x2[i]%=(long)(Math.pow(10,9)+7); } long answer = countArray(n, k, x, x1, x2); System.out.println(answer); in.close(); } }