#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return w == 1 ? x : -x;
}
inline long long qpow(int a, int b) {
  long long ans = 1, base = a;
  while (b) {
    if (b & 1) ans = (ans * base) % 998244353;
    b >>= 1;
    base = (base * base) % 998244353;
  }
  return ans;
}
long long fac[200005], inv[200005], n, k, a[200005], cnt, z;
inline long long C(int n, int m) {
  return (((fac[n] * inv[m]) % 998244353) * inv[n - m]) % 998244353;
}
int main() {
  n = read();
  k = read();
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % 998244353;
  for (int i = 0; i <= n; i++) inv[i] = qpow(fac[i], 998244353 - 2);
  z = qpow(2, 998244353 - 2);
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 2; i <= n; i++)
    if (a[i] != a[i - 1]) cnt++;
  if (a[1] != a[n]) cnt++;
  long long ans = 0, tmp = qpow(k, n);
  for (int i = 0; i * 2 <= cnt; i++) {
    ans = (ans + (C(cnt, i) * C(cnt - i, i) % 998244353) *
                     qpow((k - 2), cnt - 2 * i)) %
          998244353;
  }
  ans = (ans * qpow(k, n - cnt)) % 998244353;
  cout << ((tmp - ans + 998244353) % 998244353 * z) % 998244353;
  return 0;
}
