#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
const int mo = 998244353;
int fac[N], inv[N], P[N];
int n, k, m, h[N], ans;
int power(int x, int y) {
  int s = 1;
  for (; y; y /= 2, x = 1ll * x * x % mo)
    if (y & 1) s = 1ll * s * x % mo;
  return s;
}
void init() {
  fac[0] = inv[0] = inv[1] = P[0] = 1;
  for (int i = (int)(2); i <= (int)(N - 1); i++)
    inv[i] = 1ll * inv[mo % i] * (mo - mo / i) % mo;
  for (int i = (int)(1); i <= (int)(N - 1); i++)
    fac[i] = 1ll * fac[i - 1] * i % mo;
  for (int i = (int)(1); i <= (int)(N - 1); i++)
    inv[i] = 1ll * inv[i - 1] * inv[i] % mo;
  for (int i = (int)(1); i <= (int)(N - 1); i++) P[i] = 2ll * P[i - 1] % mo;
}
int C(int x, int y) {
  if (y < 0 || x < 0 || y > x) return 0;
  return 1ll * fac[x] * inv[y] % mo * inv[x - y] % mo;
}
int main() {
  init();
  scanf("%d%d", &n, &k);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &h[i]);
  h[n + 1] = h[1];
  for (int i = (int)(1); i <= (int)(n); i++)
    if (h[i] != h[i + 1]) m++;
  for (int i = (int)(0); i <= (int)(m); i++) {
    int S = power(2, i);
    if (i % 2 == 0) S = (S + mo - C(i, i / 2)) % mo;
    ans = (ans + 1ll * S * C(m, i) % mo * power(max(0, k - 2), m - i)) % mo;
  }
  ans = 1ll * ans * power(k, n - m) % mo;
  ans = 1ll * ans * (mo + 1) / 2 % mo;
  printf("%d\n", ans);
}
