#include using namespace std; const long MOD = 1000000007; long countArray(int n, int k, int x) { long ones = 1; long others = 0; for (int i = 1; i < n; ++i) { int newOthers = (ones + others * (k - 2) % MOD) % MOD; int newOnes = others * (k - 1) % MOD; others = newOthers; ones = newOnes; } return x == 1 ? ones : others; } int main() { int n; int k; int x; cin >> n >> k >> x; long answer = countArray(n, k, x); cout << answer << endl; return 0; }