#include using namespace std; long mod(long a) { long r = a % 1000000007; return r < 0 ? r + 1000000007 : r; } long countArray(int n, int k, int x) { long all = k - 1; long with_x = x == 1 ? 0 : 1; for (int i = 2; i < n - 1; ++i) { with_x = mod(all - with_x); all = mod(all * (k - 1)); } return mod(all - with_x); } int main() { int n; int k; int x; cin >> n >> k >> x; long answer = countArray(n, k, x); cout << answer << endl; return 0; }