#include using namespace std; typedef long long ll; const ll mod = 1e9 + 7; ll countArray(int n, int k, int x) { vector notone(n), isone(n); isone[0] = 1; notone[0] = 0; for (int i = 1; i < n; i++) { notone[i] = (notone[i - 1] * (k - 2) + isone[i - 1]) % mod; isone[i] = (notone[i - 1] * (k - 1)) % mod; } if (x == 1) return isone[n - 1]; else return notone[n - 1]; } int main() { int n; int k; int x; cin >> n >> k >> x; ll answer = countArray(n, k, x); cout << answer << endl; return 0; }