#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, k, h[200003], nw[200003];
long long f[200003], inv[200003];
long long mypow(long long x, long long times) {
  if (x == 0) return times == 0;
  if (times == 0) return 1;
  long long ret = mypow(x, times / 2);
  ret = ret * ret % mod;
  if (times % 2) ret = ret * x % mod;
  return ret;
}
long long C(long long x, long long y) {
  return (f[x] * inv[y] % mod) * inv[x - y] % mod;
}
int main() {
  f[0] = 1;
  for (int i = 1; i < 200003; i++) f[i] = f[i - 1] * i % mod;
  for (int i = 0; i < 200003; i++) inv[i] = mypow(f[i], mod - 2);
  cin >> n >> k;
  if (k == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++) scanf("%d", h + i);
  for (int i = 0; i < n; i++) nw[i] = h[(i + 1) % n];
  int cnt = 0;
  for (int i = 0; i < n; i++) cnt += (h[i] != nw[i]);
  long long ans = mypow(k, cnt);
  for (int i = 0; i <= cnt / 2; i++)
    ans =
        (ans + mod -
         C(cnt, i) * (C(cnt - i, i) * mypow(k - 2, cnt - i * 2) % mod) % mod) %
        mod;
  ans = ans * mypow(k, n - cnt) % mod;
  cout << ans * 499122177 % mod;
}
