#include <bits/stdc++.h>
using namespace std;
int N, n, d, h[200200];
long long k, fac[200200] = {1LL}, p2[200200] = {1LL};
inline void init() {
  fac[0] = 1LL;
  for (int i = (1); i < (200200); i++) fac[i] = (fac[i - 1] * i) % 998244353LL;
  p2[0] = 1LL;
  for (int i = (1); i < (200200); i++) p2[i] = (p2[i - 1] * 2) % 998244353LL;
}
inline long long pow_md(long long a, long long p) {
  long long rem = 1LL;
  while (p) {
    if (p % 2) rem = (rem * a) % 998244353LL;
    a = (a * a) % 998244353LL;
    p >>= 1;
  }
  return rem;
}
inline long long inv(long long a, long long md = 998244353LL) {
  return pow_md(a, md - 2);
}
inline long long nCr(long long n, long long r) {
  if (r < 0 || r > n) return 0;
  return ((fac[n] * inv(fac[r])) % 998244353LL * inv(fac[n - r])) % 998244353LL;
}
int main() {
  init();
  cin >> N >> k;
  for (int i = (1); i < (N + 1); i++) cin >> h[i];
  n = N;
  for (int i = (1); i < (N + 1); i++)
    if (h[i] == h[i % N + 1]) {
      n--;
    }
  d = N - n;
  long long ans = 0LL;
  if (n <= 1)
    ans = n;
  else {
    for (int s = (0); s < (n); s++) {
      long long f_s =
          ((pow_md(k, d) * pow_md(k - 2, s)) % 998244353LL * nCr(n, s)) %
          998244353LL;
      long long a_s = p2[n - s];
      if ((n - s) % 2 == 0) a_s -= nCr(n - s, (n - s) / 2);
      a_s = (a_s + 998244353LL) % 998244353LL;
      a_s = (a_s * inv(2)) % 998244353LL;
      ans = (ans + (f_s * a_s) % 998244353LL) % 998244353LL;
    }
  }
  cout << ans << '\n';
}
