#include <bits/stdc++.h>
template <class t>
inline void read(t &s) {
  s = 0;
  register long long f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  long long buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(std::string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(std::string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(std::string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool ckmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool ckmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline long long lowbit(long long x) { return x & (-x); }
const long long MaxN = 2e5 + 50;
const long long p = 998244353;
inline long long fpow(long long a, long long b) {
  register long long res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1) res = res * a % p;
  return res;
}
struct CC {
  long long f[MaxN], inv[MaxN];
  CC() {
    f[0] = 1;
    for (long long i = 1; i < MaxN; ++i) f[i] = f[i - 1] * i % p;
    inv[MaxN - 1] = fpow(f[MaxN - 1], p - 2);
    for (long long i = MaxN - 2; ~i; --i) inv[i] = inv[i + 1] * (i + 1) % p;
  }
  inline long long operator()(const long long &n, const long long &m) const {
    if (n < m) return 0;
    return f[n] * inv[m] % p * inv[n - m] % p;
  }
} C;
long long a[MaxN], n, k;
inline long long nxt(long long x) { return x == n ? 1 : x + 1; }
signed main(void) {
  read(n, k);
  for (long long i = 1; i <= n; ++i) read(a[i]);
  register long long m = 0;
  for (long long i = 1; i <= n; ++i)
    if (a[i] != a[nxt(i)]) ++m;
  register long long ans = 0;
  for (long long i = 0; i <= m / 2; ++i)
    (ans += C(m, i) * C(m - i, i) % p * fpow(k - 2, m - 2 * i) % p) %= p;
  ans = (fpow(k, m) - ans + p) % p;
  write(ans * fpow(2, p - 2) % p * fpow(k, n - m) % p), std::puts("");
  return 0;
}
