#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int N = 2e5 + 7;
const long long mod = 998244353;
int a[N];
long long f[N], inv[N];
long long n, k, c, ans;
long long binpow(long long x, long long pw) {
  if (!pw) return 1LL;
  if (pw % 2 == 0) {
    long long t = binpow(x, pw / 2);
    return (t * t) % mod;
  } else
    return (binpow(x, pw - 1) * x) % mod;
}
long long C(long long n, long long x) {
  return ((f[n] * inv[x]) % mod * inv[n - x]) % mod;
}
long long dv(long long a, long long b) {
  return (a * binpow(b, mod - 2)) % mod;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == a[i - 1]) c++;
  }
  if (a[n] == a[1]) c++;
  n -= c;
  c = binpow(k, c);
  k -= 2;
  f[0] = 1;
  for (long long i = 1; i <= n; i++) f[i] = (f[i - 1] * i) % mod;
  inv[n] = binpow(f[n], mod - 2);
  for (long long i = n - 1; i >= 0; i--) inv[i] = (inv[i + 1] * (i + 1)) % mod;
  for (long long x = 0; x <= n; x++) {
    if (x % 2 == 0)
      ans += (((C(n, x) * dv(binpow(2LL, x) - C(x, x / 2LL) + 2LL * mod, 2LL)) %
               mod * c) %
              mod * binpow(k, n - x)) %
             mod;
    else
      ans += (((C(n, x) * binpow(2LL, x - 1LL)) % mod * c) % mod *
              binpow(k, n - x)) %
             mod;
    ans %= mod;
  }
  cout << ans;
}
