#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 8;
const long long mod = 998244353;
long long inv[N], jie[N], k2[N];
int n, k, a[N];
long long quick(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
void pre() {
  jie[0] = 1;
  inv[0] = inv[1] = 1, k2[0] = 1;
  for (int i = (2); i < (N); ++i) {
    int k = mod / i, r = mod % i;
    inv[i] = -k * inv[r] % mod;
    inv[i] += mod;
  }
  for (int i = (1); i < (N); ++i)
    jie[i] = i * jie[i - 1] % mod, inv[i] = inv[i] * inv[i - 1] % mod,
    k2[i] = (k - 2) * k2[i - 1] % mod;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = (0); i < (n); ++i) scanf("%d", &a[i]);
  int cnt = 0;
  for (int i = (0); i < (n); ++i)
    if (a[i] ^ a[(i + 1) % n]) ++cnt;
  pre();
  long long ans = quick(k, cnt);
  for (int i = 0; i <= cnt; i += 2) {
    ans = (ans - jie[cnt] * inv[i / 2] % mod * inv[i / 2] % mod * inv[cnt - i] %
                     mod * k2[cnt - i] % mod) %
          mod;
    if (ans < 0) ans += mod;
  }
  if (ans & 1)
    ans = (ans + mod) / 2;
  else
    ans >>= 1;
  ans = ans * quick(k, n - cnt) % mod;
  printf("%lld", ans);
}
