#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int N = 2097155;
const int mo = 998244353;
const double pi = acos(-1);
inline int read() {
  int x = 0, f = 1;
  char ch = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
  return x * f;
}
inline int ksm(int p, int q, int mo) {
  int res = 1;
  for (; q; q >>= 1, p = 1LL * p * p % mo)
    if (q & 1) res = 1LL * res * p % mo;
  return res;
}
const int MAXN = 200010;
const int inv2 = (mo + 1) / 2;
int K[MAXN], n, ds, k;
int fac[MAXN], inv[MAXN];
inline int C(int p, int q) {
  if (!p || !q)
    return 1;
  else
    return 1LL * fac[p] * inv[q] % mo * inv[p - q] % mo;
}
inline void init() {
  fac[0] = 1;
  for (int i = 1; i <= MAXN - 10; ++i) fac[i] = 1LL * fac[i - 1] * i % mo;
  inv[MAXN - 10] = ksm(fac[MAXN - 10], mo - 2, mo);
  for (int i = MAXN - 11; i >= 0; i--) inv[i] = 1LL * inv[i + 1] * (i + 1) % mo;
}
int main() {
  init();
  n = read();
  k = read();
  for (int i = 1; i <= n; ++i) K[i] = read();
  for (int i = 2; i <= n; ++i) ds += (K[i] == K[i - 1]);
  if (K[1] == K[n]) {
    int tot = ksm(k, n - 1 - ds, mo);
    int zhong = 0;
    for (int i = 0; i <= (n - 1 - ds) >> 1; ++i) {
      (zhong += 1LL * ksm(k - 2, n - 1 - ds - (i << 1), mo) * C(i << 1, i) %
                mo * C(n - 1 - ds, i << 1) % mo) %= mo;
    }
    printf("%d\n",
           1LL * (tot - zhong + mo) % mo * inv2 % mo * ksm(k, ds + 1, mo) % mo);
  } else {
    int tot = ksm(k, n - 1 - ds, mo);
    int pianyou = 0, zhong = 0, ans = 0;
    for (int i = 0; i <= (n - 1 - ds - 1) >> 1; ++i)
      (pianyou += 1LL * ksm(k - 2, n - 1 - ds - (i << 1) - 1, mo) *
                  C((i << 1) + 1, i) % mo * C(n - 1 - ds, (i << 1) + 1) % mo) %=
          mo;
    ans = (tot - pianyou + mo) % mo;
    for (int i = 0; i <= (n - 1 - ds) >> 1; ++i)
      (zhong += 1LL * ksm(k - 2, n - 1 - ds - (i << 1), mo) * C(i << 1, i) %
                mo * C(n - 1 - ds, i << 1) % mo) %= mo;
    (ans += (1LL * (tot - zhong + mo) % mo * inv2 % mo * (k - 2) % mo)) %= mo;
    printf("%d\n", 1LL * ans * ksm(k, ds, mo) % mo);
  }
}
