#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int logpow(int a, int b) {
  int ans = 1, d = a;
  while (b) {
    if (b & 1) ans = 1LL * ans * d % mod;
    b >>= 1;
    d = 1LL * d * d % mod;
  }
  return ans;
}
int n, k, a[200002], fact[200002], bigger[200002];
int comb(int n, int k) {
  return 1ll * fact[n] * logpow(fact[k], mod - 2) % mod *
         logpow(fact[n - k], mod - 2) % mod;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (k == 1 || n == 1) {
    cout << 0;
    return 0;
  }
  fact[0] = 1;
  for (int i = 1; i <= n; i++) fact[i] = 1ll * fact[i - 1] * i % mod;
  bigger[0] = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 1) {
      bigger[i] = logpow(2, i - 1);
    } else {
      bigger[i] = 1ll * (logpow(2, i) - comb(i, i / 2) + mod) *
                  logpow(2, mod - 2) % mod;
    }
  }
  a[n + 1] = a[1];
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] != a[i + 1]) cnt++;
  int ans = 0;
  for (int j = 0; j <= cnt; j++) {
    ans = (ans + 1ll * logpow(k - 2, j) * bigger[cnt - j] % mod *
                     comb(cnt, cnt - j) % mod) %
          mod;
  }
  cout << 1ll * ans * logpow(k, n - cnt) % mod << "\n";
  return 0;
}
