#include <bits/stdc++.h>   using ul = std::uint32_t;   using li = std::int32_t;   using ull = std::uint64_t;   using ll = std::int64_t;   using llf = long double;   ul n, m, k;   const ul maxn = 2e5;   const ul base = 998244353;   ul plus(ul a, ul b) { return a + b < base ? a + b : a + b - base; }   ul plus(ul a, ul b, ul c) { return plus(plus(a, b), c); }   ul minus(ul a, ul b) { return a < b ? a + base - b : a - b; }   ul mul(ul a, ul b) { return ull(a) * ull(b) % base; }   ul mul(ul a, ul b, ul c) { return mul(mul(a, b), c); }   ul mul(ul a, ul b, ul c, ul d) { return mul(mul(a, b, c), d); }   void exgcd(li a, li b, li& x, li& y) {     if (b) {       exgcd(b, a % b, y, x);       y -= a / b * x;     } else {       x = 1;       y = 0;     }   }   ul inverse(ul a) {     li x, y;     exgcd(a, base, x, y);     return x < 0 ? x + li(base) : x;   }   ul pow(ul a, ul b) {     ul ret = 1;     while (b) {       if (b & 1) {         ret = mul(a, ret);       }       b >>= 1;       a = mul(a, a);     }     return ret;   }   ul h[maxn + 1];   ul fac[maxn + 1];   ul fiv[maxn + 1];   ul twopow[maxn + 1];   ul bi(ul a, ul b) { return mul(fac[a], fiv[b], fiv[a - b]); }   ul g(ul a) {     ul ret = mul(base + 1 >> 1, twopow[a]);     if (~a & 1) {       ret = minus(ret, mul(base + 1 >> 1, bi(a, a >> 1)));     }     return ret;   }   int main() {     fac[0] = 1;     twopow[0] = 1;     for (ul i = 1; i <= maxn; ++i) {       fac[i] = mul(fac[i - 1], i);       twopow[i] = plus(twopow[i - 1], twopow[i - 1]);     }     fiv[maxn] = inverse(fac[maxn]);     for (ul i = maxn; i; --i) {       fiv[i - 1] = mul(fiv[i], i);     }     std::scanf( %u%u , &n, &k);     k %= base;     for (ul i = 1; i <= n; ++i) {       std::scanf( %u , &h[i]);     }     for (ul i = 1; i <= n; ++i) {       m += h[i] != h[i % n + 1];     }     ul ans = 0;     for (ul a = 0; a <= m; ++a) {       ans = plus(ans, mul(bi(m, a), pow(minus(k, 2), m - a), g(a)));     }     ans = mul(ans, pow(k, n - m));     std::printf( %u n , ans);     return 0;   }   