#include <bits/stdc++.h>
using namespace std;
const int p = 998244353;
int add(int a, int b) {
  a += b;
  if (a >= p) a -= p;
  return a;
}
int sub(int a, int b) {
  a -= b;
  if (a < 0) a += p;
  return a;
}
int mult(int a, int b) { return (long long)a * b % p; }
int bin(int x, int n) {
  x %= p;
  int res = 1;
  while (n > 0) {
    if (n & 1) res = mult(res, x);
    x = mult(x, x);
    n >>= 1;
  }
  return res;
}
int inv(int x) { return bin(x, p - 2); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];
  if (k == 1) {
    cout << 0;
    return 0;
  }
  int base = 1, cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (h[i] == h[(i + 1) % n])
      base = mult(base, k);
    else
      ++cnt;
  }
  vector<int> fact(n + 1, 1);
  for (int i = 1; i <= n; ++i) fact[i] = mult(fact[i - 1], i);
  auto cnk = [&](int n, int k) {
    return mult(fact[n], inv(mult(fact[k], fact[n - k])));
  };
  int ans = 0;
  for (int i = 0; i < cnt; ++i) {
    int ways = mult(cnk(cnt, i), bin(k - 2, i));
    int m = cnt - i;
    if (m & 1)
      ways = mult(ways, bin(2, m - 1));
    else
      ways = mult(ways, mult(sub(bin(2, m), cnk(m, m / 2)), inv(2)));
    ans = add(ans, ways);
  }
  cout << mult(base, ans);
  return 0;
}
