#include <bits/stdc++.h>
using namespace std;
const int g = 3;
int add(int a, int b) {
  a += b;
  return a >= 998244353 ? a - 998244353 : a;
}
void Inc(int &a, int b) { a = add(a, b); }
int ksm(int a, int b) {
  int s = 1;
  for (; b; b >>= 1, a = 1ll * a * a % 998244353)
    if (b & 1) s = 1ll * s * a % 998244353;
  return s;
}
int n, k, h[200005], fac[200005], inv[200005], p2[200005], c1, c2;
int C(int n, int m) {
  return 1ll * fac[n] * inv[m] % 998244353 * inv[n - m] % 998244353;
}
int A[200005], B[200005];
int main() {
  fac[0] = 1, p2[0] = 1;
  ;
  for (int i = 1; i < 200005; i++)
    fac[i] = 1ll * fac[i - 1] * i % 998244353,
    p2[i] = add(p2[i - 1], p2[i - 1]);
  inv[200005 - 1] = ksm(fac[200005 - 1], 998244353 - 2);
  for (int i = 200005 - 2; i >= 0; i--)
    inv[i] = 1ll * inv[i + 1] * (i + 1) % 998244353;
  scanf("%d%d", &n, &k);
  if (k == 1) return (puts("0") & 0);
  for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
  for (int i = 1; i < n; i++)
    if (h[i] == h[i + 1])
      c2++;
    else
      c1++;
  if (h[1] == h[n])
    c2++;
  else
    c1++;
  int ans = 0;
  for (int i = 1; i <= c1; i++) {
    if (i & 1)
      ans = add(ans, 1ll * C(c1, i) * p2[i - 1] % 998244353 *
                         ksm(k - 2, c1 - i) % 998244353);
    else
      ans = add(ans, 1ll * C(c1, i) * add(p2[i], 998244353 - C(i, i / 2)) %
                         998244353 * inv[2] % 998244353 * ksm(k - 2, c1 - i) %
                         998244353);
  }
  printf("%d\n", 1ll * ans * ksm(k, c2) % 998244353);
  return 0;
}
