#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 14, mod = 998244353;
int n, k, a[maxn], po[maxn], fac[maxn], rfac[maxn];
int ch(int n, int r) {
  return (long long)fac[n] * rfac[r] % mod * rfac[n - r] % mod;
}
int rev(int a) {
  int ans = 1;
  for (int b = mod - 2; b; b >>= 1, a = (long long)a * a % mod)
    if (b & 1) ans = (long long)ans * a % mod;
  return ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  fac[0] = rfac[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fac[i] = (long long)fac[i - 1] * i % mod;
    rfac[i] = rev(fac[i]);
  }
  po[0] = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    po[i + 1] = po[i] * 2 % mod;
  }
  int c = 0, ans = 0, zc = 1;
  for (int i = 0; i < n; i++)
    if (a[i] == a[(i + 1) % n]) zc = (long long)zc * k % mod, c++;
  int r2 = rev(2);
  for (int z = c; z < n; z++) {
    int tw = po[n - z - 1];
    if ((n - z) % 2 == 0)
      tw = (tw - (long long)ch(n - z, (n - z) / 2) * r2 % mod + mod) % mod;
    ans = (ans + (long long)zc * ch(n - c, z - c) % mod * tw) % mod;
    zc = (long long)zc * (k - 2) % mod;
  }
  cout << ans << '\n';
}
