import java.util.*; import java.io.*; public class Solution { static long MOD = 1000000007L; public static void main(String[] args) throws Exception{ InputReader in = new InputReader(System.in); long n = in.nextLong(); long k = in.nextLong(); long x = in.nextLong(); if(n==3) { if(x==1) { System.out.println(k-1); } else { System.out.println(k-2); } } else { long base = power(k-1,n-3); long rslt = (k-2)*base; //System.out.println(rslt); rslt+=MOD; rslt%=MOD; rslt+=1; rslt%=MOD; System.out.println(rslt); } } public static void QuickSort(int[] A, int lo, int hi) { if(lokey) { hi = mid-1; } else { lo = mid+1; } } return -1; } public static int upperBound(int[] A, int key, int lo, int hi) { while(lo<=hi) { int mid = (lo+hi)/2; if(A[mid]>key && (mid==1 || A[mid-1]<=key)) { return mid; } else if(A[mid]>key) { hi = mid-1; } else { lo = mid+1; } } return -1; } public static int lowerBound(int[] A, int key, int lo, int hi) { while(lo<=hi) { int mid = (lo+hi)/2; if(A[mid]>=key && (mid==1 || A[mid-1]=key) { hi = mid-1; } else { lo = mid+1; } } return -1; } public static long power(long x, long n) { if(n==1L) { return x; } long ret = (power(x,n/2)+MOD)%MOD; long val = (ret*ret+MOD)%MOD; if(n%2==1) { val*=x; val+=MOD; val%=MOD; } return val; } public static void initialize(int[] A, int[] segmentTree, int start, int end, int index) { if(start==end) { segmentTree[index] = start; return; } int mid = (start+end)/2; initialize(A,segmentTree, start, mid, index*2+1); initialize(A,segmentTree, mid+1, end, index*2+2); if(A[segmentTree[index*2+1]]<=A[segmentTree[index*2+2]]) { segmentTree[index] = segmentTree[index*2+1]; } else { segmentTree[index] = segmentTree[index*2+2]; } } public static void update(int[] A, int[] segmentTree, int start, int end, int index, int pos, int val) { if(start==end) { A[segmentTree[index]] = val; return; } int mid = (start+end)/2; if(pos<=mid) { update(A,segmentTree,start,mid,index*2+1,pos,val); } else { update(A,segmentTree,mid+1,end,index*2+2,pos,val); } if(A[segmentTree[index*2+1]]<=A[segmentTree[index*2+2]]) { segmentTree[index] = segmentTree[index*2+1]; } else { segmentTree[index] = segmentTree[index*2+2]; } } public static int query(int[] A, int[] segmentTree, int start, int end, int index, int rangeStart, int rangeEnd) { if(rangeStart>end || rangeEnd=end) { return segmentTree[index]; } int mid = (start+end)/2; int val1 = query(A,segmentTree, start, mid, index*2+1, rangeStart, rangeEnd); int val2 = query(A,segmentTree, mid+1, end, index*2+2, rangeStart, rangeEnd); if(val1==-1) { return val2; } if(val2==-1) { return val1; } if(A[val1]<=A[val2]) { return val1; } return val2; } public static void constructSegmentTree(int[] A, int n) { int x = (int)Math.ceil(Math.log(n)/Math.log(2)); int size =0; int[] segmentTree = new int[size+1]; initialize(A,segmentTree,0,n-1,0); //update update(A,segmentTree,0,n-1,0,4,10); //query int ret = query(A,segmentTree,0,n-1,0,9,9); } public static int[][][] FibonacciGeneration(int P) { int[][][] A = new int[P][2][2]; A[0][0][0] = 1; A[0][0][1] = 1; A[0][1][0] = 1; A[0][1][1] = 0; for(int i=1;i=0;i--) { if((T&(1<