#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <class t>
inline void write(t x) {
  if (x < 0) {
    putchar('-'), write(-x);
  } else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
const long long mod = 998244353;
const long long N = 2e5 + 5;
long long n, k, f[N], inv[N], ans, a[N], b[N], m;
long long fpow(long long x, long long y, long long mod) {
  long long res = 1;
  for (; y; y >>= 1, mod ? (x *= x) %= mod : x *= x)
    if (y & 1) mod ? (res *= x) %= mod : res *= x;
  return res;
}
long long C(long long n, long long m) {
  return f[n] * inv[m] % mod * inv[n - m] % mod;
}
signed main() {
  read(n);
  read(k);
  for (long long i = 1; i <= n; i++) read(a[i]), b[i % n + 1] = a[i];
  if (k == 1) {
    write(0);
    return 0;
  }
  for (long long i = 1; i <= n; i++)
    if (a[i] ^ b[i]) m++;
  f[0] = 1;
  for (long long i = 1; i <= m; i++) f[i] = f[i - 1] * i % mod;
  inv[m] = fpow(f[m], mod - 2, mod);
  for (long long i = m - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
  for (long long i = 0; i * 2 <= m; i++)
    (ans += C(m, i) * C(m - i, i) % mod * fpow(k - 2, m - i * 2, mod) % mod) %=
        mod;
  (ans *= fpow(k, n - m, mod)) %= mod;
  write((fpow(k, n, mod) - ans + mod) % mod * fpow(2, mod - 2, mod) % mod);
}
