#include <bits/stdc++.h>
using namespace std;
long long Pow(long long a, int b) {
  long long ans = 1;
  while (b) {
    if (b & 1) (ans *= a) %= 998244353;
    (a *= a) %= 998244353, b >>= 1;
  }
  return ans;
}
int fac[200005], inv[200005];
long long C(int n, int m) {
  return 1ll * fac[n] * inv[m] % 998244353 * inv[n - m] % 998244353;
}
int main() {
  int n, k, fi, pre, x, num = 0;
  scanf("%d%d%d", &n, &k, &fi), pre = fi;
  if (k == 1) return puts("0"), 0;
  for (int i = 1; i < n; i++, pre = x) {
    scanf("%d", &x);
    if (x != pre) num++;
  }
  if (fi != pre) num++;
  fac[0] = 1;
  for (int i = 1; i <= num; i++) fac[i] = 1ll * fac[i - 1] * i % 998244353;
  inv[num] = Pow(fac[num], 998244353 - 2);
  for (int i = num - 1; ~i; i--)
    inv[i] = 1ll * inv[i + 1] * (i + 1) % 998244353;
  long long ans = Pow(k, num) - Pow(k - 2, num);
  for (int i = 1; i <= num / 2; i++)
    (ans -= C(num, i) * C(num - i, i) % 998244353 * Pow(k - 2, num - 2 * i) %
            998244353) %= 998244353;
  ans = (ans + 998244353) * Pow(2, 998244353 - 2) % 998244353 *
        Pow(k, n - num) % 998244353;
  printf("%lld", ans);
  return 0;
}
