#include <bits/stdc++.h>
using namespace std;
long long qsm(long long x, long long y) {
  long long a = 1;
  long long base = x;
  while (y > 0) {
    if (y & 1) {
      a = (a * base) % 998244353;
    }
    y >>= 1;
    base = (base * base) % 998244353;
  }
  return a;
}
long long jc[200005] = {1};
long long inv[200005];
long long bit[200005] = {1};
long long n, k;
long long h[200005];
long long h1[200005];
long long count1;
void ini() {
  for (int i = 1; i <= 200000; i++) {
    jc[i] = (jc[i - 1] * i) % 998244353;
    bit[i] = bit[i - 1] * 2 % 998244353;
  }
  for (int i = 1; i <= 200000; i++) {
    inv[i] = qsm(jc[i], 998244353 - 2);
  }
}
long long c(long long x, long long y) {
  return (jc[y] * inv[x] % 998244353 * inv[y - x] % 998244353) % 998244353;
}
long long bbb;
int main() {
  ini();
  bbb = qsm(2, 998244353 - 2);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  if (k == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (i == n) {
      h1[i] = h[1];
    } else {
      h1[i] = h[i + 1];
    }
    if (h[i] == h1[i]) count1++;
  }
  long long ans = 0;
  long long temp = 1;
  long long temp1;
  long long temp2 = 1;
  for (int i = 0; i < n - count1; i++) {
    temp1 = n - count1 - i;
    if (temp1 % 2 == 0)
      ans = (ans + temp *
                       ((bit[temp1] - c((temp1 / 2), temp1)) % 998244353 +
                        998244353) %
                       998244353 * bbb) %
            998244353;
    else
      ans = (ans + temp * bit[temp1 - 1]) % 998244353;
    temp2 = (temp2 * (k - 2)) % 998244353;
    temp = temp2 * c(i + 1, n - count1) % 998244353;
  }
  ans = (ans * qsm(k, count1)) % 998244353;
  cout << ans;
}
