#include <bits/stdc++.h>
int fac[201000], inv[201000], a[201000];
int C(int a, int b) {
  return 1ll * fac[a] * inv[b] % 998244353 * inv[a - b] % 998244353;
}
int qpow(int x, int p) {
  int ans = 1;
  while (p) {
    if (p & 1) ans = 1ll * ans * x % 998244353;
    x = 1ll * x * x % 998244353;
    p >>= 1;
  }
  return ans;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (k == 1) return 0 * puts("0");
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  a[n + 1] = a[1];
  fac[0] = inv[1] = inv[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % 998244353;
  for (int i = 2; i <= n; i++)
    inv[i] = 1ll * (998244353 - 998244353 / i) * inv[998244353 % i] % 998244353;
  for (int i = 1; i <= n; i++) inv[i] = 1ll * inv[i - 1] * inv[i] % 998244353;
  int cnt = 0, m = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == a[i + 1])
      cnt++;
    else
      m++;
  }
  int ans = 0;
  for (int i = 0; i * 2 <= m; i++) {
    ans = (ans + 1ll * C(m, i) * C(m - i, i) % 998244353 *
                     qpow(k - 2, m - i - i) % 998244353) %
          998244353;
  }
  ans =
      1ll * (qpow(k, m) - ans + 998244353) * qpow(2, 998244353 - 2) % 998244353;
  printf("%lld\n", 1ll * ans * qpow(k, cnt) % 998244353);
}
