#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010, P = 998244353;
int n, k, num, ans, h[maxn], fact[maxn], inv[maxn];
int qp(int x, int y) {
  int z = 1;
  for (; y; y >>= 1, x = 1LL * x * x % P) {
    if (y & 1) z = 1LL * z * x % P;
  }
  return z;
}
int C(int x, int y) { return 1LL * fact[x] * inv[y] % P * inv[x - y] % P; }
int main() {
  scanf("%d %d", &n, &k);
  for (int i = fact[0] = inv[0] = 1; i <= n; i++) {
    fact[i] = 1LL * i * fact[i - 1] % P;
    inv[i] = qp(fact[i], P - 2);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &h[i]);
  }
  for (int i = 0; i < n; i++) {
    if (h[i] ^ h[(i + 1) % n]) num++;
  }
  for (int i = 0; i + i <= num; i++) {
    ans = (ans + 1LL * C(num, i) * C(num - i, i) % P * qp(k - 2, num - i - i)) %
          P;
  }
  ans = 1LL * qp(k, n - num) * ans % P;
  printf("%d\n", 1LL * qp(2, P - 2) * (qp(k, n) - ans + P) % P);
  return 0;
}
