#include <bits/stdc++.h>
inline int read() {
  char c = getchar();
  int x = 0, ft = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') ft = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  return x * ft;
}
const int mod = 998244353, N = 2e5 + 5;
inline int fpow(int x, int k) {
  int res = 1;
  for (; k; k >>= 1, x = 1ll * x * x % mod)
    if (k & 1) res = 1ll * res * x % mod;
  return res;
}
int n, k, m, ans, h[N], fac[N], inv[N];
inline int combn(int n, int m) {
  return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; ++i) h[i] = read();
  for (int i = 1; i <= n; ++i) m += (h[i] != h[i % n + 1]);
  fac[0] = inv[0] = inv[1] = 1;
  for (int i = 1; i <= m; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
  for (int i = 2; i <= m; ++i)
    inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
  for (int i = 1; i <= m; ++i) inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
  for (int i = 1; i <= m; ++i) {
    int tmp = 1ll * (fpow(2, i) + mod - (i & 1 ? 0 : combn(i, i / 2))) % mod *
              combn(m, i) % mod;
    ans = (ans +
           1ll * tmp * (mod + 1) / 2 % mod * fpow(std::max(k - 2, 0), m - i)) %
          mod;
  }
  return printf("%lld\n", 1ll * fpow(k, n - m) * ans % mod), 0;
}
