#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 200005, mod = 998244353;
long long fac[N], ni[N], fk[N], ans;
int h[N];
long long ksm(long long a, int b) {
  int ans = 1;
  for (; b; b >>= 1) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
  }
  return ans;
}
int main() {
  int n = read(), k = read(), m = 0;
  for (int i = (int)(0); i <= (int)(n - 1); i++) h[i] = read();
  for (int i = (int)(0); i <= (int)(n - 1); i++) m += h[i] != h[(i + 1) % n];
  for (int i = (int)(fk[0] = fac[0] = 1); i <= (int)(m); i++) {
    fk[i] = fk[i - 1] * (k - 2) % mod;
    fac[i] = fac[i - 1] * i % mod;
  }
  ni[m] = ksm(fac[m], mod - 2);
  for (int i = (int)(m); i >= (int)(1); i--) ni[i - 1] = ni[i] * i % mod;
  for (int i = (int)(0); i <= (int)(m); i++)
    if ((m - i) % 2 == 0) {
      int t = (m - i) / 2;
      ans = (ans + fac[m] * ni[i] % mod * ni[t] % mod * ni[t] % mod * fk[i]) %
            mod;
    }
  ans = (ksm(k, m) - ans + mod) % mod * (mod + 1) / 2 % mod;
  for (int i = (int)(1); i <= (int)(n - m); i++) ans = ans * k % mod;
  cout << ans << endl;
}
