#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 998244353;
int fac[N];
int pw(int x, int y) {
  int ret = 1;
  for (; y; y /= 2) {
    if (y & 1) ret = 1ll * ret * x % mod;
    x = 1ll * x * x % mod;
  }
  return ret;
}
int c(int x, int y) {
  return 1ll * fac[y] * pw(fac[x], mod - 2) % mod * pw(fac[y - x], mod - 2) %
         mod;
}
int h[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  fac[0] = 1;
  for (int i = 1; i < N; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
  int n, k;
  cin >> n >> k;
  if (n == 1) return cout << 0, 0;
  int t = 0;
  for (int i = 0; i < n; i++) cin >> h[i];
  for (int i = 0; i < n; i++) t += (h[i] != h[(i + 1) % n]);
  int ans = pw(k, n);
  for (int i = 0; i <= t / 2; i++) {
    int bad = 1ll * c(i, t) * c(i, t - i) % mod * pw(k - 2, t - 2 * i) % mod *
              pw(k, n - t) % mod;
    ans -= bad;
    if (ans < 0) ans += mod;
  }
  cout << 1ll * ans * pw(2, mod - 2) % mod;
  return 0;
}
