#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int maxn = 2e5 + 7;
int n, k, h[maxn];
long long powmod(long long a, long long b) {
  if (b == 0) return 1;
  return b % 2 == 0 ? powmod(a * a % mod, b / 2)
                    : powmod(a * a % mod, b / 2) * a % mod;
}
long long fac[maxn], inv[maxn];
long long C(int a, int b) {
  if (b < 0 || b > n) return 0;
  return (fac[a] * inv[b] % mod) * inv[a - b] % mod;
}
int main() {
  fac[0] = inv[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fac[i] = i * fac[i - 1] % mod;
    inv[i] = powmod(i, mod - 2) * inv[i - 1] % mod;
  }
  cin >> n >> k;
  if (k == 1) {
    cout << "0" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) cin >> h[i];
  int num = 0;
  h[n] = h[0];
  for (int i = 0; i < n; i++) {
    if (h[i] != h[i + 1]) num++;
  }
  long long ans = 0;
  for (int i = 0; i * 2 <= num; i++) {
    long long tmp = C(num, i) * C(num - i, i) % mod *
                    powmod(k - 2, num - 2 * i) % mod * powmod(k, n - num);
    ans = (ans + tmp) % mod;
  }
  cout << ((powmod(k, n) - ans + mod) * inv[2]) % mod << endl;
}
