#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const long long mod = 998244353;
int n, k;
long long h[MAXN];
long long fact[MAXN], invFact[MAXN];
long long fastPow(long long x, long long p) {
  long long curr = x, ans = 1;
  while (p != 0) {
    if (p % 2 != 0) {
      ans = (ans * curr) % mod;
    }
    p /= 2;
    curr = (curr * curr) % mod;
  }
  return ans;
}
long long inv(long long x) { return fastPow(x, mod - 2); }
long long comb(int k, int n) {
  if (k == 0) return 1;
  long long ans = fact[n];
  ans = (ans * invFact[k]) % mod;
  ans = (ans * invFact[n - k]) % mod;
  return ans;
}
void Init() {
  fact[0] = 1;
  for (int i = 1; i < MAXN; i++) fact[i] = (fact[i - 1] * i) % mod;
  invFact[0] = 1;
  for (int i = 1; i < MAXN; i++) invFact[i] = (invFact[i - 1] * inv(i)) % mod;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  if (k == 1) {
    cout << "0" << '\n';
    return 0;
  }
  int equals = 0;
  for (int i = 0; i < n; i++) {
    if (h[i] == h[(i + 1) % n]) {
      equals++;
    }
  }
  Init();
  n -= equals;
  long long sum = 0;
  for (int third = 0; third < n; third++) {
    long long mul = (fastPow(k - 2, third) * comb(third, n)) % mod;
    long long val = fastPow(2, n - third);
    if ((n - third) % 2 == 0) {
      val = (val - comb((n - third) / 2, n - third) + mod) % mod;
    }
    val = (val * inv(2)) % mod;
    sum = (sum + val * mul) % mod;
  }
  cout << (sum * fastPow(k, equals)) % mod << '\n';
}
