#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL MOD = 998244353;
void mul(LL& a, LL b) { a = ((a % MOD) * (b % MOD)) % MOD; }
void add(LL& a, LL b) { a = ((a % MOD) + (b % MOD) + MOD) % MOD; }
LL modpow(LL a, int n) {
  LL res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
  }
  return res;
}
const int N = 2e5 + 1;
LL fact[N], invf[N];
void prec() {
  fact[0] = invf[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % MOD;
    invf[i] = modpow(fact[i], MOD - 2);
  }
}
LL choose(int n, int r) {
  return (fact[n] * ((invf[n - r] * invf[r]) % MOD)) % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  prec();
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[n] = a[0];
  int diff = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != a[i + 1]) {
      diff++;
    }
  }
  LL ans = 0;
  for (int nz = 1; nz <= diff; nz++) {
    LL curr = modpow(2, nz);
    if (nz % 2 == 0) {
      add(curr, -choose(nz, nz / 2));
    }
    mul(curr, choose(diff, nz));
    mul(curr, modpow(k - 2, diff - nz));
    add(ans, curr);
  }
  mul(ans, modpow(2, MOD - 2));
  mul(ans, modpow(k, n - diff));
  cout << ans << endl;
  return 0;
}
