#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353, N = 2e5 + 5;
inline int input() {
  char c = getchar();
  int o;
  while (c > 57 || c < 48) c = getchar();
  for (o = 0; c > 47 && c < 58; c = getchar()) o = (o << 1) + (o << 3) + c - 48;
  return o;
}
long long A[N], n, k, res = 1, cnt = 0, JC[N], inv[N], Pow2[N], Powk[N];
void init() {
  JC[0] = 1;
  for (int i = 1; i <= cnt; i++) JC[i] = JC[i - 1] * i % mod;
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= cnt; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
  for (int i = 2; i <= cnt; i++) inv[i] = inv[i] * inv[i - 1] % mod;
  Pow2[0] = Powk[0] = 1;
  for (int i = 1; i <= cnt; i++) {
    Pow2[i] = (Pow2[i - 1] << 1) % mod;
    Powk[i] = (Powk[i - 1] * (k - 2)) % mod;
  }
}
long long C(long long a, long long b) {
  return JC[a] * inv[b] % mod * inv[a - b] % mod;
}
void DP() {
  long long ans = 0;
  for (int i = 0; i < cnt; i++, ans %= mod)
    if ((cnt - i) & 1)
      ans = ans + ((C(cnt, i) * Powk[i]) % mod * Pow2[cnt - i - 1] % mod);
    else
      ans = ans + (((C(cnt, i) * Powk[i]) % mod *
                    (Pow2[cnt - i] - C(cnt - i, (cnt - i) / 2) + mod)) %
                   mod * inv[2] % mod);
  res = res * (ans + mod) % mod;
}
int main() {
  n = input();
  k = input();
  for (int i = 1; i <= n; i++) {
    A[++cnt] = input();
    if (A[cnt] == A[cnt - 1]) cnt--, res = res * k % mod;
  }
  if (A[cnt] == A[1]) cnt--, res = res * k % mod;
  init();
  if (k == 1) {
    puts("0");
    return 0;
  } else if (k == 2) {
    long long ans = 0;
    for (int i = 0; i < (cnt + 1) / 2; i++, ans %= mod) ans = ans + C(cnt, i);
    res = res * ans % mod;
    printf("%lld\n", res);
    return 0;
  }
  DP();
  printf("%lld", res);
  return 0;
}
