#include using namespace std; uint64_t countArray(double n, double k, double x) { // Return the number of ways to fill in the array. double sol = 0; sol = pow(k, (int)n - 2); //(1)Total number of permutations sol -= pow(k, (int)n - 3); //(2)All starting with 1 sol -= (k-2); //(3)Single repeted digit permutations sol -= pow(k, (int)n - 3); //(4)All permutations ending with x sol += pow(k, (int)n - 4); //(5)Account for already discarded permutations in (2) // For higher number of digits take care of repatings within (1223) if ((n-2) > 3) { } return (uint64_t)sol; } int main() { uint64_t n; uint64_t k; uint64_t x; cin >> n >> k >> x; uint64_t answer = countArray((double)n, (double)k, (double)x); cout << answer << endl; return 0; }