#include <bits/stdc++.h>
using namespace std;
struct Debug {
  int cnt = 0;
  bool on = false;
  char debug[10] = "debug";
  template <class T>
  Debug& operator<<(const T& v) {
    if (on && cnt++ == 0) cerr << "debug: ";
    if (on) cerr << v << ' ';
    return *this;
  }
  Debug& operator<<(ostream& (*pManip)(ostream&)) {
    if (on) cerr << (*pManip);
    cnt = 0;
    return *this;
  }
} debug;
const long long mod = 998244353;
struct mint {
  long long x;
  mint() : x(0) {}
  mint(long long _x) { x = _x % mod; }
  mint operator+(const mint& b) const { return (x + b.x) % mod; }
  mint operator-(const mint& b) const { return (x - b.x + mod) % mod; }
  mint operator*(const mint& b) const { return (x * b.x) % mod; }
  template <class T>
  mint operator^(T b) const {
    if (!b) return 1;
    mint tmp = (*this) ^ (b / 2);
    return b % 2 ? tmp * tmp * (*this) : tmp * tmp;
  }
  mint inv() const {
    static unordered_map<long long, long long> inv_dp;
    if (inv_dp.count(x))
      return inv_dp[x];
    else if (inv_dp.size() < 100000)
      return mint(inv_dp[x] = ((*this) ^ (mod - 2)).x);
    else
      return (*this) ^ (mod - 2);
  }
  mint operator/(const mint& b) const { return (*this) * b.inv(); }
};
const int MAXN = 1e6 + 10;
long long n, m, k;
int a[MAXN], b[MAXN];
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  if (argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;
  cin >> n >> k;
  for (auto i = (0); i < (n); i++) {
    cin >> a[i];
    b[i + 1] = a[i];
  }
  b[0] = b[n];
  m = 0;
  for (auto i = (0); i < (n); i++)
    if (a[i] != b[i]) m++;
  mint res = 0;
  mint comb(1);
  mint comb1(1);
  for (auto kk = (1); kk < (m + 1); kk++) {
    comb = comb * mint(m - kk + 1) / mint(kk);
    mint tmp = mint(k - 2) ^ (m - kk);
    tmp = tmp * comb;
    if (kk % 2 == 0) {
      comb1 = comb1 * mint(kk) * mint(kk - 1) /
              mint((kk - 2) - (kk - 2) / 2 + 1) / mint(kk / 2);
      tmp = tmp * ((mint(2) ^ (kk - 1)) - comb1 / mint(2));
    } else
      tmp = tmp * ((mint(2) ^ (kk - 1)));
    res = res + tmp;
  }
  res = res * (mint(k) ^ (n - m));
  cout << res.x << endl;
  return 0;
}
