#include <bits/stdc++.h>
const int MAXN = 2e5 + 7;
const long long HA = 998244353;
long long fp(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) r = r * a % HA;
    b >>= 1, a = a * a % HA;
  }
  return r;
}
int n, k, a[MAXN], m;
long long fac[MAXN], ifac[MAXN];
long long C(int n, int m) {
  return n < m ? 0 : fac[n] * ifac[m] % HA * ifac[n - m] % HA;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = (1); i <= (n); ++i)
    scanf("%d", &a[i]), m += (a[i] == (a[i - 1]));
  m += a[1] == a[n];
  m = n - m;
  fac[0] = ifac[0] = 1;
  for (int i = (1); i <= (n); ++i) fac[i] = fac[i - 1] * i % HA;
  ifac[n] = fp(fac[n], HA - 2);
  for (int i = (n - 1); i >= (1); --i) ifac[i] = ifac[i + 1] * (i + 1) % HA;
  long long ans = fp(k, n - m) * fp(2, HA - 2) % HA;
  long long gx = fp(k, m);
  for (int i = 0; i * 2 <= m; i++) {
    long long tmp = fp(k - 2, m - 2 * i) * C(m, i) % HA * C(m - i, i) % HA;
    gx = (gx - tmp + HA) % HA;
  }
  printf("%lld\n", ans * gx % HA);
  return 0;
}
