#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int mod = 998244353;
int h[200005];
int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
int mult(int a, int b) { return a * (long long)b % mod; }
int modPow(int a, int step) {
  int ans = 1;
  while (step) {
    if (step & 1) ans = mult(ans, a);
    step >>= 1;
    a = mult(a, a);
  }
  return ans;
}
int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
int fact[200005], inv[200005];
int c(int n, int k) { return mult(fact[n], mult(inv[k], inv[n - k])); }
int main() {
  fact[0] = inv[0] = 1;
  for (int i = 1; i < 200005; i++) {
    fact[i] = mult(fact[i - 1], i);
    inv[i] = modPow(fact[i], mod - 2);
  }
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> h[i];
  int cnt = 0;
  for (int i = 0; i < n; i++) cnt += h[i] == h[(i + 1) % n];
  int cnt2 = n - cnt;
  if (cnt2 == 0 || k == 1) {
    cout << 0;
    return 0;
  }
  int total = modPow(k, cnt2);
  int tot2 = 0;
  for (int i = 0; i <= cnt2; i += 2) {
    tot2 =
        add(tot2, mult(mult(c(cnt2, i), c(i, i / 2)), modPow(k - 2, cnt2 - i)));
  }
  total = sub(total, tot2);
  total = mult(total, (mod + 1) / 2);
  cout << mult(total, modPow(k, cnt));
}
