#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long mod = 998244353;
long long h[200005];
long long gt[200005];
long long binpow(long long a, long long b) {
  long long ans = 1;
  long long cac = a % mod;
  while (b) {
    if (b & 1) {
      ans = (ans * cac) % mod;
    }
    cac = (cac * cac) % mod;
    b /= 2;
  }
  return ans;
}
long long C(long long a, long long b) {
  return (gt[b] * binpow((gt[a] * gt[b - a]) % mod, mod - 2)) % mod;
}
signed main() {
  gt[0] = 1;
  for (long long i = 1; i <= 200000; i++) {
    gt[i] = gt[i - 1] * i;
    gt[i] %= mod;
  }
  cin >> n >> k;
  long long nhan = 1, tot = 1;
  for (long long i = 0; i < n; i++) {
    cin >> h[i];
  }
  long long co = n;
  for (long long i = 0; i < n; i++) {
    if (h[i] == h[(i + 1) % n]) {
      co--;
      nhan = (nhan * k) % mod;
    }
  }
  tot = binpow(k, co);
  for (long long i = 0; i <= co / 2; i++) {
    tot =
        (tot -
         ((C(i, co) * C(i, co - i)) % mod * (binpow(k - 2, co - 2 * i))) % mod +
         mod) %
        mod;
  }
  tot = (tot * binpow(2, mod - 2)) % mod;
  tot = (tot * nhan) % mod;
  cout << tot;
}
