import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static final long mod = 1000000007; static public long f[] = new long[100100]; static long na(long a, long n) { if(n == 0) return 1; long q = na(a,n/2); q = (q*q)%mod; if(n%2 == 0) return q; return (q*a)%mod; } static long countArray(int n, int k, int x) { if(k == 2) { if(2-(n%2) == x) return 1; return 0; } if(x != 1) f[2] = 1; else f[2] = 0; for(int i=3;i<=n;i++) f[i] = (na(k-1,i-2) - f[i-1])%mod; if(f[n] < 0) f[n] += mod; return f[n]; // Return the number of ways to fill in the array. } 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 answer = countArray(n, k, x); System.out.println(answer); in.close(); } }