#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long pw(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y % 2 == 1) ans = ans * x % mod;
    x = x * x % mod;
    y /= 2;
  }
  return ans;
}
long long f1[200005], f2[200005];
long long C(int x, int y) {
  return y > x ? 0 : f1[x] * 1ll * f2[y] % mod * f2[x - y] % mod;
}
long long p2[200005];
int a[200005];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  f1[0] = f2[0] = p2[0] = 1;
  for (int i = 1; i <= n; i++) {
    f1[i] = f1[i - 1] * 1ll * i % mod;
    f2[i] = pw(f1[i], mod - 2);
    p2[i] = p2[i - 1] * 1ll * 2 % mod;
  }
  if (k == 1) {
    printf("0\n");
    return 0;
  }
  long long sum = 1;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == a[(i + 1) % n])
      sum = sum * 1ll * k % mod;
    else
      cnt++;
  }
  long long inv = pw(2, mod - 2);
  long long ans = 0;
  for (int i = 0; i <= cnt - 1; i++) {
    long long res = sum * 1ll * C(cnt, i) % mod * pw(k - 2, i) % mod;
    if ((cnt - i) % 2 == 1) {
      res = res * 1ll * p2[cnt - i - 1] % mod;
    } else {
      res =
          res * 1ll *
          ((p2[cnt - i] - C(cnt - i, (cnt - i) / 2) + mod) % mod * inv % mod) %
          mod;
    }
    ans = (ans + res) % mod;
  }
  printf("%lld\n", ans);
}
