#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 10, mod = 998244353;
int a[maxN], fact[maxN], rev[maxN];
int p[maxN], q[maxN];
int power(int a, int b) {
  if (b == 0) return 1;
  long long res = power(a, b / 2);
  res *= res, res %= mod;
  if (b & 1) res *= a, res %= mod;
  return res;
}
int comb(int n, int k) {
  if (k < 0 || k > n) return 0;
  long long res = fact[n];
  res *= rev[k];
  res %= mod;
  res *= rev[n - k], res %= mod;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  if (k == 1) return cout << 0 << endl, 0;
  fact[0] = 1;
  for (int i = 1; i < maxN; i++) fact[i] = 1LL * fact[i - 1] * i % mod;
  rev[maxN - 1] = power(fact[maxN - 1], mod - 2);
  for (int i = maxN - 2; i >= 0; i--) rev[i] = 1LL * rev[i + 1] * (i + 1) % mod;
  int b = 0;
  long long ans = 0, w = 1;
  for (int i = 0; i < n; i++)
    if (a[i] == a[(i + 1) % n]) {
      b++;
      w = 1LL * w * k % mod;
    }
  p[0] = 1;
  for (int i = 1; i < maxN; i++) p[i] = 1LL * p[i - 1] * (k - 2) % mod;
  q[0] = 1;
  for (int i = 1; i < maxN; i++) q[i] = 1LL * q[i - 1] * 2 % mod;
  n -= b;
  for (int f = 1; f <= n; f++) {
    long long ways = comb(n, f);
    ways *= p[n - f];
    ways %= mod;
    if (f % 2 == 1)
      ways *= 1LL * q[f] * rev[2] % mod;
    else {
      long long good = 1LL * q[f] * rev[2] % mod;
      long long bad = 1LL * comb(f, f / 2) * rev[2] % mod;
      good = (good + mod - bad) % mod;
      ways *= good, ways %= mod;
    }
    ways %= mod;
    ans += ways;
    ans %= mod;
  }
  ans *= w;
  ans %= mod;
  cout << ans << endl;
}
