#include <bits/stdc++.h>
using namespace std;
int n, k, a[((int)2e5 + 10)], cnt;
long long p = 1, f[((int)2e5 + 10)], o[((int)2e5 + 10)], c[((int)2e5 + 10)];
long long fpow(long long x, long long y) {
  if (y == 0) return 1;
  long long res = fpow(x, y / 2);
  res = (res * res) % (998244353);
  if (y & 1) res = (res * x) % (998244353);
  return res;
}
long long mi(long long x) { return fpow(x, (998244353) - 2); }
int main() {
  f[0] = f[1] = 1;
  o[1] = 1;
  long long m2 = mi(2);
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  if (k == 1) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == a[(i + 1) % n])
      p = (p * k) % (998244353);
    else
      cnt++;
  }
  for (int i = 2; i <= n; i++) {
    f[i] = (f[i - 1] * i) % (998244353);
    o[i] = (o[i - 1] * 2) % (998244353);
  }
  for (int i = 2; i <= n; i += 2) {
    long long fp = mi(f[i / 2]);
    fp = (((fp * fp) % (998244353)) * m2) % (998244353);
    long long ffp = (f[i] * fp) % (998244353);
    o[i] = ((o[i] - ffp % (998244353)) + (998244353)) % (998244353);
  }
  c[0] = c[cnt] = 1;
  for (int i = 1; i <= cnt / 2; i++) {
    c[i] = c[cnt - i] =
        (fpow((f[i] * f[cnt - i]) % (998244353), (998244353) - 2) * f[cnt]) %
        (998244353);
  }
  if (k == 2) {
    printf("%lld\n", (o[cnt] * p) % (998244353));
    return 0;
  }
  long long ans = 0, both = 1, bb = 0;
  for (int i = 0; i < cnt; i++) {
    bb = both * c[i];
    bb %= (998244353);
    bb = (bb * p) % (998244353);
    ans += bb * o[cnt - i];
    ans %= (998244353);
    both *= (k - 2);
    both %= (998244353);
  }
  printf("%lld\n", ans);
  return 0;
}
