#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf;
inline int read() {
  int x = 0, sign = 0;
  char s = getchar();
  while (!isdigit(s)) sign |= s == '-', s = getchar();
  while (isdigit(s)) x = (x << 1) + (x << 3) + (s - '0'), s = getchar();
  return sign ? -x : x;
}
void print(int x) {
  if (x > 9) print(x / 10);
  (*O++ = x % 10 + '0');
}
const int N = 2e5 + 5;
const long long mod = 998244353;
long long ksm(long long a, long long b) {
  long long s = 1, m = a;
  while (b) {
    if (b & 1) s = s * m % mod;
    b >>= 1, m = m * m % mod;
  }
  return s;
}
long long inv(long long x) { return ksm(x, mod - 2); }
long long n, k, ans, tmp, v, a[N], f[N], vf[N];
long long C(long long m, long long n) {
  return f[n] * vf[m] % mod * vf[n - m] % mod;
}
int main() {
  cin >> n >> k, f[0] = vf[0] = 1;
  for (int i = 1; i <= n; i++)
    cin >> a[i], f[i] = f[i - 1] * i % mod, vf[i] = inv(f[i]);
  for (int i = 1; i <= n; i++) v += a[i] != a[i == 1 ? n : i - 1];
  tmp = ksm(k, n - v);
  for (int i = 0; i <= v; i++)
    ans = (ans + ksm(k - 2, v - i) * C(v - i, v) % mod *
                     (ksm(2, i) - (i & 1 ? 0 : C(i / 2, i))) % mod * inv(2)) %
          mod;
  cout << ((ans + mod) % mod) * tmp % mod << endl;
  return 0;
}
