#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mo = 998244353;
int a[N];
long long p[N];
long long qk(long long x, int y) {
  long long r = 1;
  for (; y; y >>= 1) {
    if (y & 1) r = r * x % mo;
    x = x * x % mo;
  }
  return r;
}
long long c(int n, int m) {
  return p[n] * qk(p[m], mo - 2) % mo * qk(p[n - m], mo - 2) % mo;
}
int main() {
  int n, m = 0;
  long long k, ans = 1;
  p[0] = 1;
  scanf("%d%lld", &n, &k);
  for (auto i = (1); i <= (n); ++i) p[i] = p[i - 1] * i % mo;
  for (auto i = (1); i <= (n); ++i) scanf("%d", &a[i]);
  for (auto i = (1); i <= (n); ++i)
    if (a[i % n + 1] != a[i]) {
      ++m;
      ans = ans * k % mo;
    }
  for (auto i = (0); i <= (m / 2); ++i)
    ans = (ans + mo - c(m, i) * c(m - i, i) % mo * qk(k - 2, m - i * 2) % mo) %
          mo;
  ans = ans * qk(2, mo - 2) % mo;
  for (auto i = (m + 1); i <= (n); ++i) ans = ans * k % mo;
  printf("%lld\n", ans);
}
