#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const long long N = 1e6 + 5, mod = 998244353;
long long a[N], fac[N], inv[N];
long long ksm(long long b, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = 1ll * res * b % mod;
    b = 1ll * b * b % mod;
    n >>= 1;
  }
  return res;
}
void init(long long n) {
  fac[0] = 1;
  for (long long i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[n] = ksm(fac[n], mod - 2);
  for (long long i = n - 1; i >= 0; --i)
    inv[i] = 1ll * (i + 1) * inv[i + 1] % mod;
}
long long C(long long n, long long m) {
  return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  init(n);
  for (long long i = 1; i <= n; ++i) cin >> a[i];
  long long x = 0, y = 0;
  for (long long i = 1; i <= n; ++i)
    if (a[i] == a[i % n + 1])
      ++x;
    else
      ++y;
  long long ans = 0;
  for (long long i = 1; i <= y; ++i) {
    long long tmp;
    if (i % 2 == 1)
      tmp = ksm(2, i - 1);
    else
      tmp = (ksm(2, i - 1) - 1ll * inv[2] * C(i, i / 2) % mod + mod) % mod;
    ans = (ans + 1ll * C(y, i) * ksm(k - 2, y - i) % mod * tmp % mod) % mod;
  }
  cout << 1ll * ans * ksm(k, x) % mod;
}
signed main() {
  ios::sync_with_stdio(false);
  long long T = 1;
  while (T--) solve();
}
