#include <bits/stdc++.h>
using namespace std;
const long long inf = 1 << 30;
const long long Inf = 1ll << 60ll;
namespace io {
char buf[(1 << 23)], *p1 = buf, *p2 = buf, c;
long long f;
template <typename T>
T read() {
  T x = 0;
  f = 0;
  c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, (1 << 23), stdin), p1 == p2)
           ? EOF
           : *p1++);
  while (!isdigit(c))
    (c == '-') && (f = 1),
        c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, (1 << 23), stdin),
                          p1 == p2)
                 ? EOF
                 : *p1++);
  while (isdigit(c))
    x = x * 10 + (c & 15),
    c = (p1 == p2 &&
                 (p2 = (p1 = buf) + fread(buf, 1, (1 << 23), stdin), p1 == p2)
             ? EOF
             : *p1++);
  return f ? -x : x;
}
}  // namespace io
const long long N = 200005, mod = 998244353;
long long n, k, fac[N], a[N], inv[N];
long long qpow(long long b, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1) res = res * b % mod;
    b = b * b % mod;
    p >>= 1ll;
  }
  return res;
}
long long C(long long x, long long y) {
  return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
signed main() {
  scanf("%lld%lld", &n, &k);
  long long cnt = 0;
  fac[0] = inv[0] = 1;
  for (long long i = 1; i <= n; ++i)
    fac[i] = fac[i - 1] * i % mod, inv[i] = qpow(fac[i], mod - 2);
  for (long long i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  for (long long i = 1; i < n; ++i)
    if (a[i] != a[i + 1]) cnt++;
  if (a[1] != a[n]) cnt++;
  long long ans = qpow(k, n), v = 0;
  for (long long i = 0; i <= cnt / 2; ++i)
    (v += qpow(k - 2, cnt - i * 2) * C(cnt, i) % mod * C(cnt - i, i)) %= mod;
  v = v * qpow(k, n - cnt) % mod;
  printf("%lld\n", (ans - v + mod) * (mod / 2 + 1) % mod);
  return 0;
}
