func_code_string: #include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline long long fast_pow(long long a, long long b, long long p) {     long long t = 1;     a %= p;     while (b) {       if (b & 1) t = t * a % p;       b >>= 1ll;       a = a * a % p;     }     return t;   }   long long inv[1010101], fac[1010101], n, h[1010101], K;   inline long long C(long long n, long long m) {     if (n < 0 || m < 0 || n < m) return 0;     return fac[n] * inv[m] % 998244353 * inv[n - m] % 998244353;   }   int main() {     n = read(), K = read();     long long ttt = 0;     for (int i = 1; i <= n; i++) {       h[i] = read();     }     for (int i = 1; i <= n; i++) {       if (h[i] != h[(i + 1 == n + 1) ? 1 : (i + 1)]) ttt++;     }     fac[0] = inv[0] = inv[1] = 1;     for (long long i = 2; i <= n; i++)       inv[i] = (998244353 - (998244353 / i) * inv[998244353 % i] % 998244353) %                998244353;     for (int i = 2; i <= n; i++) inv[i] = inv[i - 1] * inv[i] % 998244353;     for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % 998244353;     long long ans = 0;     long long inv2 = fast_pow(2ll, 998244353 - 2, 998244353);     for (long long i = 0; i <= ttt; i++) {       ans =           (ans +            C(ttt, i) * fast_pow(K - 2 + 998244353, ttt - i, 998244353) %                998244353 *                ((fast_pow(2ll, i, 998244353) - ((i % 2 == 1) ? 0 : C(i, i / 2))) *                     inv2 % 998244353 +                 998244353) %                998244353) %           998244353;     }     cout << ans * fast_pow(K, n - ttt, 998244353) % 998244353;     return 0;   }   