#include <bits/stdc++.h>
using namespace std;
const long long inf = -1e18;
const long long INF = 1e18;
const long long mod = 998244353;
const long long N = 200005;
long long n, k, m;
long long a[N];
long long fac[500005], inv[500005];
long long qpow(long long a, long long b) {
  if (b == 0) return 1;
  if (b & 1) {
    return a % mod * qpow(a, b - 1) % mod;
  } else {
    long long ans = qpow(a, b >> 1);
    return ans * ans % mod;
  }
}
void init() {
  fac[0] = fac[1] = 1;
  for (long long i = 2; i <= 500000; i++) fac[i] = fac[i - 1] * i % mod;
  inv[500000] = qpow(fac[500000], mod - 2);
  for (long long i = 499999; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}
long long getC(long long m, long long n) {
  return fac[m] * inv[n] % mod * inv[m - n] % mod;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  init();
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= n; i++) {
    if (a[i] == a[i % n + 1]) {
      m++;
    }
  }
  long long ans = qpow(k, m), res = 0;
  m = n - m;
  for (long long i = 0; i * 2 <= m; i++) {
    res += getC(m, i) * getC(m - i, i) % mod * qpow(k - 2, m - 2 * i) % mod;
    res = res % mod;
  }
  ans = ans * res % mod;
  ans = (qpow(k, n) - ans + mod) * inv[2] % mod;
  cout << ans << endl;
}
