#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
const int seed = 233;
const double PI = acos(-1.0);
const double eps = 1e-7;
const int inf = 0x3f3f3f3f;
const int max_n = 200005;
namespace {
inline int Add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
inline int Sub(int x, int y) { return (x -= y) < 0 ? x + mod : x; }
inline int Mul(int x, int y) { return 1ll * x * y % mod; }
inline int Pow(int x, int y = mod - 2) {
  if (y == 0) return 1;
  int res = 1;
  while (y) {
    if (y & 1) res = 1ll * res * x % mod;
    x = 1ll * x * x % mod;
    y >>= 1;
  }
  return res;
}
}  // namespace
long long f[max_n * 2];
long long inv[max_n * 2];
long long invn[max_n * 2];
long long C(int n, int m) {
  if (n < m || m < 0) return 0;
  return f[n] * inv[n - m] % mod * inv[m] % mod;
}
long long S(int n, int m) {
  if (n == 0 && m == 0) return 1;
  return C(m + n - 1, n - 1);
}
long long solve(int n, int s, int m) {
  long long res = S(n, s);
  for (int i = 1; i <= n; i++) {
    if (i & 1)
      res = Sub(res, Mul(C(n, i), S(n, s - m * i)));
    else
      res = Add(res, Mul(C(n, i), S(n, s - m * i)));
  }
  return res;
}
void init(int n) {
  f[0] = 1;
  for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % mod;
  inv[n] = Pow(f[n]);
  for (int i = n - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
  invn[1] = 1;
  for (int i = 2; i <= n; i++) invn[i] = invn[mod % i] * (mod - mod / i) % mod;
}
long long Lucas(long long n, long long m) {
  if (n < m || m < 0) return 0;
  if (m == 0) return 1;
  return C(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod;
}
int n, k;
int h[max_n];
long long inv2 = Pow(2, mod - 2);
int main() {
  scanf("%d%d", &n, &k);
  init(max_n);
  for (int i = 1; i <= n; i++) scanf("%d", h + i);
  if (n == 1 || k == 1)
    puts("0");
  else {
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (h[i] != h[i % n + 1]) cnt++;
    }
    int x = n - cnt;
    long long ans = 0;
    for (int i = 1; i <= cnt; i++) {
      long long tmp = Pow(k - 2, cnt - i) * C(cnt, i) % mod;
      if (i & 1)
        tmp = tmp * Pow(2, i - 1) % mod;
      else {
        tmp *= (Pow(2, i) + mod - C(i, i / 2)) * 1ll * inv2 % mod;
        tmp %= mod;
      }
      ans += tmp, ans %= mod;
    }
    ans *= Pow(k, x), ans %= mod;
    printf("%lld\n", ans);
  }
  return 0;
}
