#include <bits/stdc++.h>
using namespace std;
int i, j, m, n, x[200005];
long long k, mod, cnt, ans, fac[200005], facinv[200005], power[200005];
long long getinv(long long a, long long p) {
  if (a == 1) return 1;
  long long k = a - getinv(p % a, a);
  return (k * p + 1) / a;
}
long long comb(long long a, long long b) {
  return fac[a] * facinv[b] % mod * facinv[a - b] % mod;
}
int main() {
  cnt = 0;
  ans = 1;
  mod = 998244353;
  scanf("%d%lld", &n, &k);
  fac[0] = facinv[0] = 1;
  for (i = 1; i <= n; i++) {
    fac[i] = fac[i - 1] * i % mod;
    facinv[i] = facinv[i - 1] * getinv(i, mod) % mod;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
  }
  for (i = 1; i <= n; i++) {
    if (x[i] != x[i % n + 1]) cnt++;
  }
  for (i = 1; i <= n - cnt; i++) {
    ans = ans * k % mod;
  }
  long long temp = 1;
  for (i = 1; i <= cnt; i++) {
    temp = temp * k % mod;
  }
  power[0] = 1;
  for (i = 1; i <= n; i++) {
    power[i] = power[i - 1] * (k - 2) % mod;
  }
  for (i = 0; i <= cnt / 2; i++) {
    temp = (temp + mod -
            comb(cnt, i) % mod * comb(cnt - i, i) % mod * power[cnt - i * 2] %
                mod) %
           mod;
  }
  temp = temp * facinv[2] % mod;
  ans = ans * temp % mod;
  printf("%lld\n", ans);
  return 0;
}
