#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long su = 0, f = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) su = su * 10 + c - '0';
  return su * f;
}
inline void wr(long long x) {
  if (x < 0)
    putchar('-'), wr(-x);
  else {
    if (x >= 10) wr(x / 10);
    putchar(x % 10 + '0');
  }
}
inline void wri(long long x) {
  wr(x);
  putchar(' ');
}
inline void wrn(long long x) {
  wr(x);
  putchar('\n');
}
inline void wrn(long long x, long long y) {
  wri(x);
  wrn(y);
}
inline void wrn(long long x, long long y, long long z) {
  wri(x);
  wrn(y, z);
}
int n, m, ans, k, a[600055];
int Next[600055 * 2], head[600055], to[600055 * 2], nedge, g[600055][4];
void add(int a, int b) {
  Next[++nedge] = head[a];
  head[a] = nedge;
  to[nedge] = b;
}
void add_ne(int a, int b) {
  add(a, b);
  add(b, a);
}
inline void ad(int &x, int k) {
  x += k;
  x -= (x >= 998244353) ? 998244353 : 0;
  x += (x < 0) ? 998244353 : 0;
}
int ksm(long long x, int k) {
  int su = 1;
  for (; k; k >>= 1, x = x * x % 998244353)
    if (k & 1) su = su * x % 998244353;
  return su;
}
int fac[600055], inv[600055];
int C(int n, int m) {
  return (n < m || m < 0)
             ? 0
             : 1ll * fac[n] * inv[m] % 998244353 * inv[n - m] % 998244353;
}
void init_c(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % 998244353;
  inv[n] = ksm(fac[n], 998244353 - 2);
  for (int i = n - 1; i >= 0; i--)
    inv[i] = 1ll * inv[i + 1] * (i + 1) % 998244353;
}
signed main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  a[n + 1] = a[1];
  ans = 1;
  int su = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] == a[i + 1])
      ans = 1ll * ans * k % 998244353;
    else
      su++;
  int s1 = ksm(k, su);
  init_c(n);
  int t = 1;
  for (int i = 0; i <= su; i++) {
    if ((su - i) % 2 == 0)
      ad(s1,
         -1ll * t * C(su - i, (su - i) / 2) % 998244353 * C(su, i) % 998244353);
    t = 1ll * t * (k - 2) % 998244353;
  }
  s1 = 1ll * s1 * ksm(2, 998244353 - 2) % 998244353;
  wrn(1ll * s1 * ans % 998244353);
  return 0;
}
