#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
const int mod = 998244353;
int fac[N + 5], inv[N + 5];
int sum[N + 5];
const int inv2 = 499122177;
int n, K;
int h[N + 5];
int Pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b % 2) ans = (1ll * ans * a) % mod;
    a = (1ll * a * a) % mod;
    b /= 2;
  }
  return ans;
}
int C(int a, int b) { return 1ll * fac[a] * inv[a - b] % mod * inv[b] % mod; }
int Calc(int same, int dif) {
  int ans = 0;
  for (int i = 0; i <= dif; i++) {
    int sum = 0;
    if ((dif - i) % 2 == 0)
      sum = 1ll * (Pow(2, dif - i) - C(dif - i, (dif - i) / 2)) * inv2 % mod;
    else
      sum = 1ll * Pow(2, dif - i) * inv2 % mod;
    ans = (ans + 1ll * sum * Pow(K - 2, i) % mod * C(dif, dif - i)) % mod;
  }
  ans = 1ll * ans * Pow(K, same) % mod;
  return ans;
}
void Init() {
  fac[0] = 1;
  inv[0] = 1;
  for (int i = 1; i <= N; i++) {
    fac[i] = 1ll * fac[i - 1] * i % mod;
    inv[i] = Pow(fac[i], mod - 2);
  }
}
int main() {
  Init();
  scanf("%d %d", &n, &K);
  for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
  if (K == 1) {
    printf("0");
    return 0;
  }
  int num1 = 0, num2 = 0;
  for (int i = 1; i <= n; i++) {
    int next = i + 1;
    if (i == n) next = 1;
    if (h[i] == h[next])
      num1++;
    else
      num2++;
  }
  printf("%d", (Calc(num1, num2) + mod) % mod);
}
