import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.Scanner; import java.util.StringTokenizer; public class exa { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static int power(int x,int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y%2==1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } public static void main(String a[]) { FastReader sc=new FastReader(); int n = sc.nextInt(); int k = sc.nextInt(); int x = sc.nextInt(); long ans=k-1; int con=1000000007; ans=power(k-1,n-2,con); if(x==1) System.out.println((ans-(k-2)-1)%con); else System.out.println((ans-(k-2))%con); } }