//EVIEBOT #include #define inf 0x3f3f3f3f #define INF 1000111000111000111LL #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define fastIO ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL); #define endl '\n' #define pb push_back #define pf push_front #define fi first #define se second #define MP make_pair #define MT make_tuple #define clr(xxx) memset(xxx, 0, sizeof(xxx)); typedef long long int lli; using namespace std; ofstream outfile; ifstream infile; int main() { infile.open("input.txt"); outfile.open("output.txt"); lli n, k, i, x, mod = 1000000007; cin >> n >> k >> x; lli waysall[100010], wayslastx[100010], waysf[100010]; waysall[1] = 1; if(x == 1){ wayslastx[1] = 1; waysf[1] = 1; }else{ wayslastx[1] = 0; waysf[1] = 0; } for(lli i = 2; i <= n; ++i){ waysall[i] = (waysall[i-1]*(k-1))%mod; wayslastx[i] = waysall[i-1]; waysf[i] = (((wayslastx[i] - waysf[i-1])%mod)+mod)%mod; } cout << waysf[n] << "\n"; }