#include using namespace std; #define NUM 100005 #define LEN 1000000007 static inline int mulp(int a, int b, int p) { long long int ta = (long long int)(a%p); long long int tb = (long long int)(b%p); long long int tp = (ta*tb)%(long long int)p; return (int)tp; } long countArray(int n, int k, int x) { int tot, n1, otot, on1, i; otot = 1; if (x == 1) on1 = 1; else on1 = 0; for(i=n-2; i>=0; i--) { tot = mulp(k-1, otot, LEN); n1 = (otot-on1+LEN)%LEN; otot = tot; on1 = n1; } return n1; } int main() { int n; int k; int x; cin >> n >> k >> x; long answer = countArray(n, k, x); cout << answer << endl; return 0; }