#include <bits/stdc++.h>   using namespace std;   long long n, k;   int a[200007];   long long fac[200007];   long long inv[200007];   long long pw2[200007];   long long free_pw[200007];   long long fastpow(long long x, long long st) {     long long ret = 1;     while (st > 0) {       if ((st & 1) != 0) {         ret = (ret * x) % 998244353;         --st;       } else {         x = (x * x) % 998244353;         st >>= 1;       }     }     return ret;   }   long long get_comb(long long x, long long y) {     if (x < y) {       return 0;     }     long long ret = fac[x];     ret = (ret * inv[y]) % 998244353;     ret = (ret * inv[x - y]) % 998244353;     return ret;   }   void input() {     scanf( %I64d%I64d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     a[n + 1] = a[1];     fac[0] = pw2[0] = free_pw[0] = 1;     for (int i = 1; i <= n; ++i) {       fac[i] = (fac[i - 1] * i) % 998244353;       pw2[i] = (pw2[i - 1] * 2) % 998244353;       free_pw[i] = (free_pw[i - 1] * (k - 2)) % 998244353;     }     inv[n] = fastpow(fac[n], 998244353 - 2);     for (int i = n - 1; i >= 0; --i) {       inv[i] = (inv[i + 1] * (i + 1)) % 998244353;     }   }   void solve() {     int free = 0;     long long aux = 1;     for (int i = 1; i <= n; ++i) {       if (a[i] == a[i + 1]) {         ++free, aux = (aux * k) % 998244353;       }     }     long long ans = 0;     for (int i = 0; i < n - free; ++i) {       long long w = (get_comb(n - free, i) * free_pw[i]) % 998244353;       int lft = n - free - i;       long long coef = pw2[lft];       if ((lft & 1) == 0) {         coef = (coef - get_comb(lft, lft / 2) + 998244353) % 998244353;       }       coef = (coef * inv[2]) % 998244353;       ans = (ans + (w * coef) % 998244353) % 998244353;     }     printf( %I64d n , (aux * ans) % 998244353);   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     input();     solve();     return 0;   }   