#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643383279;
const int M = 998244353;
int n, k, a[200005], i, j, s;
long long ans, p = 1, fac[200005];
long long qpow(long long a, long long b) {
  long long s = a, ans = 1;
  while (b) {
    if (b & 1) ans = ans * s % M;
    s = s * s % M;
    b >>= 1;
  }
  return ans;
}
int main() {
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (i = 1; i <= n; ++i) {
    if (a[i] != a[i % n + 1])
      ++s;
    else
      p = p * k % M;
  }
  ans = qpow(k, n);
  fac[0] = 1;
  for (i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % M;
  for (i = 0; i * 2 <= s; ++i)
    ans = (ans - qpow(fac[i], M - 2) * qpow(fac[i], M - 2) % M *
                     qpow(fac[s - i * 2], M - 2) % M * qpow(k - 2, s - i * 2) %
                     M * fac[s] % M * p) %
          M;
  ans = ans * qpow(2, M - 2) % M;
  cout << (ans % M + M) % M;
}
