#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, P = 998244353;
int n, k, m, ans, h[N], fac[N], inv[N];
int qpow(int B, int p) {
  int R = 1;
  for (; p; p >>= 1, B = 1LL * B * B % P)
    if (p & 1) R = 1LL * R * B % P;
  return R;
}
inline int C(int i, int j) {
  return 1LL * fac[i] * inv[j] % P * inv[i - j] % P;
}
int main() {
  scanf("%d%d", &n, &k);
  fac[0] = 1;
  for (int i = 1; i <= n; ++i)
    scanf("%d", h + i), fac[i] = 1LL * fac[i - 1] * i % P;
  h[n + 1] = h[1], inv[n] = qpow(fac[n], P - 2);
  for (int i = 1; i <= n; ++i)
    if (h[i] != h[i + 1]) ++m;
  for (int i = n - 1; ~i; --i) inv[i] = 1LL * inv[i + 1] * (i + 1) % P;
  for (int i = 0; i <= m >> 1; ++i)
    ans = (ans + 1LL * C(m, i) * C(m - i, i) % P * qpow(k - 2, m - 2 * i) % P) %
          P;
  ans = 1LL * (qpow(k, m) - ans + P) % P * qpow(2, P - 2) % P;
  printf("%lld\n", 1LL * ans * qpow(k, n - m) % P);
  return 0;
}
