#include <bits/stdc++.h>
using namespace std;
const long long M = 998244353ll;
long long n, m, k, a[200005], ans;
long long fac[200005], inv[200005];
long long C(long long n, long long m) {
  return fac[n] * inv[m] % M * inv[n - m] % M;
}
long long ksm(long long x, long long w) {
  long long s = 1;
  while (w) {
    if (w & 1) s = s * x % M;
    x = x * x % M;
    w >>= 1;
  }
  return s;
}
signed main() {
  cin >> n >> k;
  for (long long i = 1; i <= n; cin >> a[i++])
    ;
  for (long long i = 1; i < n; i++)
    if (a[i] != a[i + 1]) m++;
  if (a[n] != a[1]) m++;
  fac[0] = inv[0] = 1;
  for (long long i = 1; i <= n + 1; i++)
    fac[i] = fac[i - 1] * i % M, inv[i] = ksm(fac[i], M - 2);
  for (long long i = 0; i <= m / 2; i++)
    ans = (ans + C(m, i) * C(m - i, i) % M * ksm(k - 2, m - 2 * i) % M *
                     ksm(k, n - m) % M) %
          M;
  ans = (ksm(k, n) - ans + M) % M;
  cout << ans * ksm(2, M - 2) % M << endl;
  return 0;
}
